Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
β¨ 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
onBivector2
toXy
, which is consistent with the naming inBivector3
. This is becauseMagnitude
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 productRvR*
. The geometric product of a rotor with a vector does involve a trivector though (which cancels out nicely due toR
andR*
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: