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.
In order to define a coordinate system I need 3 vectors, one for each axis.
Constrains:
How can I find X and Y axis? A Matlab sample would be perfect.
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: