# Euler angles to rotation matrix. Rotation direction

So we have a 2D rotation matrix for counterclockwise (positive) angle "$a$":
$\begin{pmatrix} \cos(a) & -\sin(a) \\ \sin(a) & \cos(a) \end{pmatrix}$.

For clockwise (negative) angle: $\begin{pmatrix} \cos(a) & \sin(a) \\ -\sin(a) & \cos(a) \end{pmatrix}$.

When converting euler angles to 3d rotation matrix we extend rotation matrices of yaw ($z$), pitch ($y$) and roll ($x$) angles and multiply them. The same convention is used for all angles: counterclockwise direction, right-handed system.

$R_x = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos(x) & -\sin(x) \\ 0 & \sin(x) & \cos(x) \end{pmatrix}$, $R_y = \begin{pmatrix} \cos(y) & 0 & \sin(y) \\ 0 & 1 & 0 \\ -\sin(y) & 0 & \cos(y) \end{pmatrix}$, $R_z = \begin{pmatrix} \cos(z) & -\sin(z) & 0 \\ \sin(z) & \cos(z) & 0 \\ 0 & 0 & 1 \end{pmatrix}$.

Why is the direction of rotation for the pitch angle (sign of sin elements) different from yaw and roll angles? Thanks.

• $R_z$: $\sin(x), \cos(x)$ or $\sin(z), \cos(z)$? – Oleg567 Jul 11 '13 at 8:30
• Thanks, Oleg567, changed x to z in Rz matrix – Andrey Grachev Jul 11 '13 at 9:35

## 1 Answer

Matrix rows or columns are traditionally listed under $(x,y,z)$ order.

Cyclically change the pairs under consideration i.e $(x,y)\to(y,z)\to(z,x)$. The pairs $(x,y)$ and $(y,z)$ show up in the same order in the matrix but the $(z,x)$ shows up in reverse in the matrix. That is the cause of apparent discrepancy but really there is no discrepancy.

For example write

$x'=x\cos \alpha - y \sin \alpha$

$y'=x\sin \alpha + y \cos \alpha$

now change $(x,y)\to(y,z)\to(z,x)$ and $\alpha\to \beta \to \gamma$ and write the three matrices to see how $(z,x)$ part gets flipped.

Edit:

If you want them to look alike then give up the matrix notation and instead write

$y'=y\cos \beta - z \sin \beta$

$z'=y\sin \beta + z \cos \beta$

And

$z'=z\cos \gamma - x \sin \gamma$

$x'=z\sin \gamma + x \cos \gamma$

In each instance if you try to write $\left[ \matrix{ x' \cr y' \cr z'}\right]$ in terms of $\left[ \matrix{ x \cr y \cr z}\right]$ you will see that the mystery goes away.

• Maesumi, thank you for the answer. But – Andrey Grachev Jul 11 '13 at 10:48
• But then if Ry was |sin(y) 0 cos(y)| |0 1 0 | |cos(y) 0 -sin(y)|, it would be easier to avoid confusion. – Andrey Grachev Jul 11 '13 at 11:01
• Then it would not be counterclockwise like the others! – Maesumi Jul 11 '13 at 12:05
• got that, thanks. – Andrey Grachev Jul 11 '13 at 12:21