Do rotation matrices rotate about inertial or body angles? [closed]

I have Yaw, pitch, and roll angles in that order (Euler 321) to apply to a body reference frame in cartesian coordinate system. I want to know what the body reference frame vector coordinates are after those angles are applied.

I start with a orthonormal reference frame $R$, apply the rotation matrices $R_Z$ then $R_Y$ and $R_X$, those being: $$R_{X}(\theta) = \begin{pmatrix}1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta\end{pmatrix},\qquad R_{Y}(\theta) = \begin{pmatrix}\cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta\end{pmatrix},\qquad R_{Z}(\theta) = \begin{pmatrix}\cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1\end{pmatrix}.$$ I have assumed rotation matrices rotate about the corresponding axis of the reference frame to which it's applied, not of the coordinate system, however Matlab seems to say otherwise when I plot the reference frames before and after: yaw is fine because it is the first operation, but during pitch Ybody is not invariant for example.

In contrast, I tried to replace each of the rotation matrices previously defined in: $$RotatedRefFrame=R_XR_YR_ZRefFrame$$ By the rotation matrix about an arbitrary axis: $$R_u = \begin{bmatrix} \cos \theta +u_x^2 \left(1-\cos \theta\right) & u_x u_y \left(1-\cos \theta\right) - u_z \sin \theta & u_x u_z \left(1-\cos \theta\right) + u_y \sin \theta \\ u_y u_x \left(1-\cos \theta\right) + u_z \sin \theta & \cos \theta + u_y^2\left(1-\cos \theta\right) & u_y u_z \left(1-\cos \theta\right) - u_x \sin \theta \\ u_z u_x \left(1-\cos \theta\right) - u_y \sin \theta & u_z u_y \left(1-\cos \theta\right) + u_x \sin \theta & \cos \theta + u_z^2\left(1-\cos \theta\right) \end{bmatrix}$$ Taking the axes off the reference frame, and it works.

My question is therefore: do rotation matrices rotate about BODY axes of the geometry rotated, or INERTIAL axes? The former case would mean I have an error in my code, but simplifying it to the edge of being just the mathematics presented and thoroughly debugging it step by step hasn't revealed any error.

closed as off-topic by ACuriousMind♦, Chris Mueller, JamalS, Ruslan, John RennieMar 21 '15 at 11:37

• This question does not appear to be about physics within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• I'm voting to close this question as off-topic because it is about debugging code. – ACuriousMind Mar 20 '15 at 13:52
• It is not about debugging code, the Matlab code is to prove the mathematics/physics, and it has proven it is wrong. – Mister Mystère Mar 20 '15 at 14:14
• I have to agree with @ACuriousMind , this is about debugging code. The Euler angle transformation matrices have been proven, applied over and over again and other than the issue of rotating through zenith have never failed to produce expected results. – docscience Mar 20 '15 at 14:22
• @MisterMystère Then something is wrong with your code, not the Euler transformations. – Chris Mueller Mar 20 '15 at 15:56
• "The only purpose of the code in this question is to prove the transformation maths are correct, and it has proven they weren't." ::facepalm:: To begin, to have a chance, to get anyone to even consider that your statement might possibly be true you'd need a lot of very clear and convincing test cases. Suspect your own code first is the mantra of ever skilled programmer. – dmckee Mar 20 '15 at 15:58

The columns of a 3×3 rotation matrix contain the coordinates of the local xyz axes (expressed in world coordinates). With Euler angles (321) you apply the elementary rotations $R_Z$, $R_Y$, $R_X$ in sequence to form the local → world rotation matrix. That is

$$E = R_Z(\varphi) R_Y(\psi) R_X(\theta)$$

This is interpreted as each rotation occuring about the currently local (intermediate axis). So the first rotation is about the world $\bar{Z}$ axis, but the second rotation is about the rotated $R_Z(\varphi) \bar{Y}$ axis. The convention is that $E$ works from local to world as in $$(\mbox{world vector}) = E \;(\mbox{local vector})$$ and in reverse $$(\mbox{local vector}) = E^\top \;(\mbox{world vector})$$

