1-2-1 or X-Y-X rotation matrix not supported
조회 수: 7 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
James Tursa
2019년 12월 20일
According to the doc here:
The angle2quat supports the 'XYX' sequence. What functions are you using?
댓글 수: 3
James Tursa
2019년 12월 20일
편집: James Tursa
2019년 12월 20일
Can you use the angle2quat( ) function from the Aerospace Toolbox instead? A bit strange that eul2quat( ) has this limitation when other functions in MATLAB do not. Maybe should submit an enhancement request to MathWorks for this oversight. The quat2eul( ) function also has this limitation.
Another option is to use a utility like SpinCalc by John Fuller that can be found in the FEX:
But if you use SpinCalc, be aware that it will return quaternions in Vector-Scalar order. Whereas the MATLAB toolbox functions work with quaternions in Scalar-Vector order. So you would need to manually adjust the result of SpinCalc to put it into the MATLAB convention. E.g.,
>> angdeg = [10,20,30];
>> angrad = angdeg*pi/180;
>> qsv = angle2quat(angrad(1),angrad(2),angrad(3),'XYX')
qsv =
0.925416578398323 0.336824088833465 0.171010071662834 -0.030153689607046
>> qvs = SpinCalc('EA121toQ',angdeg)
qvs =
0.336824088833465 0.171010071662834 -0.030153689607046 0.925416578398323
>> [qvs(4),qvs(1:3)]
ans =
0.925416578398323 0.336824088833465 0.171010071662834 -0.030153689607046
>> SpinCalc('QtoEA121',qvs,1e-10,0)
ans =
10.000000000000002 19.999999999999993 30.000000000000004
추가 답변 (2개)
Matt J
2019년 12월 20일
편집: Matt J
2019년 12월 20일
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
James Tursa
2019년 12월 20일
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
2019년 12월 20일
편집: Jim Riggs
2019년 12월 20일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Quaternion Math에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!