Find two perpendicular vectors from another vector

I have a vector1 that I know 3D coordinates (vector1 can be in any direction) and I would like to find two perpendicular vectors to this vector 1 (the two perpendicular vectors must be perpendicular to each other).

What's the fastest way to find two vectors programmatically (in Java if possible)?

I tried to rotate vector1 90 degrees, but it doesn't seem to always work depending on the direction of the vector.

Edit: Perpendicular vectors can be in any direction.

+3


source to share


1 answer


To find the first vector, you can apply the following algorithm:
Suppose the original vector (A, B, C)

. Two vectors are perpendicular if their dot product is 0. So, we get the equation A * x + B * y + C * z = 0

. At least one of A

, B

or C

not equal to zero. Let's assume it is C

not zero. Then the vector ( 1

, 1

, -(A + B) / C

) is suitable. A case where C = 0

, but A != 0

or B != 0

can be handled in a similar way.



Finding the second vector is much easier: you can use the cross product of the original vector and the first vector. What is it.

+5


source







All Articles