Note that to rotate about a local vector by $\theta$, for example the local $\bar{z}$ attached to a rigid body with orientation matrix $E$ you do the following

$${\rm Rot}(E \bar{z}, \theta) \equiv E\,R_Z(\theta)\,E^\top$$

which is interpreted as move to the local frame, rotate about the local Z and then move back to the world frame.

So when the inertia matrix is defined in body coordiantes, in needs to be transformed to world coordinates in order to be used in dynamics. This is done with:

$$I = E I_{body} E^\top$$

• I think the 321 sequence is RxRyRz, not RzRyRx -> C'=RzC for Z rotation, then C'' = RyC' for Y rotation, then C'''=RxC'' for X rotation. This is a clear answer, thanks. So you confirm that to get the coordinates of an object rotated with an Euler sequence 321 Rx(c)Ry(b)Rz(a)*InertialFrame is valid, and therefore the anomaly I've detected is in my code somewhere? – Mister Mystère Mar 20 '15 at 18:18
• 321 means rotate about Z, then Y then X and by convention it is RzRyRx. Othewise it would have been 123. 1=X, 2=Y, 3=Z. At least when we are talking about body coordinates. – ja72 Mar 20 '15 at 18:20
• I think you are using the inverse transformation. $$E^\top = R_X(-\theta) R_Y(-\psi) R_Z(-\varphi)$$ and hence the RxRyRz. Make sure you rotation matrix is interpreted local → world and not the othe way around. – ja72 Mar 20 '15 at 18:23
• Right, yes, I am defining a matrix world -> local because that's what I am trying to do (calculate coordinates of reference frame vectors from Euler angles). So could you confirm that to do this, bodyFrame = Rx(c)Ry(b)Rz(a)*InertialFrame is valid for a 321 sequence? That would mean I'm looking for errors in the wrong place. This is what I understand from your answer, but that's for confirmation. – Mister Mystère Mar 20 '15 at 18:38

Let's say you do the calculation $C_{final}=R_xR_yR_zC_{o}$, where the $C$s are coordinates. The first rotation is about the $z$ axis of $C_{o}$ and will produce a new coordinate system in which the new $z$ is the same as the old, but the $x$ and $y$ axes are different. The next rotation will be about the new $y$ axis and will produce a newer, new $x$ and a new $z$. The final rotation will be about the doubly rotated $x$.

NOTE: According to Arfken, Mathematical Methods for Physicists, and Brink & Satchler, Angular Momentum, Euler rotations occur in the order $R_z(\alpha)$, then $R_y(\beta)$, and finally $R_z(\gamma)$. So, the rotations are about original $z$, new $y=y'$, and new $z=z'$.

• Thanks for your answer. So can you confirm that RxRyRz rotate first about Z inertial, then Y', then X'', and not Z inertial, Y inertial, and X inertial? Regarding the note: Euler rotations have different definitions that are equally accepted from my experience - I chose a 321 sequence – Mister Mystère Mar 20 '15 at 18:13
• Euler rotations can occur in any order, and of course can lead to different outcomes since the math is non-commutative. The "according to ..." note refers to a convention accepted by some group. You can use any order as long as you are consistent with that convention. There is nothing universal, magic about the xyz sequence. After all I can always relabel the axes. – docscience Mar 20 '15 at 20:49
• @MisterMystère If by "inertial" you mean the original coordinate directions before any rotation matrices are applied, yes, I confirm. @docscience I agree you can apply the rotation matrices in any order you want. If they are called Euler angles, the third rotation is about the new axis that is the transformed first rotation axis: en.wikipedia.org/wiki/Euler_angles – Bill N Mar 20 '15 at 21:27
• Thanks BillN. After much hesitation I'll accept the other answer as I find it clearer, but that did help a lot (+1). – Mister Mystère Mar 21 '15 at 14:23