## Rotations: from one Euler angle sequence to another

Let’s suppose we are given an Euler angle sequence ZYX with angles

as = {0.2, 0.25, 0.3}

We have been asked to convert that to ZYZ.

(You probably want to have read the previous quaternion posts.) I will remind us that the notation ZYX means the rotation

Rx Ry Rz,

with the Z-axis rotation first; and I write the angles in the same order, ZYX,, so the given rotation is

m0 = Rx(.3) Ry(.25) Rz(.2).

We do not need to compute it, but we might as well; if for no better reason than that we will be able to check our answer. The rotation matrix for the given Euler angle sequence works out to:

$m0 = \left(\begin{array}{ccc} 0.949599 & 0.192493 & -0.247404 \\ -0.118141 & 0.950819 & 0.286333 \\ 0.290353 & -0.242673 & 0.925637\end{array}\right)$

By the way, there is a good reason for writing it out as the product of three matrices, rather than calling my function which does the same calculation: we eliminate any ambiguity about the order of the rotation axes and the order of the angles. It is informative to display the actual order of the matrix multiplications and the order of the angles.

The most direct path to the ZYZ Euler angle sequence we want to find is to convert the given ZYX Euler angle sequence to a quaternion…

q1=eToQ["ZYX",as] = Quaternion[0.978015, 0.135224, 0.137461, 0.0794041].

… and convert that to a ZYZ Euler angle sequence:

We should note that all three angles have changed… just in case you were wondering if any part of ZYX was preserved when we went to ZYZ. No, this is a matter of simultaneous equations.

I had not encoded this Euler sequence originally, so I had to add it. While I was there I decided that I wanted to print the equations constructed by Mathematica®. As I’ve said before, I let Mathematica work them out for me every time.

There is one piece of trickery: my three variables are always sx, sy, and sz. Those stand for “sine of x”, “sine of y”, and “sine of z”. But the meanings attached to x,y,z vary.

For the ZYX Euler angle sequence (or for XYZ if I ever encode it, or anything else with 3 distinct axes) those in turn are shorthand for “sine of the rotation angle about the x-axis”, “sine of the rotation angle about the y-axis”, and “sine of the rotation angle about the z-axis”. Perfect.

But what about the ZYZ that we just worked? Well, sy is the sine of the rotation angle about the y-axis… but sz is the sine of the rotation angle for the first z-axis rotation… and sx, for which there is no x-axis, is the sine of the rotation angle about the second z-axis.

It was far easier to set it up that way, than to create different variable names for different cases. While Mathematica determined the equations for me, I laid out the association of the three unknowns with the appropriate quaternions.

For the other possibility, ZXZ, your guess would be correct if you said: sx is what it should be (the rotation angle about the x-axis), sz is the rotation angle for the first z-axis rotation, and sy is used for the rotation angle for the second z-axis rotation.

Anyway, having said all that, let’s construct the rotation from the newly found ZYZ Euler angle sequence:

m1=eToRot[“ZYZ”,e1[[2]]],

getting

$m1 = \left(\begin{array}{ccc} 0.949599 & 0.192493 & -0.247404 \\ -0.118141 & 0.950819 & 0.286333 \\ 0.290353 & -0.242673 & 0.925637\end{array}\right)$

That is the same rotation matrix. We done good.

That’s it, that’s all we needed. We went from a ZYX Euler angle sequence to its quaternion representation and then to a ZYZ Euler angle sequence. And we checked our work by computing the rotation matrix from both Euler angle sequences that represent it.

But just for completeness, let me convert the quaternion q0 — it’s the only one we have today — back to ZYX, which is what we were given:

For the record, those last three numbers had sines labeled sy, sx, sz, in order.

There are my equations, just in case it was killing you not to see them. And bear in mind that my convention is, to put it differently: if a rotation axis occurs once, use its name; if a rotation axis occurs twice, use its name for the first rotation angle, and use the symbol of the missing axis for the second rotation.

So, short and sweet. One simple example, and the equations for getting from a quaternion to ZYX, ZYZ, or ZXZ Euler angle sequences.