@@ -11,29 +11,19 @@ Follows the Hamilton convention for quaternions.
11
11
QuatRotation(w,x,y,z)
12
12
QuatRotation(q::AbstractVector)
13
13
```
14
- where `w` is the scalar (real) part, `x`,`y`, and `z` are the vector (imaginary) part,
14
+ where `w` is the scalar (real) part, `x`, `y`, and `z` are the vector (imaginary) part,
15
15
and `q = [w,x,y,z]`.
16
16
"""
17
17
struct QuatRotation{T} <: Rotation{3,T}
18
18
q:: Quaternion{T}
19
19
20
- @inline function QuatRotation {T} (w, x, y, z , normalize:: Bool = true ) where T
20
+ @inline function QuatRotation {T} (q :: Quaternion , normalize:: Bool = true ) where T
21
21
if normalize
22
- inorm = inv (sqrt (w* w + x* x + y* y + z* z))
23
- new {T} (Quaternion (w* inorm, x* inorm, y* inorm, z* inorm, true ))
22
+ new {T} (sign (q))
24
23
else
25
- new {T} (Quaternion (w, x, y, z, true ))
26
- end
27
- end
28
-
29
- @inline function QuatRotation {T} (q:: Quaternion ) where T
30
- if q. norm
31
24
new {T} (q)
32
- else
33
- throw (InexactError (nameof (T), T, q))
34
25
end
35
26
end
36
- QuatRotation {T} (q:: QuatRotation ) where T = new {T} (q. q)
37
27
end
38
28
39
29
function Base. getproperty (q:: QuatRotation , f:: Symbol )
52
42
53
43
# ~~~~~~~~~~~~~~~ Constructors ~~~~~~~~~~~~~~~ #
54
44
# Use default map
45
+ function QuatRotation {T} (w,x,y,z, normalize:: Bool = true ) where T
46
+ QuatRotation {T} (Quaternion (w,x,y,z), normalize)
47
+ end
55
48
function QuatRotation (w,x,y,z, normalize:: Bool = true )
56
49
types = promote (w,x,y,z)
57
- QuatRotation {eltype(types)} (w,x,y,z, normalize)
50
+ QuatRotation {float( eltype(types) )} (w,x,y,z, normalize)
58
51
end
59
52
60
- function QuatRotation (q:: T ) where T<: Quaternion
61
- if q. norm
62
- return QuatRotation (real (q), imag_part (q)... , false )
63
- else
64
- throw (InexactError (nameof (T), T, q))
65
- end
53
+ function QuatRotation (q:: Quaternion{T} , normalize:: Bool = true ) where T<: Real
54
+ return QuatRotation {float(T)} (q, normalize)
66
55
end
67
56
68
57
function Quaternions. Quaternion (q:: QuatRotation )
84
73
85
74
# Copy constructors
86
75
QuatRotation (q:: QuatRotation ) = q
76
+ QuatRotation {T} (q:: QuatRotation ) where T = QuatRotation {T} (q. q)
87
77
88
78
# QuatRotation <=> Quat
89
79
# (::Type{Q})(q::Quat) where Q <: QuatRotation = Q(q.w, q.x, q.y, q.z, false)
@@ -233,21 +223,13 @@ Rotations.params(p) == @SVector [1.0, 2.0, 3.0] # true
233
223
@inline params (q:: QuatRotation ) = SVector {4} (real (q. q), imag_part (q. q)... )
234
224
235
225
# ~~~~~~~~~~~~~~~ Initializers ~~~~~~~~~~~~~~~ #
236
- @inline Base. one (:: Type{Q} ) where Q <: QuatRotation = Q (1.0 , 0.0 , 0.0 , 0.0 )
226
+ @inline Base. one (:: Type{Q} ) where Q <: QuatRotation = Q (1.0 , 0.0 , 0.0 , 0.0 , false )
237
227
238
228
239
229
# ~~~~~~~~~~~~~~~ Math Operations ~~~~~~~~~~~~~~~ #
240
230
241
231
# Inverses
242
- Base. inv (q:: Q ) where Q <: QuatRotation = Q (conj (q. q))
243
-
244
- function _normalize (q:: Q ) where Q <: QuatRotation
245
- w = real (q. q)
246
- x, y, z = imag_part (q. q)
247
-
248
- n = norm (params (q))
249
- Q (w/ n, x/ n, y/ n, z/ n)
250
- end
232
+ Base. inv (q:: Q ) where Q <: QuatRotation = Q (conj (q. q), false )
251
233
252
234
# Identity
253
235
(:: Type{Q} )(I:: UniformScaling ) where Q <: QuatRotation = one (Q)
@@ -261,11 +243,11 @@ Create a `Quaternion` with zero scalar part (i.e. `q.q.s == 0`).
261
243
"""
262
244
function pure_quaternion (v:: AbstractVector )
263
245
check_length (v, 3 )
264
- Quaternion (zero (eltype (v)), v[1 ], v[2 ], v[3 ], false )
246
+ Quaternion (zero (eltype (v)), v[1 ], v[2 ], v[3 ])
265
247
end
266
248
267
249
@inline pure_quaternion (x:: Real , y:: Real , z:: Real ) =
268
- Quaternion (zero (x), x, y, z, false )
250
+ Quaternion (zero (x), x, y, z)
269
251
270
252
function expm (ϕ:: AbstractVector )
271
253
check_length (ϕ, 3 )
@@ -309,7 +291,7 @@ rmult(w) * SVector(q)
309
291
Sets the output mapping equal to the mapping of `w`
310
292
"""
311
293
function Base.:* (q1:: QuatRotation , q2:: QuatRotation )
312
- return QuatRotation (q1. q* q2. q)
294
+ return QuatRotation (q1. q * q2. q, false )
313
295
end
314
296
315
297
"""
0 commit comments