A trick for vector projection - just so u know

Started by
-1 comments, last by llvllatrix 21 years, 10 months ago
If you ever have to project one vector on to another in 3d (and have the projection return the coordinates of the new vector) i came up with a fast way: Mathematical theory: -Let V1(xv1,yv1,zv2) be the vector to be projected on to -Let V2(xv2,yv2,zv2) be the vector being projected -Treat the vector you are projecting on to as a normal to a plane in scaler form. so you have your plane (xv1 * x) + (yv1 * y) + (zv1 * z) = D where D is a constant -Find D using V2 so D = (xv1 * xv2) + (yv1 * yv2) + (zv1 * zv2) -Now treat V1 as a line in parametric form x = txv1 y = tyv1 z = tzv1 - Sub this into your plane, isolate t and plug back into your V1 line equation, solve for x,y,z and you have your projected vector. -This looks a lot simpiler coded and the most complicated operator it uses is divide, making it fairly fast. How i used this: Whenever i got a collision with my terrain i projected the net force of the object that collided with the terrain onto the normal of the triangle on the terrain that colided with my object and negated all of the components. Then i added this force into my object preventing the object from going into the terrain.

This topic is closed to new replies.

Advertisement