[Math] From Euler angles to rotation matrix: rotating around new axes or original axes

coordinate systemslinear algebramatricesrotationstransformation

To transform from a coordinate frame XYZ to another frame xyz via Euler angles ($\alpha, \beta, \gamma$) in the order (X-Y-X) rotation, we can write the overall rotation matrix as the triple product of the individual rotations in reverse order:

R = R$_x$($\gamma)$R$_y$($\beta$)R$_x$($\alpha$)

This should represent successive rotations with respect to the corresponding axes that is introduced from the previous rotation. Knowing this I can write the rotation order as X-Y'-X" because the original X and Y axes maybe changed after each rotation.

However, when I apply this to a real system, the result does not agree with the above. Instead the rotation matrix causes sequential rotations around the original X-Y-X axes.

For example, I define the original XYZ axes as (1,0,0), (0,1,0), (0,0,1). Rotation about the X axes 90° has a rotation matrix:

$R_X(90°) = \begin{bmatrix}
1 & 0 & 0 \\
0 & cos(90°) & -sin(90°) \\
0 & sin(90°) & cos(90°)
\end{bmatrix}
= \begin{bmatrix}
1 & 0 & 0 \\
0 & 0 & -1 \\
0 & 1 & 0
\end{bmatrix} $

Hence in the new frame, Y become Z, and Z become -Y:

Y' = $R_X(90°) \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}$ = $\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$

Z' = $R_X(90°) \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$ = $\begin{bmatrix} 0\\ 0\\ -1 \end{bmatrix}$

If now we consider a rotation of $45°$ about the new Y' axes, it's actually about the old Z axes with a rotation matrix:

$R_{Y'}(45°) = \begin{bmatrix}
cos(45°) & 0 & sin(45°) \\
0 & 1 & 0 \\
-sin(45°) & 0 & cos(45°)
\end{bmatrix} = \begin{bmatrix} \sqrt2/2 & 0 & \sqrt2/2 \\ 0 & 1 & 0 \\ -\sqrt2/2 & 0 & \sqrt2/2 \end{bmatrix} $

Note that X'=X because the first rotation is about the X axis, we have the new X" axis:

X" = $R_{Y'}(45°) \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} \sqrt2/2 \\ 0 \\ -\sqrt2/2 \end{bmatrix}$

So this new X" axis lies on the old XZ plane. However, as the rotation is about the old Z axis, the new X" should be on the XY plane. This is shown briefly in the image attached.

Can anyone let me know what I did wrong? If there's something wrong with the above, how could we fix it to arrive to the correct answer?

https://i.stack.imgur.com/dTxN2.png

EDIT: SOLUTION TO THIS PROBLEM
The accepted comment hits the point. Obviously I was confused about old and new coordinates in the act of the rotation. The matrices I have written are transformation matrices that bring the coordinates with respect to (w.r.t) the newly rotated frame, to the coordinates w.r.t the old frame.

Coming back to the example. For clarity, I am considering 2 rotations so I will call the coordinate system as frame 1, frame 2, and frame 3, corresponding to the original XYZ, then after rotation about the X axis X'Y'Z', and after rotation about the Y axis X"Y"Z".

First rotation: Rotation of 90° about the original X axis, the R$_X(90°)$ transforms coordinate w.r.t the new frame 2 to one w.r.t the old frame 1. Consider the X axis:

X' = X (w.r.t frame 1) = R$_X(90°)$ X (w.r.t frame 2)

We know that X (w.r.t frame 2) is (1,0,0)$^T$, so:

X' = X (w.r.t frame 1) = $R_X(90°) \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}$ = $\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}$

which is correct (because the rotation is about the old X axis so X' is the same with X).

Second rotation 45° about the new Y' axis. If we use the same logic as above, for transformation from X' to X" we can write:

X (w.r.t frame 2) = R$_Y(45°)$ X (w.r.t frame 3)

Again X (w.r.t frame 3) is (1,0,0)$^T$. We can calculate X (w.r.t frame 2) directly. However what I want is to know the vector w.r.t the original frame 1, not frame 2.

From the first rotation, I know I can write:

X (w.r.t frame 1) = R$_X(90°)$ X (w.r.t frame 2)

Hence, I have the X" axis as:

X" = X (w.r.t frame 1) = R$_X(90°)$ X (w.r.t frame 2) = R$_X(90°)$ R$_Y(45°)$ X (w.r.t frame 3)

X" = $\begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} \sqrt2/2 & 0 & \sqrt2/2 \\ 0 & 1 & 0 \\ -\sqrt2/2 & 0 & \sqrt2/2 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} $

= $\begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} \sqrt2/2 \\ 0 \\ -\sqrt2/2 \end{bmatrix}$

= $\begin{bmatrix} \sqrt2/2 \\ \sqrt2/2 \\ 0 \end{bmatrix}$

This gives the correct coordinate for the newest X" axis (coordinate w.r.t the original frame 1). Hence, to be able to rotate with respect to the body frame, not the global frame, we need to write the rotation matrix as:

R =R$_1$R$_2$R$_3$ = R$_x$($\alpha)$R$_y$($\beta$)R$_x$($\gamma$)

where 1,2,3 denotes the order of rotations.

Best Answer

Maybe I have not properly understood the problem, but I seems to me, that there is confusion in the understanding of the order of rotations.

If rotations are written in relation to global axes, we need the inverse order of matrices (because dot product is applied to vector from right to left): $$ R = R_3 R_2 R_1. $$

If rotations are written in relation to body axes, we need the direct order: $$ R = R_1R_2R_3 $$

Having said that, you probably miss the order in the initial ${ R } = { R } _ { x } ( \alpha ) \mathrm { R } _ { y } ( \beta ) \mathrm { R } _ { x } ( \gamma )$ equation. If you use the rotations in relation to global axes, you need to switch the order.