-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrotmat2eulang.m
49 lines (38 loc) · 1.34 KB
/
rotmat2eulang.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function eul = rotmat2eulang(R,order)
% ROTMAT2EULANG Calculates fixed-euler angles from rotation matrix
% 20201030 download from https://github.com/wspr/matlab-euler-angles/blob/master/rotmat2eulang.m
% * `R`: Rotation matrix (3x3)
% * `order`: Order of Euler angles to return; any of:
% {'XYZ','XZY','YXZ','YZX','ZYX','ZXY'}
% * `EUL`: Euler angles in specified order
%
switch order
case 'XYZ'
eul(1) = atan2(-R(2,3),R(3,3)).*180./pi;
eul(2) = asin(R(1,3)).*180./pi;
eul(3) = atan2(-R(1,2),R(1,1)).*180./pi;
case 'XZY'
eul(1) = atan2(R(3,2),R(2,2)).*180./pi;
eul(2) = -asin(R(1,2)).*180./pi;
eul(3) = atan2(R(1,3),R(1,1)).*180./pi;
case 'YXZ'
eul(1) = atan2(R(1,3),R(3,3)).*180./pi;
eul(2) = -asin(R(2,3)).*180./pi;
eul(3) = atan2(R(2,1),R(2,2)).*180./pi;
case 'YZX'
eul(1) = atan2(-R(3,1),R(1,1)).*180./pi;
eul(2) = asin(R(2,1)).*180./pi;
eul(3) = atan2(-R(2,3),R(2,2)).*180./pi;
case 'ZXY'
eul(1) = atan2(-R(1,2),R(2,2)).*180./pi;
eul(2) = asin(R(3,2)).*180./pi;
eul(3) = atan2(-R(3,1),R(3,3)).*180./pi;
case 'ZYX'
eul(1) = atan2(R(2,1),R(1,1)).*180./pi;
eul(2) = -asin(R(3,1)).*180./pi;
eul(3) = atan2(R(3,2),R(3,3)).*180./pi;
otherwise
error('Don''t know specified rotation order %s', order)
end
end
% Licence included in README.