Archived

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

kstuart@ucla.edu

Circle - point collision detection formula?

Recommended Posts

Hi all, I''m trying to write a game wherein I want to do what seems to be a simple collision detection. I have a circle moving at a constant rate, and a point moving at a constant rate. I want to determine whether the circle collides with the point. I have looked around for a long time on the ''net for a formula to do this detection, but have not found one. I would appreciate greatly any pointers to such. Thanks, -Ken Stuart kstuart@ucla.edu PS. I am writing in Perl, in case there''s already some code available that I could just import.

Share this post


Link to post
Share on other sites
RWarden    118
You''re in luck; point-in-circle is probably the easiest kind of collision detection you can possibly do.

If the distance between the center of the circle and the point is less than the radius of the circle, the two have collided.
If they are equal, the point is on the circle itself.
Otherwise, there was no collision.

Now, determining the distance between the points can be slow because of the sqrt call in determining the distance between the two points. However you can eliminate the sqrt call by comparing the distance squared with the radius squared. One extra multiplication is a whole lot faster than a sqrt .

-RWarden (roberte@maui.net)

Share this post


Link to post
Share on other sites