# 1-2-1 or X-Y-X rotation matrix not supported

3 views (last 30 days)
SE on 20 Dec 2019
Commented: SE on 2 Jan 2020
Hi all,
I want to convert from euler to quaternion with 1-2-1 (respectively X-Y-X) rotation.
However, Matlab is not supporting this, is there a way to go around this?

James Tursa on 20 Dec 2019
According to the doc here:
The angle2quat supports the 'XYX' sequence. What functions are you using?
SE on 2 Jan 2020
Can you use the angle2quat( ) function from the Aerospace Toolbox instead?
--> this actually did the job, thanks!

Matt J on 20 Dec 2019
Edited: Matt J on 20 Dec 2019
You could compose the rotation matrix and use rotm2quat.
function quat = xyx2quat(eul)
Rx = @(x) [1, 0, 0;...
0, cos(x), -sin(x);...
0, sin(x), cos(x) ];
Ry= @(x) [cos(x), 0, sin(x); 0 1 0; -sin(x), 0, cos(x) ];
rotm=Rx(eul(3))*Ry(eul(2))*Rx(eul(1));
quat = rotm2quat(rotm);
end
James Tursa on 20 Dec 2019
There is a subtle difference here. In the MATLAB toolbox code and in the SpinCalc code, the assumption is that the angles represent the relationship between coordinate frames, whereas using the code above assumes the angles represent a vector rotation within the same coordinate frame. This difference results in the "opposite" sense of rotation. E.g., using the method above:
>> angles = [10,20,30];
>> rotm=Rx(angles(3))*Ry(angles(2))*Rx(angles(1));
>> quat = rotm2quat(rotm)
quat =
0.925416578398323 0.336824088833465 0.171010071662834 0.030153689607046
You can see that the last element has the opposite sign as the results using the angle2quat( ) and SpinCalc( ) functions. To get the same result as these functions, where the angles represent a rotation of the coordinate frames instead of a vector rotation, you need to reverse the order of the rotations with this method. E.g.,
>> rotm=Rx(angles(1))*Ry(angles(2))*Rx(angles(3));
>> quat = rotm2quat(rotm)
quat =
0.925416578398323 0.336824088833465 0.171010071662834 -0.030153689607046
Now you can see that the last element has the same sign as the result from angle2quat( ) and SpinCalc( ).

Jim Riggs on 20 Dec 2019
Edited: Jim Riggs on 20 Dec 2019
I recently cataloged all of the permutations of the 2 and 3 axis planar rotations.
It is easy to write your own functions.
See the attached paper for the method equations, the section on "Repeated Angle Rotations".
Here is an exerpt from the paper: See the paper for the definition of "direct" and "inverse" rotations. It effects the interpretation of the signs of the angles.
Once you calculate the Direction Cosine Matrix, you can convert it to a quaternion or a rotation vector.