Advertisement

Finding a vector perpendicular to another vector?

Started by January 06, 2003 02:32 AM
2 comments, last by ChromaZ28 22 years, 1 month ago
Let''s say I have a vector pointing backwards v1=(0,0,-1). How do I find a vector perpendicular to that pointing 90 degrees from that...in this case it would be v2=(0,1,0). Any ideas?
In 3D, you can only find a vector which is perpendicular to a plane, not a vector. There are infinitly many vectors which are 90o to a vector.

Given that fact, if you have two vectors in a plane, you can simply use the cross product to find a vector which is perpendicular to them. This gives you two possible answers, one pointing one way and the other pointing the opposite direction - it depends on the order: v1 x v2 points in the opposite direction to v2 x v1.

If I had my way, I''d have all of you shot!


codeka.com - Just click it.

Advertisement
In 3D, you have a whole plane perpendicular to any given vector. To get a unique vector as the result, you need two vectors to be orthogonal to. Then, the vector you are looking for is defined as the cross-product of the first two.

If you only have one vector, you could pick an arbitrary vector, make sure it is not colinear with your original vector (i.e. that they are not aligned), do the cross product of the two (if they are aligned, the cross product with result in a (0,0,0) vector), then normalise (divide by the length) to get back to a length-1 vector.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:
How do I find a vector perpendicular to that pointing 90 degrees from that...in this case it would be v2=(0,1,0).

(1,0,0) is also perpendicular and so is (1,1,0) and (-1,0,0) and (1,-1,0), and even (23.253,.0484,0).

Vectors are perpendicular to planes, not other vectors. Think about it. Even when you take the cross product, it is understood that the two original vectors designate a plane. In your example, any vector coplanar with the XY plane would be perpendicular to (0,0,-1).

This topic is closed to new replies.

Advertisement