-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patheuler_rotation.m
170 lines (161 loc) · 6.41 KB
/
euler_rotation.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
function euler_rotation(R, alpha, beta, gamma)
%% Computes the "classical" Euler angle sequence
% This program computes the classical Euler angle sequence
%
% Jeremy Penn
% 18 October 2017
%
% Revision 19/10/17
%
% function eulerRotation(R, alpha, beta, gamma)
%
% Purpose: This function computes the Euler angle sequence about any 3
% axis sequence.
%
% Inputs: o R - A 1x3 vector of the satellite's initial position.
% o alpha - The primary Euler angle.
% o beta - The secondary Euler angle.
% o gamma - The tertiary Euler angle.
%
% Requires: rot1.m, rot2.m, rot3.m
%
clc;
%% Check the angles are between 0 and 360
alpha = mod(alpha, 360);
beta = mod(beta, 360);
gamma = mod(gamma, 360);
%% Convert to radians
alpha = alpha * pi/180;
beta = beta * pi/180;
gamma = gamma * pi/180;
%% Check that R is a column vector
if isrow(R)
R = transpose(R);
end
%% Calculate Euler angle sequences
str1 = input('Please choose the primary rotation axis ','s');
str2 = input('Please choose the secondary rotation axis ','s');
str3 = input('Please choose the tertiary rotation axis ','s');
switch str1
case 'x'
switch str2
case 'x'
switch str3
case 'z'
r = rot1(alpha)*rot1(beta)*rot3(gamma)*R;
case 'y'
r = rot1(alpha)*rot1(beta)*rot2(gamma)*R;
case 'x'
r = rot1(alpha)*rot1(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
case 'y'
switch str3
case 'z'
r = rot1(alpha)*rot2(beta)*rot3(gamma)*R;
case 'y'
r = rot1(alpha)*rot2(beta)*rot2(gamma)*R;
case 'x'
r = rot1(alpha)*rot2(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
case 'z'
switch str3
case 'z'
r = rot1(alpha)*rot3(beta)*rot3(gamma)*R;
case 'y'
r = rot1(alpha)*rot3(beta)*rot2(gamma)*R;
case 'x'
r = rot1(alpha)*rot3(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
otherwise
error('Input must be char not a %s',class(str2))
end
case 'y'
switch str2
case 'x'
switch str3
case 'z'
r = rot2(alpha)*rot1(beta)*rot3(gamma)*R;
case 'y'
r = rot2(alpha)*rot1(beta)*rot2(gamma)*R;
case 'x'
r = rot2(alpha)*rot1(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
case 'y'
switch str3
case 'z'
r = rot2(alpha)*rot2(beta)*rot3(gamma)*R;
case 'y'
r = rot2(alpha)*rot2(beta)*rot2(gamma)*R;
case 'x'
r = rot2(alpha)*rot2(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
case 'z'
switch str3
case 'z'
r = rot2(alpha)*rot3(beta)*rot3(gamma)*R;
case 'y'
r = rot2(alpha)*rot3(beta)*rot2(gamma)*R;
case 'x'
r = rot2(alpha)*rot3(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
otherwise
error('Input must be char not a %s',class(str2))
end
case 'z'
switch str2
case 'x'
switch str3
case 'z'
r = rot3(alpha)*rot1(beta)*rot3(gamma)*R;
case 'y'
r = rot3(alpha)*rot1(beta)*rot2(gamma)*R;
case 'x'
r = rot3(alpha)*rot1(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
case 'y'
switch str3
case 'z'
r = rot3(alpha)*rot2(beta)*rot3(gamma)*R;
case 'y'
r = rot3(alpha)*rot2(beta)*rot2(gamma)*R;
case 'x'
r = rot3(alpha)*rot2(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
case 'z'
switch str3
case 'z'
r = rot3(alpha)*rot3(beta)*rot3(gamma)*R;
case 'y'
r = rot3(alpha)*rot3(beta)*rot2(gamma)*R;
case 'x'
r = rot3(alpha)*rot3(beta)*rot1(gamma)*R;
otherwise
error('Input must be char not a %s',class(str3))
end
otherwise
error('Input must be char not a %s',class(str2))
end
otherwise
error('Input must be char not a %s',class(str1))
end
%% Display the results
fprintf('The new x-coordinate is %.2f\n',r(1))
fprintf('The new y-coordinate is %.2f\n',r(2))
fprintf('The new z-coordinate is %.2f\n',r(3))
end