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

Dual Quaternions for Rigid Body Transforms #487

Open
miakramer opened this issue Nov 26, 2018 · 12 comments
Open

Dual Quaternions for Rigid Body Transforms #487

miakramer opened this issue Nov 26, 2018 · 12 comments
Labels
enhancement good first issue Good first issue for newcomers. P-low Low priority

Comments

@miakramer
Copy link

Dual quaternions can represent all of rigid body transformations (translation + rotation), with some advantages over matrixes:

  • Better numerical stability
  • Smaller memory footprint (8 values, two algebraic constraints)
  • Small processing speed improvement (one paper I found said ~10% over matrices)

They also keep the simplicity of combining transformations is just multiplication.

A downside is that they only work for 3 dimensions (if I understand correctly), but given a large portion of users likely will be using only 3D geometry (for graphics, etc), it might be worth it. Also, there is already support for non-dual quaternions, so there is some interest.

Many of you probably already know this, just thought I'd document the case for them as I understand it.

If people are interested in this, I'll create a fork and add the feature? This is my first time contributing to an open-source project on github, so I may need a little guidance... Or, if someone else is interested in writing it that would work as well.

@sebcrozet sebcrozet added enhancement good first issue Good first issue for newcomers. P-low Low priority labels Nov 26, 2018
@sebcrozet
Copy link
Member

Hi! Adding dual quaternions would be a very interesting addition to nalgebra! As far as I know, nobody is working on this right now so your contribution is welcome! I'd be curious to see how dual quaternions compare to the existing Isometry3 structure which are representations of rigid-body transformations with 7 values and one algebraic constraint (one unit quaternion and one 3D vector).

If you need guidance, I suggest you open a pull-request even if you have not yet finished, and request for reviews when you need them. You should also see how quaternions are currently implemented. In particular, following the same file structure you should add:

  • geometry/dual_quaternions.rs containing the definition of the dual quaternion struct and operations which are not constructors nor operator overloading.
  • geometry/dual_quaternions_ops.rs containing operator overloading.
  • geometry/dual_quaternion_construction.rs containing static functions for constructing the dual quaternions.

Of course don't hesitate to ask questions on github, or on the nalgebra discord chanel!

@arturoc
Copy link
Contributor

arturoc commented Nov 26, 2018

dual quaternions are also really useful to avoid some artifacts while doing mesh skinning compared to using matrices

@miakramer
Copy link
Author

Should I work on the master branch or create a new feature branch?
I'm also curious to see how they compare. I know they're used a lot in IK and robotics due to the numerical stability. Maybe after writing them I'll do some benchmarks for speed and stability (since using Isometry3 has the numerical stability in angle from the quaternion already).

@sebcrozet
Copy link
Member

Should I work on the master branch or create a new feature branch?

Master is okay, we don't have specific rules for the source branch of pull-requests.

Maybe after writing them I'll do some benchmarks for speed and stability (since using Isometry3 has the numerical stability in angle from the quaternion already).

That would be great!

@Nivek92
Copy link

Nivek92 commented Sep 19, 2020

I would love to see this revived. I believe DualQuaternions would make a great addition to nalgebra as they find more and more use in different engineering categories (robotics, aerospace, etc.) and game development.

Are there people interested in working on this together?

@miakramer
Copy link
Author

I'm sorry I didn't get to the fork, finals came up right after this and it slipped my mind. I don't think I could head it but I would definitely be interested in contributing. It'd be very interesting to try out for games, and I bet CPUs with wide SIMD registers may be able to compute with them very efficiently.

On another note, for rotations I wonder if wedge products are a better fit than quaternions? They generalize to higher dimensions while iirc quaternions only represent rotations in three and four dimensions, and they're similar in practice

@chinedufn
Copy link
Contributor

chinedufn commented Dec 16, 2020

I'd be curious to see how dual quaternions compare to the existing Isometry3 structure

The main advantage of DQs is that they are excellent for linear blending / interpolation. In practice this means that they are excellent for vertex skinning.

If you interpolate two DQs you will get the shorted path rotation between them.

vs. you can't just blend two Isometry3 and get a shorted path rotation between them.


I was in the middle of writing a DQ multiply function in a project and thought... How come nalgebra doesn't have this.

Just found this issue - glad to see that there's interest.

Here's how I see the path forwards:

  1. PR a DualQuaternion struct that contains the 8 floats (perhaps stored as two quaternions). Release this. Now anyone that is writing their own DQ math is at least working against the same type.

  2. Over time people can contribute different functions such as multiplication ... linear blend ... etc

  3. As these functions get contributed we can replace out own math in our own projects with the math in nalgebra.

Basically I think that this will be more likely to progress as a lot of small additions instead of one big PR adding full DQ support.


I'll PR step number one and if it lands I'd be happy to follow up with PRs contributing misc DQ code I have stored in misc places.

@sebcrozet
Copy link
Member

Here's how I see the path forwards:

1. PR a `DualQuaternion` struct that contains the 8 floats (perhaps stored as two quaternions). Release this. Now anyone that is writing their own DQ math is at least working against the same type.

2. Over time people can contribute different functions such as multiplication ... linear blend ... etc

3. As these functions get contributed we can replace out own math in our own projects with the math in `nalgebra`.

@chinedufn Sounds like a reasonable way forward, yes.

chinedufn added a commit to chinedufn/nalgebra that referenced this issue Dec 16, 2020
This commit introduces the `DualQuaternion` type, in line with the plan
laid out in [dimforge#487].

[dimforge#487]: dimforge#487
chinedufn added a commit to chinedufn/nalgebra that referenced this issue Dec 16, 2020
This commit introduces the `DualQuaternion` type, in line with the plan
laid out in [dimforge#487].

[dimforge#487]: dimforge#487
chinedufn added a commit to chinedufn/nalgebra that referenced this issue Dec 16, 2020
This commit introduces the `DualQuaternion` type, in line with the plan
laid out in [dimforge#487].

[dimforge#487]: dimforge#487
@miakramer
Copy link
Author

I know I was the one to make this issue originally, but I've been learning about geometric algebra for my research and I think it's a far better domain than the hypercomplex numbers. They're largely equivalent in two and three dimensions (see this excellent blog post: https://marctenbosch.com/quaternions/), and they generalize efficiently to higher dimensions (rotations in $n$ dimensions require $n(n-1)/2 + 1$ floats, rather than the $n^2$ of a rotation matrix, plus the same benefits that quaternions have in terms of numerical stability). I'm not trying to discourage the use of dual quaternions, because they still seem very cool and useful, just suggesting that folks may be interested in the geometric algebra approach in addition. You can add homogeneous coordinates to get back all of E(n). Geometric algebra also extends well to non-Euclidean manifolds (see Grassman.jl).

chinedufn added a commit to chinedufn/nalgebra that referenced this issue Dec 18, 2020
This commit introduces the `DualQuaternion` type, in line with the plan
laid out in [dimforge#487].

[dimforge#487]: dimforge#487
@chinedufn
Copy link
Contributor

I think that this can be closed

@tpdickso
Copy link
Collaborator

#824 should add the majority of missing functionality; but let me know if there's something that I missed, because I'd be glad to help complete it.

@ChristopherRabotin
Copy link
Contributor

Hi there,
I am the maintainer of the hyperdual crate that defines multi-dimensional dual numbers used for automatic differentiation. I'd be happy to help out on this feature as well.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Good first issue for newcomers. P-low Low priority
Projects
None yet
Development

No branches or pull requests

7 participants