@@ -6,13 +6,15 @@ Compute the quaternion that rotates vector `u` so that it aligns with vector
66"""
77function rotation_between end
88
9- function rotation_between (u:: SVector {2} , v:: SVector {2} )
9+ function rotation_between (u:: StaticVector {2} , v:: StaticVector {2} )
1010 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." ))
1113 theta = Base. angle (c)
1214 return Angle2d (theta)
1315end
1416
15- function rotation_between (u:: SVector {3} , v:: SVector {3} )
17+ function rotation_between (u:: StaticVector {3} , v:: StaticVector {3} )
1618 # Robustified version of implementation from https://www.gamedev.net/topic/429507-finding-the-quaternion-betwee-two-vectors/#entry3856228
1719 normprod = sqrt (dot (u, u) * dot (v, v))
1820 T = typeof (normprod)
@@ -22,9 +24,11 @@ function rotation_between(u::SVector{3}, v::SVector{3})
2224 @inbounds return QuatRotation (w, v[1 ], v[2 ], v[3 ]) # relies on normalization in constructor
2325end
2426
25- function rotation_between (u:: SVector {N} , v:: SVector {N} ) where N
27+ function rotation_between (u:: StaticVector {N} , v:: StaticVector {N} ) where N
2628 e1 = normalize (u)
2729 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." ))
2832 c = dot (e1, normalize (v))
2933 s = sqrt (1 - c^ 2 )
3034 P = [e1 e2 svd ([e1 e2]' ; full= true ). Vt[StaticArrays. SUnitRange (3 ,N),:]' ]
0 commit comments