I am currently working my way through a book on Game Programming in Actionscript 3, and have gotten to a formula required for collision detection on finding the intersection point of two vectors.
Im not sure if the author uses vectors in the strictest definition, but the convention he uses is e.g for a vector V1 :
V1.a is the start point of the vector V1.b is the end point of the vector V1.ln is the vector perpendicular to V1 (its 'left normal') V1.vx is the difference between the x coordinate of V1.b and V1.a V1.vy similar to vx V1.dx is the same as vx , but for V1 scaled down to a unit vector (the direction vector)
Now,in the example we have V1 which is the motion vector of the ship, and V2, which is the target vector (i.e the line the ship is going to collide with at some point)
In order to calculate at what point on V2 the ship will collide travelling along motion vector V1, the book gives the following code using the "perpendicular dot product" (Which i have not come across before) and creating a third vector V3 between the start point of V1 and the start point of V2 (V1.a and V2.a):
perpProduct1 = v3.ln.vx * v2.dx + v3.ln.vy * v2.dy
perpProduct2 = v1.ln.vx * v2.dx + v1.ln.vy * v2.dy
t = perpProduct1 / perpProduct2
intersectionX = v1.a.x + v1.vx * t
intersectionY = v1.a.y + v1.vy * t
Now, i could easily just copy and paste that code wherever i need it and be done with it. But it bugs me that i dont really understand the mathematics of whats going on here. If someone could please give me a geometric explanation of how this algorithm finds the intersection point, or at least some sort of algebraic proof, it would help me sleep a little better tonight. Cheers.