Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Inertia tensor in Matrix Form from InertiaTensor and InertiaTensorRotation

Discussion in 'Physics' started by Maeslezo, Jul 28, 2020.

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    191
    Hello,

    Inertia tensor is normally defined as a 3x3 Matrix
    upload_2020-7-28_14-2-20.png
    Unity and Physx give something equivalent, an IntertiaTensor, and an InertiaTensorRotation. I think they do it like this because it is cheaper (3+4 = 7 values) against (3x3=9 values).

    My question is, having an InertiaTensor and an InertiaTensorRotation, how can I calculate the 3x3 Inertia Tensor?

    I reckon this should be quite straightforward but I can't get the maths right

    I am tempted to do:
    Code (CSharp):
    1. var intertiaMatrix = Matrix4x4.TRS(Vector3.One, inertiaTensorRotation, inertiaTensor)
    Because TRS transforms the quaternion in a canonical form and it is scaled by the inertia tensor

    Thank you
     
    Last edited: Jul 28, 2020
  2. myelin_price

    myelin_price

    Joined:
    Oct 24, 2019
    Posts:
    1
    Did you ever figure this out? I'm new to Unity and have a similar requirement.
     
  3. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    191
    No, not really. But this is something I would like to study as soon as I can
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,978
    I also tried to get more information on the inertia tensor rotation, but even the PhysX devs seem reluctant to talk about this.

    I've been able to convert an inertia tensor matrix to the equivalent inertia tensor vector and inertia tensor rotation by translating the PhysX code, but haven't found the formula that does the opposite.
     
  5. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    191
    Yes actually it is a very opaque topic from the PhysX's side

    I could understand that PhysX decided to go to two structures (vector and quaternion) instead of a 3x3 matrix in order to save a little of memory, although this change could increase the number of calculations and operations.

    Anyway, I thought the maths from vector + quaternion to 3x3 should be straightforward, but when I did it manually, the results where different, so I think I am missing something here.
     
    Last edited: Dec 16, 2020
  6. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,978
    It's more than that. Actually it seems part of a heavily simplified rigidbody dynamics model.

    In reality (and realistic rb dynamics models) a rotating object has angular momentum. The angular velocity results of dividing the angular momentum by the inertia [matrix]. Therefore, modifying the inertia actually changes the angular velocity.

    But in PhysX's simplified model this doesn't happen. Instead of integrating angular momentum, they integrate angular velocity. So when a torque is applied, the resulting change in the angular velocity is calculated by dividing the torque by the inertia. Further changes in the inertia don't modify the angular velocity. Only when a new torque is applied the angular velocity changes based on the current inertia value. Therefore, freely rotating objects (no forces/torques applied) exhibit different behaviors in PhysX compared with the real world (and with realistic models).

    While working in Project 424 we found severe differences when applying torques in PhysX using a non-identity inertia tensor rotation, compared with the same exact situation in an high-end dynamics simulation model. We haven't investigated further yet, but the preliminary results point that the combination of inertia tensor vector/rotation provide very different effects than the expected from the original inertia matrix.
     
  7. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    286
    I suspect the values of the Vector3 are the principal moments of inertia and the quaternion describing the differential rotation between the local coordinate system and the axes of the principal moments of inertia. There I would also guess that creating the rotation matrix with Matrix4x4.TRS is the right way to go.

    Did you dig deeper into this @Edy? I'm not well practised in doing matrix transforms, but you should do something like T.inverse * X * T (or the other way round?). It's also not clear to me in which coordinate system the matrix you suggested in your initial post lives.

    As for the differences between PhysX and more sophisticated models: I assume from a small test a while ago that Euler's equations are not respected. https://en.wikipedia.org/wiki/Euler's_equations_(rigid_body_dynamics) meaning that the behaviour in the following video will not show in PhysX.

    (skip to 0:20)
     
  8. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    191
    That where I started to think about this.
    Simulating the bicycle equilibrium, I got very different outputs. Simulating in Matlab with a 3x3 Inertia Matrix, I got the bicycle stabilized, but I couldn't reproduce that behavior with the vector/quaternion model in Unity

    So the classic example about a figure skater increasing his angular velocity decreasing his moment of inertia is not possible in Physx, isn't? Very important point, I didn't know that
     
  9. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,978
    Exactly, that doesn't work. Modifying the inertia alone doesn't cause any effect in the rigidbody.

    Maybe, just maybe, that example could be simulated explicitly by computing the angular momentum, modifying the inertia, then compute and apply a new angular speed out of the angular momentum and the new inertia.
     
  10. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,978
    We already thought about that, but no, the results were different. We don't know how to reconstruct the original inertia matrix out of the vector + rotation.

    The gyroscopic effect is a different thing, but no, it's not simulated in PhysX either.
     
unityunity