Do rotation matrices rotate about inertial or body angles? 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.
 A: 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'$.
A: 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 $$
Related answers: 


*

*https://physics.stackexchange.com/a/113896/392

*https://physics.stackexchange.com/a/74484/392

*https://physics.stackexchange.com/a/72633/392
