Skip to main content
gamedev.net
🔒 Locked

Collision detection algorithm

Started by OuncleJulien Apr 16, 2004 at 7:38 PM 1 replies 350+ views
Original Post
OuncleJulien
OuncleJulien
Hey guys, I''m working on a collision detection routine and had a question regarding the algorithm listed on this page (http://www.gamedev.net/reference/articles/article1026.asp) for the closestPointOnLine function:
Point  closestPointOnLine(Point a, Point b, Point p)
{
   // Determine t (the length of the vector from ‘a’ to ‘p’)


   Vector c = p - a;
   Vector V = Normalized vector [b – a];
   double d = distance from a to b;
   double t = V * c;

   // Check to see if ‘t’ is beyond the extents of the line segment


   if (t < 0) return a;
   if (t > d) return b;
 
   // Return the point between ‘a’ and ‘b’


   set length of V to t;
   return a + V;
}
On the double t = V * c; line.. it''s multiplying V * c, which are both vectors. Which implys that they''re taking the Dot Product, right?
hplus0603
hplus0603
Yup. This basically projects the point onto the line, and measures whether the point is before, after, or within the line segment along that projection.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.