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

πŸ”„ Implement Rotors #240

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

πŸ”„ Implement Rotors #240

wants to merge 12 commits into from

Conversation

tomrijnbeek
Copy link
Member

@tomrijnbeek tomrijnbeek commented Oct 16, 2021

✨ What's this?

Implements 2D and 3D rotors.

πŸ”— Relationships

Bivectors were recently added in #235. This PR builds on those.

Closes #229

πŸ” Why do we want this?

Rotors are a great way to represent rotations. While their math ends up being the same as quaternions, they are built on a more intuitive bases, making it easier to reason about the math and underlying components.

πŸ— How is it done?

This PR builds on the bivectors implemented before. It really comes down to implementing mathematical formulas and making the public interface intuitive. The non-obvious public members are all documented.

The implementation was largely done through TDD to ensure that the rotors have the correct behaviour. The actual implementation came together through working out the maths and/or using cross-referencing with other implementations.

πŸ’₯ Breaking changes

I decided to rename Magnitude on Bivector2 to Xy, which is consistent with the naming in Bivector3. This is because Magnitude is also often referred to as the absolute magnitude of a vector (and is used as such in the relevant classes). Note that no version with bivectors has been deployed to NuGet yet, so this would not be creating breaking changes for NuGet dependencies.

πŸ”¬ Why not another way?

Rotors form a specific subgroup within the geometric algebra. In particular, in 3D, rotors are considered the subgroup of the even multi-vectors. That is, they only contain 0- and 2-dimensional components. In general, the geometric product of two multi-vectors isn't necessarily a rotor. The more mathematical pure implementation would have us implementing either the entire group of versors (all combinations of products of multivectors), or implement lots of different types depending on which components may be present. This would have allowed us to implement the Rotate functions not as functions that work out all the math, but as the actual geometric product RvR*. The geometric product of a rotor with a vector does involve a trivector though (which cancels out nicely due to R and R* not being independent), so instead the terms are just expanded and done in-place.

πŸ¦‹ Side effects

There are still more features that could be added. Rotors could be transformed to their corresponding matrices and quaternions, rotors could be composed by multiplying them, and we can have more methods to construct rotors (e.g. from Euler angles) or decompose them (e.g. to Euler angles or axis-angle).

πŸ’‘ Review hints

Further reading to understand the subject matter:

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

Successfully merging this pull request may close these issues.

Implement rotors
1 participant