Archived

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

Circle-Rotated Rectangle Intersection

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites