0

Possible Duplicate:
Circle-Rectangle collision detection (intersection)

How can I calculate if a circle's shape is overlapping the shape of an rectangle (both 2D) ?

The information I have about both is the circles center and its radius, the rectangles upper left vertex and its width and height. If you have other solutions based on other representations that would be fine too. Also: I'm programming in Java, are there any usefull classes?

Community
  • 1
  • 1
B. Lauing
  • 41
  • 1
  • 6

1 Answers1

-2

For the corner closest to the circle center, calculate the distance from the corner to the circle center. If it is less than the radius, the shapes overlap.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • 1
    The *corner* does not necessarily overlap with the circle, just because the shapes overlap. – aioobe May 15 '12 at 13:56
  • You are right, the circle may be contained within the rectangle, or intersect the rectangle between two corners. – Sjoerd May 15 '12 at 14:01