Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find two perpendicular vectors out of another vector

Tags:

java

vector

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

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

I tried to rotate the vector1 by 90 degrees but it doesn't seems to always work depending of the direction of vector1.

Edit: Perpendicular vectors can be in any directions.

like image 248
moumoute6919 Avatar asked Dec 03 '25 17:12

moumoute6919


1 Answers

To find the first vector, you can apply the following algorithm:
Let's assume that the original vector is (A, B, C). Two vectors are perpendicular if their scalar product is 0. So we get an equation A * x + B * y + C * z = 0. At least one of the A, B or C is not zero. Let's assume that C is not zero. Then a vector(1, 1, -(A + B) / C) fits. The case when 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 a vector product of the original vector and the first vector. That's it.

like image 60
kraskevich Avatar answered Dec 06 '25 07:12

kraskevich