Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
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! –  Markus Orreilly Aug 13 '12 at 11:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.