1

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.

Mister Mystère
  • 987
  • 9
  • 25
  • 5
    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
  • 1
    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
  • I beg to differ, as I have just tried with the same code but with a rotation matrix based on arbitrary axis (taking the correct axis of the reference frame) and it works. It starts to become clear that the rotation matrices are about inertial axes, which makes an Euler321 DCM RxRyRz*geometry totally wrong... – Mister Mystère Mar 20 '15 at 14:36
  • 1
    @MisterMystère Then something is wrong with your code, not the Euler transformations. – Chris Mueller Mar 20 '15 at 15:56
  • 1
    "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 --- ex-moderator kitten Mar 20 '15 at 15:58
  • That's what I did, and even with 3 lines of code + 3 to display which are EXACTLY implementing Rotated=RxRyRz*Frame, the result is the same: Ybody moves when it shouldn't. My question is simple: does the matrix RxRyRz turns first about Z inertial, then Y inertial and X inertial, or Z inertial (=Z body), Y body, and X body? Because it really seems like it's the first case. – Mister Mystère Mar 20 '15 at 16:29
  • Start learning to debug. In your case the best way (from my perspective) would be trying to see what happens on each step, first with only $R_Z$ with varying angle, then with $R_YR_Z$ with varying angles, then with the whole transformation, and then you'd be able to see what happens and where the mistake is. Currently this question is not only off topic, but also shows insufficient effort. – Ruslan Mar 20 '15 at 16:44
  • Not if I tell you I've already debugged it step by step. The error might be in the code, but after extensively debugging it my second option was that I wasn't understanding the rotation matrices correctly and that's why I'm here. There is a possibility that after correctly debugging a code it turns out the error is still in there, but I am starting to doubt my assumptions related to the use of 3D algebra. If you tell me RxRyRz rotates about BODY ANGLES then the error is definitely in the code somewhere - is it the case? – Mister Mystère Mar 20 '15 at 16:49
  • I have now updated my post to show more clearly what I am asking. I do apologise for the lack of clarity, but I am disappointed in the aggressivity I sense given that I never post without prior efforts, and I contribute to this forum and other SEs. – Mister Mystère Mar 20 '15 at 16:57
  • You have two different matrices labelled as $R_X(\theta)$. The 3rd should be labelled as $R_Z(\theta)$. – Bill N Mar 20 '15 at 17:36

2 Answers2

1

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'$.

Bill N
  • 15,410
  • 3
  • 38
  • 60
  • 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: http://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
1

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:

John Alexiou
  • 38,341
  • 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. – John Alexiou 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. – John Alexiou 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