# Finding the normal from one 3d vector/line to any point on another 3d vector/line

Say I have two 3d vectors, v1 and v2 (you can consider them both lines if you like). I'm trying to figure out a normal for v1 so that it intersects along any point of v2.

I keep drawing blanks on this one. It's easy enough to find a vector that points from v1 to v2 (just do v2 - v1), but that result isn't always perpendicular to v1.

How would you go about making that result perpendicular to v1?

## 1 Answer

You can use scalar projection, i.e. the dot product, to do that.

You want to project v2 onto v1, so normalize v1 to length 1, then take the dot product: float projection = dot(v2, normalize(v1));

This tells you how far you have to go in the direction of v1 until you are perpendicular to the end of v2, so float scalar = projection / length(v1); tells you where on v1 that point is.

so scalar * v1 gets you to that point, and v2 - scalar*v1 would be the perpendicular vector from that point on v1 to v2.

• Awesome, thanks! I knew the solution had something to do with that - I was trying the cross product between v1 and v2, and then the cross product again between v1 and the previous result - still wasn't working how I thought it should. Thank again! – d0c_s4vage Aug 13 '12 at 11:34