We now have two types for 2D rotations:
RotMatrix{2} stores four real values as a matrix
Angle2d stores one real value as a rotation angle
However, a 2D rotation can be parametrized with two real values $(c,s)$ like
$$
R = \begin{pmatrix}c & -s \\ s & c\end{pmatrix}.
$$
This rotation is the same as a rotation by a complex number $c+is$, and can be implemented like this:
struct ComplexRotation{T} <: Rotation{2,T}
c::Complex{T}
end
This is sometimes useful when we need to generate a rotation from 2D vectors.
See rotation_between for example.
|
function rotation_between(u::StaticVector{2}, v::StaticVector{2}) |
|
c = complex(v[1], v[2]) / complex(u[1], u[2]) |
|
iszero(c) && throw(ArgumentError("Input vectors must be nonzero and finite.")) |
|
isfinite(c) || throw(ArgumentError("Input vectors must be nonzero and finite.")) |
|
theta = Base.angle(c) |
|
return Angle2d(theta) |
|
end |
We now have two types for 2D rotations:
RotMatrix{2}stores four real values as a matrixAngle2dstores one real value as a rotation angleHowever, a 2D rotation can be parametrized with two real values$(c,s)$ like
This rotation is the same as a rotation by a complex number$c+is$ , and can be implemented like this:
This is sometimes useful when we need to generate a rotation from 2D vectors.
See
rotation_betweenfor example.Rotations.jl/src/rotation_between.jl
Lines 9 to 15 in f00b07d