Computing two vectors that are perpendicular to third vector in 3D
3d, math, vector
Solution
What I have done, provided that `X<>0` or `Y<>0` is
- `A = [-Y, X, 0]`
- `B = [-X*Z, -Y*Z, X*X+Y*Y]`
and then normalize the vectors.
[ X,Y,Z]·[-Y,X,0] = -X*Y+Y*X = 0
[ X,Y,Z]·[-X*Z,-Y*Z,X*X+Y*Y] = -X*X*Z-Y*Y*Z+Z*(X*X+Y*Y) = 0
[-Y,X,0]·[-X*Z,-Y*Z,X*X+Y*Y] = Y*X*Z+X*Y*Z = 0
This is called the nullspace of your vector.
If `X=0` and `Y=0` then `A=[1,0,0]`, `B=[0,1,0]`.
Problem
What is the best (fastest) way to compute two vectors that are perpendicular to the third vector(X) and also perpendicular to each other? This is how am I computing this vectors right now: ``` // HELPER - unit vector that is NOT parallel to X x_axis = normalize(X); y_axis = crossProduct(x_axis, HELPER); z_axis = crossProduct(x_axis, y_axis); ``` I know there is infinite number of solutions to this, and I don't care which one will be my solution. What is behind this question: I need to construct transformation matrix, where I know which direction should X axis (first column in matrix) be pointing. I need to calculate Y and Z axis (second and third column). As we know, all axes must be perpendicular to each other.