Jump to content
  • Advertisement
Sign in to follow this  
homer_3

Circle rectangle collision

This topic is 2944 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

I'm trying to determine if a 2D circle is intersecting with a 2D rectangle. Is this simple as finding the distance between the center of the circle and the center of the rectangle and checking if that distance is less than the diameter of the circle?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Is this simple as finding the distance between the center of the circle and the center of the rectangle and checking if that distance is less than the diameter of the circle?
That won't work for a circle and a box, no. (What you describe is how you would test for intersection between two circles or spheres.)

One way to test for intersection between a circle (or sphere) and a box is to find the point on the box closest to the circle/sphere center, and then compare the distance (or squared distance) from this point to the circle/sphere center to the circle/sphere's radius (or squared radius).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!