Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ComplexRotation <: Rotation{2} #270

Open
hyrodium opened this issue Sep 21, 2023 · 0 comments
Open

Add ComplexRotation <: Rotation{2} #270

hyrodium opened this issue Sep 21, 2023 · 0 comments

Comments

@hyrodium
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant