# How to rotate an orientation (Euler angles)

If I have an orientation defined by Euler angles and I want to simulate a rotation of the coordinate system about the origin (doesn't matter to me how the rotation is specified), how would I get the new Euler angles? I understand how to transform a point via a rotation matrix, but I'm not sure how to approach this in terms of Euler angles.

For example, I'm thinking of an airplane's orientation in terms of pitch, yaw, and roll, and say I want to simulate a random rotation of the airplane about its center.

• The rotation matrix is given here: en.wikipedia.org/wiki/Euler_angles#Rotation_matrix – Yves Daoust Mar 12 '15 at 15:50
• How would I apply the rotation matrix to my original Euler angles? – rmp251 Mar 12 '15 at 16:21
• You just compute it from the Euler angles ! – Yves Daoust Mar 12 '15 at 17:22
• Thanks for the comment but you are misunderstanding my question. How do I apply (not compute) such a rotation transformation to an orientation (as specified via Euler angles) as opposed to points in 3-space? – rmp251 Mar 12 '15 at 19:03
• I guess that the only way is to multiply the rotation matrices and inverse the process to retrieve the Euler angles corresponding to the combined rotations (see my answer about this). – Yves Daoust Mar 12 '15 at 19:58

## 1 Answer

Let us assume that the rotation is known by a $3\times3$ matrix, and let us focus on the one specified as $X_1Z_2X_3$ in the Wikipedia article.

You get $\alpha$ from $\tan\alpha=\dfrac{s_1s_2}{c_1s_2}$.

You get $\beta$ from $\tan\beta=\dfrac{\sqrt{(s_2c_3)^2+(s_2s_3)^2}}{c_2}$.

You get $\gamma$ from $\tan\gamma=\dfrac{s_3s_2}{c_3s_2}$.

As expected, $\beta=0$ creates an indeterminacy, but this case is easy to deal with (it reduces to a single rotation $\alpha+\gamma$).

You can probably improve the accuracy by a least-squares fitting of the matrix derived from the angles to the given matrix, but this will require the Levenberg-Marquardt algorithm as this is a non-linear problem.

I guess that you can also address the computation of the angles by using three well-chosen Givens rotations that will transform the input matrix to a unit one (backwards, $X_1Z_2X_3\to X_1Z_2\to X_1\to I$, corresponding to angles $(\alpha,\beta,\gamma)\to(\alpha,\beta,0)\to(\alpha,0,0)\to(0,0,0)$).

• Thanks for your answer. I was hoping for something simpler but I'll have to digest it a little bit to see if it's what I was looking for. – rmp251 Mar 13 '15 at 13:09
• The other option is to modify the angles randomly. – Yves Daoust Mar 13 '15 at 14:05