Skip to content

Commit 7617093

Browse files
committed
🔧 📚 Small improvements in euler_angles.jl
1 parent 577b98b commit 7617093

File tree

1 file changed

+41
-53
lines changed

1 file changed

+41
-53
lines changed

src/euler_angles.jl

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -58,83 +58,71 @@ function angle2dcm(angle_r1::Number,
5858
s3 = sin(angle_r3)
5959

6060
if rot_seq == :ZYX
61-
dcm = DCM( c2*c1 , c2*s1 , -s2 ,
62-
s3*s2*c1 - c3*s1, s3*s2*s1 + c3*c1, s3*c2,
63-
c3*s2*c1 + s3*s1, c3*s2*s1 - s3*c1, c3*c2)'
64-
return dcm
61+
return DCM( c2*c1 , c2*s1 , -s2 ,
62+
s3*s2*c1 - c3*s1, s3*s2*s1 + c3*c1, s3*c2,
63+
c3*s2*c1 + s3*s1, c3*s2*s1 - s3*c1, c3*c2)'
6564

6665
elseif rot_seq == :XYX
67-
dcm = DCM( c2 , s1*s2 , -c1*s2 ,
68-
s2*s3, -s1*c2*s3 + c1*c3, c1*c2*s3 + s1*c3,
69-
s2*c3, -s1*c3*c2 - c1*s3, c1*c3*c2 - s1*s3)'
70-
return dcm
66+
return DCM( c2 , s1*s2 , -c1*s2 ,
67+
s2*s3, -s1*c2*s3 + c1*c3, c1*c2*s3 + s1*c3,
68+
s2*c3, -s1*c3*c2 - c1*s3, c1*c3*c2 - s1*s3)'
7169

7270
elseif rot_seq == :XYZ
73-
dcm = DCM( c2*c3, s1*s2*c3 + c1*s3, -c1*s2*c3 + s1*s3,
74-
-c2*s3, -s1*s2*s3 + c1*c3, c1*s2*s3 + s1*c3,
75-
s2 , -s1*c2 , c1*c2)'
76-
return dcm
71+
return DCM( c2*c3, s1*s2*c3 + c1*s3, -c1*s2*c3 + s1*s3,
72+
-c2*s3, -s1*s2*s3 + c1*c3, c1*s2*s3 + s1*c3,
73+
s2 , -s1*c2 , c1*c2)'
7774

7875
elseif rot_seq == :XZX
79-
dcm = DCM( c2 , c1*s2 , s1*s2 ,
80-
-s2*c3, c1*c3*c2 - s1*s3, s1*c3*c2 + c1*s3,
81-
s2*s3, -c1*c2*s3 - s1*c3, -s1*c2*s3 + c1*c3)'
82-
return dcm
76+
return DCM( c2 , c1*s2 , s1*s2 ,
77+
-s2*c3, c1*c3*c2 - s1*s3, s1*c3*c2 + c1*s3,
78+
s2*s3, -c1*c2*s3 - s1*c3, -s1*c2*s3 + c1*c3)'
8379

8480
elseif rot_seq == :XZY
85-
dcm = DCM(c3*c2, c1*c3*s2 + s1*s3, s1*c3*s2 - c1*s3,
86-
-s2 , c1*c2 , s1*c2 ,
87-
s3*c2, c1*s2*s3 - s1*c3, s1*s2*s3 + c1*c3)'
88-
return dcm
81+
return DCM(c3*c2, c1*c3*s2 + s1*s3, s1*c3*s2 - c1*s3,
82+
-s2 , c1*c2 , s1*c2 ,
83+
s3*c2, c1*s2*s3 - s1*c3, s1*s2*s3 + c1*c3)'
8984

9085
elseif rot_seq == :YXY
91-
dcm = DCM(-s1*c2*s3 + c1*c3, s2*s3 , -c1*c2*s3 - s1*c3,
92-
s1*s2 , c2 , c1*s2 ,
93-
s1*c3*c2 + c1*s3, -s2*c3, c1*c3*c2 - s1*s3)'
94-
return dcm
86+
return DCM(-s1*c2*s3 + c1*c3, s2*s3 , -c1*c2*s3 - s1*c3,
87+
s1*s2 , c2 , c1*s2 ,
88+
s1*c3*c2 + c1*s3, -s2*c3, c1*c3*c2 - s1*s3)'
9589

9690
elseif rot_seq == :YXZ
97-
dcm = DCM( c1*c3 + s2*s1*s3, c2*s3, -s1*c3 + s2*c1*s3,
98-
-c1*s3 + s2*s1*c3, c2*c3, s1*s3 + s2*c1*c3,
99-
s1*c2 , -s2 , c2*c1 )'
100-
return dcm
91+
return DCM( c1*c3 + s2*s1*s3, c2*s3, -s1*c3 + s2*c1*s3,
92+
-c1*s3 + s2*s1*c3, c2*c3, s1*s3 + s2*c1*c3,
93+
s1*c2 , -s2 , c2*c1 )'
10194

10295
elseif rot_seq == :YZX
103-
dcm = DCM( c1*c2 , s2 , -s1*c2 ,
104-
-c3*c1*s2 + s3*s1, c2*c3, c3*s1*s2 + s3*c1,
105-
s3*c1*s2 + c3*s1, -s3*c2, -s3*s1*s2 + c3*c1)'
106-
return dcm
96+
return DCM( c1*c2 , s2 , -s1*c2 ,
97+
-c3*c1*s2 + s3*s1, c2*c3, c3*s1*s2 + s3*c1,
98+
s3*c1*s2 + c3*s1, -s3*c2, -s3*s1*s2 + c3*c1)'
10799

108100
elseif rot_seq == :YZY
109-
dcm = DCM(c1*c3*c2 - s1*s3, s2*c3, -s1*c3*c2 - c1*s3,
110-
-c1*s2 , c2 , s1*s2 ,
111-
c1*c2*s3 + s1*c3, s2*s3, -s1*c2*s3 + c1*c3)'
112-
return dcm
101+
return DCM(c1*c3*c2 - s1*s3, s2*c3, -s1*c3*c2 - c1*s3,
102+
-c1*s2 , c2 , s1*s2 ,
103+
c1*c2*s3 + s1*c3, s2*s3, -s1*c2*s3 + c1*c3)'
113104

114105
elseif rot_seq == :ZXY
115-
dcm = DCM(c3*c1 - s2*s3*s1, c3*s1 + s2*s3*c1, -s3*c2,
116-
-c2*s1 , c2*c1 , s2 ,
117-
s3*c1 + s2*c3*s1, s3*s1 - s2*c3*c1, c2*c3)'
118-
return dcm
106+
return DCM(c3*c1 - s2*s3*s1, c3*s1 + s2*s3*c1, -s3*c2,
107+
-c2*s1 , c2*c1 , s2 ,
108+
s3*c1 + s2*c3*s1, s3*s1 - s2*c3*c1, c2*c3)'
119109

120110
elseif rot_seq == :ZXZ
121-
dcm = DCM(-s1*c2*s3 + c1*c3, c1*c2*s3 + s1*c3, s2*s3,
122-
-s1*c3*c2 - c1*s3, c1*c3*c2 - s1*s3, s2*c3,
123-
s1*s2 , -c1*s2 , c2)'
124-
return dcm
111+
return DCM(-s1*c2*s3 + c1*c3, c1*c2*s3 + s1*c3, s2*s3,
112+
-s1*c3*c2 - c1*s3, c1*c3*c2 - s1*s3, s2*c3,
113+
s1*s2 , -c1*s2 , c2)'
125114

126115
elseif rot_seq == :ZYZ
127-
dcm = DCM( c1*c3*c2 - s1*s3, s1*c3*c2 + c1*s3, -s2*c3,
128-
-c1*c2*s3 - s1*c3, -s1*c2*s3 + c1*c3, s2*s3,
129-
c1*s2 , s1*s2 , c2)'
130-
return dcm
116+
return DCM( c1*c3*c2 - s1*s3, s1*c3*c2 + c1*s3, -s2*c3,
117+
-c1*c2*s3 - s1*c3, -s1*c2*s3 + c1*c3, s2*s3,
118+
c1*s2 , s1*s2 , c2)'
131119
else
132120
throw(ArgumentError("The rotation sequence :$rot_seq is not valid."))
133121
end
134122
end
135123

136124
"""
137-
### function angle2dcm(eulerang::EulerAngles{T}) where T<:Real
125+
### function angle2dcm(eulerang::EulerAngles)
138126
139127
Convert the Euler angles `eulerang` (see `EulerAngles`) to a direction cosine
140128
matrix.
@@ -157,15 +145,15 @@ the *i*-th rotation, `i Є [1,2,3]`.
157145
dcm = angle2dcm(EulerAngles(pi/2, pi, pi/4, :ZYX))
158146
159147
"""
160-
function angle2dcm(eulerang::EulerAngles{T}) where T<:Real
148+
function angle2dcm(eulerang::EulerAngles)
161149
angle2dcm(eulerang.a1,
162150
eulerang.a2,
163151
eulerang.a3,
164152
eulerang.rot_seq)
165153
end
166154

167155
"""
168-
### function smallangle2dcm(θx::Number, θy::Number, θz::Number) where T<:Real
156+
### function smallangle2dcm(θx::Number, θy::Number, θz::Number)
169157
170158
Create a direction cosine matrix from three small rotations of angles `θx`,
171159
`θy`, and `θz` about the axes X, Y, and Z, respectively.
@@ -189,7 +177,7 @@ No process of ortho-normalization is performed with the computed DCM.
189177
dcm = smallangle2dcm(+0.01, -0.01, +0.01)
190178
191179
"""
192-
function smallangle2dcm( θx::Number, θy::Number, θz::Number)
180+
function smallangle2dcm(θx::Number, θy::Number, θz::Number)
193181
DCM( 1, +θz, -θy,
194182
-θz, 1, +θx,
195183
+θy, -θx, 1)'
@@ -358,7 +346,7 @@ function angle2quat(angle_r1::Number,
358346
end
359347

360348
"""
361-
### function angle2quat(eulerang::EulerAngles{T}) where T<:Real
349+
### function angle2quat(eulerang::EulerAngles)
362350
363351
Convert the Euler angles `eulerang` (see `EulerAngles`) to a quaternion.
364352

0 commit comments

Comments
 (0)