Find other two orthogonal vectors based on one direction and other constrains

104 Views Asked by At

In order to define a coordinate system I need 3 vectors, one for each axis.

Constrains:

  • Z axis: known.
  • X axis: z == 0. It is on XY plane.
  • Y axis: z < 0.

How can I find X and Y axis? A Matlab sample would be perfect.

1

There are 1 best solutions below

1
On BEST ANSWER

I will assume that the given Z-axis is not parallel to $\hat k$ (the direction of the true $z$-axis); otherwise, the directions are not completely determined and it is impossible to have $Y$ point "downwards". I will use $\mathbf x, \mathbf y, \mathbf z$ to denote the vectors that we want (that point in the direction of our new axes).

Note that the $\mathbf x$-axes is perpendicular to both $\hat k$ and $\mathbf z$. It follows that $\mathbf x$ must be parallel to the cross-product $\hat k \times \mathbf z$.

In order to produce a right-handed coordinate system, $\mathbf y$ must point in the direction of $\mathbf z \times \mathbf x$.

In order to fulfil the requirement that $\mathbf y$ points down, we either leave the vectors as they are or flip the signs of both $\mathbf x$ and $\mathbf y$.

Putting this all together, we could apply the following code:

z = [1, -2, -1];

k = [0,0,1];
x = cross(k,z);
y = cross(z,x);
if y(3)>0
    y = -y; x = -x;
end