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:

  1. Rotation of $(yaw,pitch,roll)=(0,\frac{\pi}{4},0)$
  2. 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?

  • 1
    $\begingroup$ A side comment : I have seen that you haven't checked any answer to your your last 15 questions (some of them are 1 year old). This is definitely not a good practise on this site. Moreover, it takes such a few time to do it... Consider a max. 2-4 weeks delay for checking answers (thorough answers of course). $\endgroup$ – Jean Marie May 28 at 9:04
  • $\begingroup$ If you want to recover Euler angles, are you aware that you have to use twice a $R_Z$ type matrix (mathworld.wolfram.com/EulerAngles.html) ? $\endgroup$ – Jean Marie May 28 at 9:16
  • 1
    $\begingroup$ @JeanMarie you're right. I checked all my previous questions and I have choosen an answer for them. For the second comment I cannot understand it. For yaw,pitch and roll I mean rotations about three different axis (maybe I call them Euler's angles improperly). $\endgroup$ – aleio1 May 29 at 9:11
  • $\begingroup$ Honestly, I am not accustomed to YPR. But I have seen that indeed, you are using $R_Z$ twice ; thus it is the same as Euler's angles ; see as well math.stackexchange.com/q/147028. $\endgroup$ – Jean Marie May 29 at 18:19

I believe the problem you are having is that if you multiply the matrices in the order $R_X\cdot R_Y\cdot R_Z$, then you are rotating first around the global $Z$ axis, then the global $Y$ axis, then the global $X$ axis.

To get the rotations applied to the local (body) axes instead, you simply have to reverse the order of multiplication.

This might seem like magic, so I'll give a short explanation. After applying the $Z$-axis rotation, the body reference frame is not the same as the global reference frame: It has been rotated by $R_Z$. So at this point, if $A$ is a matrix denoting any transformation according to the body frame, then in the global frame that same transformation has the matrix representation $$ R_Z\cdot A\cdot R_Z^{-1} $$ (This will take a vector expressed in the global basis, then $R_Z^{-1}$ is the same vector expressed in the body basis. We apply $A$, then translate back to the global basis with $R_Z$.)

So first applying $R_Z$, then after that applying $R_Y$ in the new local frame has matrix representation $$ \left(R_Z\cdot R_Y\cdot R_Z^{-1}\right)\cdot R_Z = R_Z\cdot R_Y $$ If you want to apply a rotation about the body $X$-axis after this again, then similarily, the global matrix representation of this transformation is $$ (R_Z\cdot R_Y)\cdot R_X\cdot (R_Z\cdot R_Y)^{-1} $$ and if we apply this after our initial rotation of $R_Z\cdot R_Y$, then the result becomes $$ R_Z\cdot R_Y\cdot R_X $$

  • $\begingroup$ Thank you. You were very clear. So, if I would like to apply two consecutive rotations, say $R_1,R_2$, I need to premultiply body vectors by $R_1\cdot R_2\cdot R_1^{-1}$ isn't it? Is there a simpler (and computational cheaper) way? $\endgroup$ – aleio1 May 29 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.