#### Archived

This topic is now archived and is closed to further replies.

# Circle-Rotated Rectangle Intersection

This topic is 6045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How could I determine if a Circle intersects a rectangle that has been rotated at an angle? I know I can do four line segment-circle intersection checks, but that seems like too much...is there a better way to do it?

##### Share on other sites
Treat the rectangle''s orientation as the coordinate system for doing the intersection check. Transform the center of the circle into the rectangle''s local coordinate system (with, say, the "lower left" corner of the rectangle being the origin). You can do one quick check: if the center of the circle---as transformed into the rectangle''s coordinate system---is in the inside of the rectangle (0 <= x <= width of rectangle and 0 <= y <= height of rectangle), then the circle does intersect the rectangle. Otherwise, you can do a check that is like a rectangle/rectangle intersection, using 4 simple rules: 1) circle_center.x-radius is greater than the width of the rectangle; 2) circle_center.x+radius is less than zero; 3) circle_center.y-radius is greater than the height of the rectangle; 4) circle_center.y+radius is less than zero. If all 4 rules result are true, the circle does not intersect the rotated rectangle. If any one is false, then the circle might intersect the rectangle.Those basic checks will give you a quick idea of whether the circle intersects the rotated rectangle---but it won''t be a perfect check.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
If you define your rectangle as two lengths and two unit vectors then you can get the coordinates as described above by calculating the dot product of a vector from a corner to the center of the circle with each of the vectors defining the rectangle. There can only be an intersection if the coordinates of the center are between -radius and edge length + radius. Within that rectangle and outside your rectangle there are eight sectors. If the center is within the four side sectors there is an intersection because you are within the radius distance from the side. Within the corner sectors you have to be within the radius distance of the corner for an intersection to occur because every other point on the edges is further away from every point in that sector. The line dividing the sectors would go with the edge sectors. If you drew the region where an intersection occurs at it would be a rectangle with rounded corners. The radius of the corners would be the radius of the circle.

That doesn''t allow for the circle being able to completely enclose the rectangle. There I think you would have to do a line segment/circle intersection.

##### Share on other sites
Thanks for the good followup, LilBudyWizer!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002292
×