@@ -6,13 +6,15 @@ Compute the quaternion that rotates vector `u` so that it aligns with vector
6
6
"""
7
7
function rotation_between end
8
8
9
- function rotation_between (u:: SVector {2} , v:: SVector {2} )
9
+ function rotation_between (u:: StaticVector {2} , v:: StaticVector {2} )
10
10
c = complex (v[1 ], v[2 ]) / complex (u[1 ], u[2 ])
11
+ iszero (c) && throw (ArgumentError (" Input vectors must be nonzero and finite." ))
12
+ isfinite (c) || throw (ArgumentError (" Input vectors must be nonzero and finite." ))
11
13
theta = Base. angle (c)
12
14
return Angle2d (theta)
13
15
end
14
16
15
- function rotation_between (u:: SVector {3} , v:: SVector {3} )
17
+ function rotation_between (u:: StaticVector {3} , v:: StaticVector {3} )
16
18
# Robustified version of implementation from https://www.gamedev.net/topic/429507-finding-the-quaternion-betwee-two-vectors/#entry3856228
17
19
normprod = sqrt (dot (u, u) * dot (v, v))
18
20
T = typeof (normprod)
@@ -22,9 +24,11 @@ function rotation_between(u::SVector{3}, v::SVector{3})
22
24
@inbounds return QuatRotation (w, v[1 ], v[2 ], v[3 ]) # relies on normalization in constructor
23
25
end
24
26
25
- function rotation_between (u:: SVector {N} , v:: SVector {N} ) where N
27
+ function rotation_between (u:: StaticVector {N} , v:: StaticVector {N} ) where N
26
28
e1 = normalize (u)
27
29
e2 = normalize (v - e1 * dot (e1, v))
30
+ any (isnan, e1) && throw (ArgumentError (" Input vectors must be nonzero and finite." ))
31
+ any (isnan, e2) && throw (ArgumentError (" Input vectors must be nonzero and finite." ))
28
32
c = dot (e1, normalize (v))
29
33
s = sqrt (1 - c^ 2 )
30
34
P = [e1 e2 svd ([e1 e2]' ; full= true ). Vt[StaticArrays. SUnitRange (3 ,N),:]' ]
0 commit comments