1-2-1 or X-Y-X rotation matrix not supported
Ältere Kommentare anzeigen
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?
Akzeptierte Antwort
Weitere Antworten (2)
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
1 Kommentar
James Tursa
am 20 Dez. 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( ).
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.
Kategorien
Mehr zu Quaternion Math finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!