Maths vector problem

Miscellaneous Forums/General Discussion/Maths vector problem

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

You don't need to normalise the vector p1->p3, which will save you a bit of calculation. A dot product of anything less than zero means p3 is on the wrong side of the line.

In fact, this is the kind of thing that needs pictures to understand properly, so here are some:



This is your drawing with the addition of a point p3B, which is where p3 ends up, and its initial position is now called p3A.



To see if p3B is on the right side of the line, we just need to get the dot product of the vector (p1 -> p3B) with the normal vector n. If the dot product is less than zero, p3B is on the wrong side.



Then all we need to do is 'project' p3B onto the line. We need a unit vector v along the line, which we can get by taking the vector (p1 -> p2) and dividing each of its component by the vector's length.
The vector l here is just the vector (p1 -> p3B).

Now, simply taking the dot product of v and l will give us the distance along the line of the point we want.

Finally, multiplying v by the dot product and adding it to p1 will give us exactly the co-ordinates of the final position of p3.

I would've gone into more detail, but I have to get ready for a lecture in 20 minutes!