I'm trying to understand composition of rotations using eulers angles and rotation matrices. I am facing a counterintuitive situation performing two rotations about different angles. My setting is the following:
- first rotation of an angle $\psi$ about the Z body-axis (yaw)
- second rotation of an angle $\theta$ about the Y body-axis (pitch)
- third rotation of an angle $\varphi$ about the X body-axis (roll)
Denoting with
$$R_X=\begin{bmatrix}1&0&0\\ 0&\cos(\varphi)&-\sin(\varphi)\\ 0&\sin(\varphi)&\cos(\varphi)\end{bmatrix}$$ $$R_Y=\begin{bmatrix}\cos(\theta)&0&\sin(\theta)\\ 0&1&0\\ -\sin(\theta)&0&\cos(\theta)\end{bmatrix}$$ $$R_Z=\begin{bmatrix}\cos(\psi)&-\sin(\psi)&0\\ \sin(\psi)&\cos(\psi)&0\\ 0&0&1\end{bmatrix}$$
the rotation matrices relative to elementary rotation about the three body axis, I obtain that a general rotation of eulers angles $(yaw,pitch,roll)=(\psi,\theta,\varphi)$ is given by:
$$R=R_X\cdot R_Y\cdot R_Z$$
Suppose now that I would like to perform this 2 consecutive rotations:
- Rotation of $(yaw,pitch,roll)=(0,\frac{\pi}{4},0)$
- Rotation of $(yaw,pitch,roll)=(\frac{\pi}{2},0,0)$
The matrices relative to these two rotations are the following:
$$R_1=\begin{bmatrix}\frac{\sqrt{2}}{2}&0&\frac{\sqrt{2}}{2}\\ 0&1&0\\ -\frac{\sqrt{2}}{2}&0&\frac{\sqrt{2}}{2}\end{bmatrix}$$ $$R_2=\begin{bmatrix}1&0&0\\ 0&0&-1\\ 0&1&0\end{bmatrix}$$
and composing them I obtain the total rotation matrix
$$R=R_2\cdot R_1 = \begin{bmatrix}0&-1&0\\ \frac{\sqrt{2}}{2}&0&\frac{\sqrt{2}}{2}\\ -\frac{\sqrt{2}}{2}&0&\frac{\sqrt{2}}{2}\end{bmatrix}$$
If I want to recover the euler angles sequence relative to $R$ I apply these equations:
$$\theta=\arcsin(R_{13})\\ \psi=-\arctan2\left(\frac{R_{12}}{\cos(\theta)},\frac{R_{11}}{\cos(\theta)}\right)\\ \varphi=-\arctan2\left(\frac{R_{23}}{\cos(\theta)},\frac{R_{33}}{\cos(\theta)}\right)$$
obtaining $(yaw,pitch,roll)=(\frac{\pi}{2},0,-\frac{\pi}{4})$.
However applying this sequence of rotation I do not recover the initial frame (sequence of rotations 1-2) unless the rotations 1-2 are performed on different axis respect the body ones.
Probably I miss something and I'm making confusion with these concepts. Please, could you help me to understand where I miss?