Jump to content
  • Advertisement

Archived

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

MindWipe

Really fast circle - square collision detection?

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

Advertisement
Usually when optimising collision routines, the best methods are to check when it''s NOT colliding.

Simple bounding box checks against the sphere and square would speed things up considerably.

Share this post


Link to post
Share on other sites
quote:
Original post by Damocles
Usually when optimising collision routines, the best methods are to check when it''s NOT colliding.

Simple bounding box checks against the sphere and square would speed things up considerably.


Or even circle/circle testing; the distance from one corner of the square to the center is the radius of its bounding circle (because it''s a square).

Depends on which of the two is larger.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites
Square->square checking might be the best way.

Circle radius=r
Square side length=s
d=r+s/2

if circlex<squarex-d then missed
if circlex>squarex+d then missed
if circley<squarey-d then missed
if circley>squarey+d then missed

I hope I got that right. The corners will not be perfect but it should be fine for a game I think.

Mark
Cornutopia Games
http://www.cornutopia.net

[edited by - Mark Sheeky on August 17, 2003 6:27:28 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Mark Sheeky
Square->square checking might be the best way.

Circle radius=r
Square side length=s
d=r+s/2

if circlexif circlex>squarex+d then missed
if circleyif circley>squarey+d then missed

I hope I got that right. The corners will not be perfect but it should be fine for a game I think.

Mark
Cornutopia Games
http://www.cornutopia.net

[edited by - Mark Sheeky on August 17, 2003 6:27:28 AM]


I think there''s something to that. Gotta work on that and try to come up with a great system, because I need the player (circle) to slide against the walls if too near (the squares).

/MindWipe

Share this post


Link to post
Share on other sites
I think the main problem with circle/square crash detection is accuracy. I''ve been trying to come up with a way to check line-segment/circle crashes, but my solutions either a) produce VERY erronious results or b) involve calculus, which is incredibly slow and hard to think about. It''s relatively easy to tell if a circle is crossing a LINE (that is, unlimited length) by throwing down some coordinate transformations (getting the circles coordinates if the line is treated as the y-axis), but these methods can result in false-positives if it is a line SEGMENT. Sorry I couldn''t be more help, but if anyone knows how to do this, then box/circle crashes would be easy.

Share this post


Link to post
Share on other sites
Idea:

To improve the accuracy of my idea you only need to see if the circle is in one corner and at that point to a circle->circle detection using the corner of the square and the radii of the circle.

Imagine the square is the middle box of a noughts and crosses (that is tic-tac-toe). If the circle lies in one of the 4 oblique boxes, treat it like a square as in my previous post.

If the circle is in one of 4 the diagonal boxes, treat it like a circle to circle test with the corner of the central square.

Mark
Cornutopia Games
http://www.cornutopia.net

Share this post


Link to post
Share on other sites

  • 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!