# 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.

## 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 on other sites
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 on other sites

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 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 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 :)

- 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 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 on other sites
Indeed, my mistake :), This is what I had in mind, however, the rest of the algorithm should be ok.

##### Share on other sites
Thanks a lot for the helps.

I have a clear idea of what I am programming :)

best wishes

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632659
• Total Posts
3007692
• ### Who's Online (See full list)

There are no registered users currently online

×