Conversion between Euler angles and rotation matrix --- Matlab code

4,108 views
Skip to first unread message

Hiho

unread,
Apr 10, 2008, 11:37:07 PM4/10/08
to MathTools
function orthm = ang2orth(ang)

sa = sin(ang(2)); ca = cos(ang(2));
sb = sin(ang(1)); cb = cos(ang(1));
sc = sin(ang(3)); cc = cos(ang(3));

ra = [ ca, sa, 0; ...
-sa, ca, 0; ...
0, 0, 1];
rb = [ cb, 0, sb; ...
0, 1, 0; ...
-sb, 0, cb];
rc = [ 1, 0, 0; ...
0, cc, sc;...
0, -sc, cc];
orthm = rc*rb*ra;

function ang = orth2ang(orthm)
ang(1) = asin(orthm(1,3)); %Wei du
ang(2) = angle( orthm(1,1:2)*[1 ;i] ); %Jing Du
yz = orthm* ...
[orthm(1,:)',...
[-sin(ang(2)); cos(ang(2)); 0],...
[-sin(ang(1))*cos(ang(2)); -sin(ang(1)*sin(ang(2)));
cos(ang(1))] ];

ang(3) = angle(yz(2,2:3)* [1; i]); % Xuan Du

Sha Ma

unread,
Apr 11, 2008, 1:16:24 AM4/11/08
to math...@googlegroups.com
hehe,thank you very much!!! ^_^

2008/4/11, Hiho <haifen...@gmail.com>:

Haifeng Gong

unread,
Apr 11, 2008, 1:20:15 PM4/11/08
to math...@googlegroups.com
hehe

I use this Google Group to preserve my reusable code.

Haifeng

--
Haifeng GONG
Post-doctoral Scholar
Department of Statistics, UCLA

anon

unread,
Jan 9, 2017, 11:25:36 PM1/9/17
to MathTools
Reply all
Reply to author
Forward
0 new messages