Jump to content
  • Advertisement
Sign in to follow this  
me_here_me

finding perpendicular vectors

This topic is 3887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have to write a code to find a 3D vector perpendicular to a given 3D vector. I need some help in the maths. Assume that the given vector is OX {O = (Ox, Oy, Oz), X = (Xx, Xy, Xz)}. My job is to find a unit vector perpendicular to the vector OX. The unit vector should be positioned at X. Lets call the resulting vector XR. I know that there can be numerous vectors that satisfy the above conditions. Any vector lying over a circle, whose center is at X, radius 1 and positioned perpendicular to the OX. I need to find any one such vector that is perpendicular to the OX. I understand that the dot product of perpendicular vectors is zero but this help little as I have three unknown values in XR. thanks in advance for help

Share this post


Link to post
Share on other sites
Advertisement
Choose an arbitrary vector I, ex: (1, 0, 0). If it's parallel to OX, choose a different arbitrary vector (ex: (0, 1, 0). Take the cross product of I and OX. This results in a vector perpendicular to OX.

Share this post


Link to post
Share on other sites
Thanks for your elegant solution.

For my curiosity, I wondered how can we find a number of vectors, lets say 8, all of which are perpendicular to OX, but uniformly distributed regarding the angle between themselves.

I came up with the following scheme, it seems workable?

Find a vector I, not parallel to OX (as you suggested) and take a cross product to determine a perpendicular vector. Then rotate vector I, 7 times around vector OX. Keep each rotation 45 degrees and compute a cross product between I and OX. This will result in 8 vectors all perpendicular to OX and with a uniform angle between them.

The solution is correct isnt it?

anyway, thanks for your help and best wishes

Share this post


Link to post
Share on other sites
If you know how to rotate a vector around another vector, why rotate I when you can rotate the first perpendicular vector?

Share this post


Link to post
Share on other sites
There might be a faster way:

- find the biggest component of OX (as absolute values)
- with that component you'll be sure it will not be parallel withat axis, so choose it as your secondary cross opperand.
- normalize the result and place it in X

and voila :)
And for your second question:

- negate your first perpendicular for your second vector
- cross one of the vectors with the OX for your third vector
- negate your third vector for the forth
- make a 45 degrees matrix around OX
- rotate your first four vectors with that matrix for the last four

Share this post


Link to post
Share on other sites
Quote:
Original post by deltadream
- find the biggest component of OX (as absolute values)
- with that component you'll be sure it will not be parallel withat axis, so choose it as your secondary cross opperand.

Normally, the axis with the component of smallest magnitude is chosen, set to a length of 1, and the other axes set to 0. Consider the following (roughly) normalized vector:
Vector A = {0.9999, 0.009999, 0.009999};
// taking the largest axis:
Vector B = {1.0, 0.0, 0.0};
// These are nearly parallel, so you could run into problems with a cross product

// taking the least axis (break ties any way you see fit):
Vector C = {0.0, 1.0, 0.0};
// These are not at all parallel (in this case nearly orthogonal),
// so there should be no problems with a cross product.
Also, you'll run into similar problems if you just take the axis with the greatest magnitude and zero it - you could wind up with a Zero vector.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!