Circle - point collision detection formula?
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.
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement