recover basic rotations
2 次查看(过去 30 天)
显示 更早的评论
Dear reader.
Is it possible to recover the basic rotations from a general rotation matrix? i do know the order of rotating. It is for a mechanical model in simmechanics, where i use the body sensor to retrieve the matrix. I used the following test script to see if it is possible, but the result is not always ok. Is there another way to get the basic rotations that is always succes?
% recover generalized coordinates from a general 3d rotation matrix
clear all
q0=rand*2*pi-pi;
q1=rand*2*pi-pi;
q2=rand*2*pi-pi;
s0 =sin(q0); c0=cos(q0);
s1 =sin(q1); c1=cos(q1);
s2 =sin(q2); c2=cos(q2);
R0 = [c0 -s0 0;s0 c0 0;0 0 1];
R1 = [1 0 0;0 c1 -s1;0 s1 c1];
R2 = [c2 0 s2;0 1 0;-s2 0 c2];
Rm1=R0*R1*R2;
% now try to recover q0,q1 and q2 from R
q1_rec = asin(Rm1(3,2));
q0_rec = atan2(-Rm1(1,2),Rm1(2,2));
q2_rec = atan2(-Rm1(3,1),Rm1(3,3));
% comparison of rotations with recovered rotations
format long
[q0 q1 q2;q0_rec q1_rec q2_rec]
format short
s0 =sin(q0_rec); c0=cos(q0_rec);
s1 =sin(q1_rec); c1=cos(q1_rec);
s2 =sin(q2_rec); c2=cos(q2_rec);
R0 = [c0 -s0 0;s0 c0 0;0 0 1];
R1 = [1 0 0;0 c1 -s1;0 s1 c1];
R2 = [c2 0 s2;0 1 0;-s2 0 c2];
Rm1_rec=R0*R1*R2;
Rm1-Rm1_rec
0 个评论
回答(2 个)
Jan
2011-9-8
The shown code and the results look fine. Due to rounding errors you cannot reproduce the inputs exactly. Especially if q1 is near to +-Pi/2 rounding errors are amplified. To learn more about this problem look for Google: gimbal lock.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assembly 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!