   finding perpendicular vectors
  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   
  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.   ;  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  ;  If you know how to rotate a vector around another vector, why rotate I when you can rotate the first perpendicular vector?   ;  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;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.   ;  Indeed, my mistake :), This is what I had in mind, however, the rest of the algorithm should be ok.   ;  Thanks a lot for the helps.I have a clear idea of what I am programming :)best wishes   