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

Mul<Bivec3> implementation for Mat3 #30

Open
Emiluren opened this issue Feb 10, 2020 · 9 comments
Open

Mul<Bivec3> implementation for Mat3 #30

Emiluren opened this issue Feb 10, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@Emiluren
Copy link

Emiluren commented Feb 10, 2020

I am currently writing a physics engine (just to learn) and I happened to find ultraviolet while looking for a linear algebra library. I had never heard of geometric algebra before so learning about bivectors and rotors was interesting.

I managed to figure out that torque should probably be represented by a bivector but I ran into a problem when I was going to calculate the angular acceleration. I am assuming that the inverse of the inertia tensor can still be represented by a 3x3 matrix but I noticed that there is no implementation of Mul<Bivec3> for Mat3. Should there be one or am I going about this in the wrong way?

I am also considering using a Bivec3 (which I noticed has an implementation of Mul<Bivec3>) for the inertia tensor but I guess this would only let me have the equivalent of a diagonal matrix.

@fu5ha
Copy link
Owner

fu5ha commented May 7, 2020

Hmm... Mul<Bivec3> for Mat3 does sound reasonable. Should probably just be the same as for a Vec3.

@fu5ha fu5ha added the enhancement New feature or request label May 7, 2020
@chakravala
Copy link

chakravala commented Sep 1, 2020

Not a user of this language repo, but mathematically speaking, there are two possibilities for interpreting a matrix times a bivector. In one interpretation, you convert the bivector to a vector and do a standard multiply. In the other intepretation, you would think of the matrix as a dyadic tensor (column vectors nested inside a vector), and then use the Grassmann interior product as a tensor contraction.

Maybe there is another way you can think of it also.

@mewertd2
Copy link

mewertd2 commented Sep 2, 2020

If you diagonalize your inertia tensor you don't need a matrix multiply. Haven't thought through what you do with that diagonalized tensor though.

The start of this paper has some info: https://marctenbosch.com/ndphysics/NDrigidbody.pdf
Seems they are taking the dual of the angular velocity bivector to get a vector. Then just use a regular matrix/vector multiply with the inertia tensor and convert back to bivector after.

@fu5ha
Copy link
Owner

fu5ha commented Sep 2, 2020

@Emiluren just for reference, I posted this issue in a geometric algebra related discord recently as I'm a bit out of my depth (I know next to nothing about physics simulation) and these nice people decided to weigh in... if you read that paper and figure out what it is that you need ultraviolet to do, I'm happy to implement it (or you could yourself if you wish!)

@mewertd2
Copy link

mewertd2 commented Sep 2, 2020

@chakravala and I both pretty much suggested converting from/to bivector to/from vector and doing a matrix multiply with the inertia tensor as the simplest solution. For that I think @termhn you just need a dual method to convert from a vector to and from the bivector isomorphic to it. I didn't see this method here, but I didn't do long search.

dual may not be your preferred name. Conceptually it gives you a scaled blade orthogonal to your input blade.

@eric-wieser
Copy link

I don't think you want to take the dual and transform that, that results in the wrong transformation - you'll end up with a transformed bivector not matching the bivector formed from wedging two transformed vectors.

Instead, you should take an outermorphism of the matrix, which in 3d is a matrix with (some permutation of) columns c2 ^ c3, c3^c1, c1^c2 .

@hugohadfield
Copy link

hugohadfield commented Sep 2, 2020

I'm with @mewertd2 here, diagonalising the inertia tensor is definitely the way to go, then you are basically just applying a scaling to the components of the bivector.
I find a useful way to think about the inertia tensor is as a linear function on the angular velocity that maps it to the angular momentum, the inverse inertia tensor is just the inverse of that function. These functions can be instantiated as matrices and (for 3d vectorspace GA) will come out looking exactly the same as the equivalent standard inertia tensor matrices but with some sign flips and the rows/columns might be in a different order.

If you are after an easy way of calculating the inertia tensor and inverse and applying it to a bivector (and you are using an axis aligned body frame) then take these formulae: https://slides.com/hugohadfield/game2020#/54 and ignore all the t^i and t_i bits.
Edit: oh woops saw that is the wrong link, you actually want:
[
\Omega_b = M(\dot{B_b}) = m\sum_{i=1}^{i=3}\gamma_i(\dot{B_b}\cdot l^i)l_i
]
and
[
M^{-1}(\Omega_b) = \dot{B_b} = \frac{1}{m}\sum_{i=1}^{i=3}\frac{1}{\gamma_i}(\Omega_b\cdot l^i)l_i
]

@Emiluren
Copy link
Author

Emiluren commented Sep 2, 2020

Thank you all for the suggestions! As soon as I have time I'm going to have to see if I can write some code based on this.

@T0mstone
Copy link

T0mstone commented Mar 5, 2024

Hmm... Mul<Bivec3> for Mat3 does sound reasonable. Should probably just be the same as for a Vec3.

No, it probably shouldn't. The natural thing to do here is the outermorphism, i.e. A(u ʌ v) = (Au) ʌ (Av).

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

No branches or pull requests

7 participants