use matlab to calculate euler angles from rotation matrix, and then calculate rotation matrix. Why is the input matrix different from the output one?

use matlab to calculate euler angles from rotation matrix, and then calculate rotation matrix. Why is the input matrix different from the output one?

Answers (2)

2 Comments

It is for a specific example. The related code is as following. At first, I get a rotation matrix: rcurr; Then use the following code to calculate euler angles.
nPhi=acos(rcurr(3,3));
nphi1=atan2(rcurr(3,1),-rcurr(3,2));
nphi2=atan2(rcurr(1,3),rcurr(2,3));
euler(i,1:3)=[nphi1 nPhi nphi2]/pi*180;
for j=1:3
if euler(i,j)<0
euler(i,j)=euler(i,j)+360;
elseif euler(i,j)>360
euler(i,j)=euler(i,j)-360;
end
end
end
The output euler angles were stored for the next step. At next step, I use the following code to calculate rotation matrix from euler angles.
r=[cos(phi1)*cos(phi2)-sin(phi1)*sin(phi2)*cos(Phi) sin(phi1)*cos(phi2)+cos(phi1)*sin(phi2)*cos(Phi) sin(phi2)*sin(Phi);
-cos(phi1)*sin(phi2)-sin(phi1)*cos(phi2)*cos(Phi) -sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2)*cos(Phi) cos(phi2)*sin(Phi);
sin(phi1)*sin(Phi) -cos(phi1)*sin(Phi) cos(Phi)];
while the output "r" is slightly different from the rotation matrix "rcurr" obtained in the previous step.
By the way, the difference only exists in my specific code. If I pick out the above code separately, and test the result, the input "rcurr" and output "r" are the same.
So I don't know what kind of problem can cause this thing.
Without formatting the code is nearly unreadable. Please post one command per line.

Sign in to comment.

Asked:

on 30 Jan 2016

Answered:

on 1 Feb 2016

Community Treasure Hunt

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

Start Hunting!