Convert Quaternion to Euler angle extrinsically

조회 수: 77 (최근 30일)
Frank Martin
Frank Martin 2024년 1월 24일
편집: Bruno Luong 2024년 1월 26일
Hello,
I need to convert my results which are stored as quaternions into euler representation. The quat2eul and quat2angle functions seem the same and both will convert quaternions to euler angles. However, it is stated that they use intrinsic calculation (AKA rotation is done around Z axis, then Y' axis, then X'' axis). I need to convert extrinsically. I do not want each rotation to be based on the newly rotated axis. Is there any function in matlab to do this?
  댓글 수: 1
James Tursa
James Tursa 2024년 1월 25일
Please give an example of input and desired output. Maybe all you need to do is reorder.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2024년 1월 25일
편집: Matt J 2024년 1월 25일
Intrinsic euler angles can be converted to extrinsic euler angles just be reversing their order.
EDIT: In other words, a Z-Y'-X'' intrinsic rotation by psi, theta, and phi is the same as an X-Y-Z extrinsic rotation by phi, theta, and psi.
  댓글 수: 25
Paul
Paul 2024년 1월 26일
In this line:
rotmat(quaternion([phi theta psi], 'eulerd', 'XYZ', 'point'),'point')
we've specified one of the attributes as a point rotation. The usage of rotmat in the doc page ""Rotations, Orientation, and Quaternions" all show (at least as I recall) the output of rotmat is intended for right-multiplication by a vector. Given those two attributes are specified, are the Euler angles in that line of code intrinsic or extrinsic?
Bruno Luong
Bruno Luong 2024년 1월 26일
편집: Bruno Luong 2024년 1월 26일
q = quaternion([phi theta psi], 'eulerd', 'XYZ', 'point') returns quaternion for extrinsic point rotation (usage right multiplication by column vector of coordinates or q*v*conj(q))
phi = rand()*360;
theta = rand()*360;
psi = rand()*360;
q = quaternion([phi theta psi], 'eulerd', 'XYZ', 'point')
q = quaternion
-0.52669 + 0.56213i - 0.22555j - 0.59644k
% q = conj(quaternion(-[phi theta psi], 'eulerd', 'XYZ', 'frame'))
R = rotmat(q,'point')
R = 3×3
0.1868 -0.8819 -0.4330 0.3747 -0.3435 0.8612 -0.9081 -0.3231 0.2663
% Check euler decomposition of R
Rx = makehgtform('xrotate', deg2rad(phi));
Ry = makehgtform('yrotate', deg2rad(theta));
Rz = makehgtform('zrotate', deg2rad(psi));
R = Rz*Ry*Rx; R = R(1:3,1:3)
R = 3×3
0.1868 -0.8819 -0.4330 0.3747 -0.3435 0.8612 -0.9081 -0.3231 0.2663
% Verify point rotation using R and q
P = randn(3,1); % random point
RP1 = R*P
RP1 = 3×1
-0.2398 1.4719 -0.3082
v = quaternion(0,P(1),P(2),P(3));
tmp = q*v*conj(q);
[a,b,c,d] = parts(tmp);
RP2 = [b; c; d]
RP2 = 3×1
-0.2398 1.4719 -0.3082

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Bruno Luong
Bruno Luong 2024년 1월 26일
편집: Bruno Luong 2024년 1월 26일
Here is the answer by MATLAB code: extrinsic angles is flip intrinsic angles
% Generate random unit quaternion
q = quaternion(randn, randn, randn, randn);
q = q ./ norm(q)
q = quaternion
-0.50199 - 0.41335i + 0.75491j + 0.085223k
Order = 'ZYX'
Order = 'ZYX'
Ei = quat2eul(q, Order) % Intrinsic Euler angle
Ei = 1×3
-1.7849 -0.7580 2.2956
% Extrinsic Euler angle, simply flip order then flip resulting angles
Ee = fliplr(quat2eul(q, fliplr(Order)))
Ee = 1×3
1.8498 -0.9762 2.6051
% The rotation matrix corresponds to q
R = rotmat(q, 'frame')
R = 3×3
-0.1543 -0.7096 0.6875 -0.5385 0.6438 0.5437 -0.8284 -0.2863 -0.4815
% Check intrinsic frame decomposition, revers angle sign because we deal
% with "frame" rotation type, basic rotation compatible with specified
% Order 'ZYX'
Riz = makehgtform('zrotate', -Ei(1));
Riy = makehgtform('yrotate', -Ei(2));
Rix = makehgtform('xrotate', -Ei(3));
Ri = Rix*Riy*Riz; Ri = Ri(1:3,1:3) % it must match R
Ri = 3×3
-0.1543 -0.7096 0.6875 -0.5385 0.6438 0.5437 -0.8284 -0.2863 -0.4815
norm(Ri-R) % or this must be very small
ans = 4.8438e-16
% Check extrinsic frame decomposition
Rez = makehgtform('zrotate', -Ee(1));
Rey = makehgtform('yrotate', -Ee(2));
Rex = makehgtform('xrotate', -Ee(3));
Re = Rez*Rey*Rex; Re = Re(1:3,1:3) % it must match R
Re = 3×3
-0.1543 -0.7096 0.6875 -0.5385 0.6438 0.5437 -0.8284 -0.2863 -0.4815
norm(Re-R) % or this must be very small
ans = 6.5414e-16

Paul
Paul 2024년 1월 25일
Hi Frank,
According to a comment in this answer, there appears to be no function in any toolbox that works with extrinsic Euler angles.
It's possible that new functionality has been added in the intervening time or that the commenter was unaware of such functionality at that time.
Also, keep in mind that participants with a Staff flair are not providing official TMW responses here on Answers.

카테고리

Help CenterFile Exchange에서 6DOF에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by