0
$\begingroup$

How can I transform a series of $x,y,z$ points in a Cartesian system to a rotated Cartesian system using a normal vector that defines the $z$ axis of the new system. All examples I have seen use the original axis for rotation which is not what I am looking to do. Instead, I am looking to translate so that the normal vector define the $z$ axis of the new coordinate system.

I have: multiple $x,y,z$ points in original system a normal vector to define transformation (and its location if that matters)

  • 0
    The rotation as described is not unique. Do you mean to tilt the old $z$-axis “directly” onto the new one.2017-01-14
  • 0
    Yes. Then I am looking to find the new coordinates of each point after the tilt.2017-01-14

1 Answers 1

0

Let $\hat{z}_0$ be the $z$-axis unit vector in the original coordinate system, and $\hat{z}_1$ in the new coordinate system. (Note that I do assume both have length $1$.)

To rotate $\hat{z}_0$ to $\hat{z}_1$, you need a rotation of $\theta$ around axis $\hat{a}$: $$\left\lbrace\begin{array}{rcl} \vec{a} &=& \hat{z}_0 \times \hat{z}_1 \\ \sin\theta &=& \lVert\vec{a}\rVert \\ \hat{a} &=& \frac{\vec{a}}{\lVert\vec{a}\rVert} \\ \cos\theta &=& \hat{z}_0 \cdot \hat{z}_1 \end{array}\right.$$ The reason we can use the cross product of the two (unit) vectors like this as the rotation axis may be unintuitive. The key is to remember that the cross product of $\vec{a}$ and $\vec{b}$ is perpendicular to both $\vec{a}$ and $\vec{b}$. If we rotate the coordinate system of $\vec{a}$ around this axis, by the angle between $\vec{a}$ and $\vec{b}$, the rotated $\vec{a}$ will be parallel to $\vec{b}$.

If we use $(x, y, z) = \hat{a}$, $s = \sin\theta$, $c = \cos\theta$, and $d = 1 - c = 1 - \cos\theta$, then the rotation matrix $\mathbf{R}$ needed (for $\mathbf{R} \hat{z}_0 = \hat{z}_1$; see Rotation matrix Wikipedia article for details) is $$\mathbf{R} = \left [ \begin{matrix} x^2 d + c & x y d - z s & x z d + y s \\ x y d + z s & y^2 d + c & y z d - x s \\ x z d - y s & y z d + x s & z^2 d + c \end{matrix} \right ] $$ Do note that you do not need to use $\sin$, $\cos$, $\arcsin$, or $\arccos$ at all to construct the rotation matrix. I used them to remind readers of the definition of cross product and dot product for three-dimensional vectors.

Caveat: The method shown here is quite sound, but I was too lazy to verify the above math with respect to typos (and the order of the vectors in the cross product, and the direction of the rotation), so if you notice a problem or a typo or any other error, do let me know in a comment, so I can fix it.