Hi,
I've posted this question to the pybullet sub forum by mistake and have now moved it here. Sorry about that.
I am trying to use btRigidBody::setMassProps() where the second parameter inertia is a btVector3. Now, I have the rigid body description from a NIF file with an inertia tensor matrix (given that it is from a NIF I suspect it is from Havok):
m11 = 1916.75
m12 = 0.0
m13 = 0.0
m14 = 0.0
m21 = 0.0
m22 = 46.2
m23 = 0.0
m24 = 0.0
m31 = 0.0
m32 = 0.0
m33 = 1915.6
m34 = 0.0
How do I convert this matrix to a vector so that Bullet can use it?
Many thanks in advance
inertia vector from inertia tensor matrix

 Posts: 3
 Joined: Mon Jan 18, 2021 1:08 pm
Re: inertia vector from inertia tensor matrix
As you can see, the matrix is diagonal (which is good in local body coords). The most foolproof method would be to just create new vector like:
Code: Select all
btVector3 your_new_vector(matrix.m11, matrix.m22, matrix.m33)
Re: inertia vector from inertia tensor matrix
Hi,
Thanks for your response. However I would like to understand a little bit more about this  what does this vector represent? Is it the axis of rotation for this rigid body?
Also, I can't be certain that all the NIF models will have similar inertia tensor matrices (i.e. nonzero values only in the diagonal). In such cases how would I derive the inertia vector?
Thanks for your response. However I would like to understand a little bit more about this  what does this vector represent? Is it the axis of rotation for this rigid body?
Also, I can't be certain that all the NIF models will have similar inertia tensor matrices (i.e. nonzero values only in the diagonal). In such cases how would I derive the inertia vector?

 Posts: 3
 Joined: Mon Jan 18, 2021 1:08 pm
Re: inertia vector from inertia tensor matrix
Matrix of inertia represents how much torque is needed to make body get certain angular acceleration. In coordinates, which origin start in a center of mass the matrix is diagonal, meaning that providing torque at the origin in X axis ur will not make a body start spinning around Y or Z axes. If you provide those torques, however, not around center of mass, then this is not true anymore. This is why many physics engines compute rotations in body coordinates  it makes calculations much more simple.
If you are not getting diagonalized matrices, you need to diagonalize them.
https://yutsumura.com/howtodiagonaliz ... planation/
btMatrix3x3 has a diagonalize() function, which uses Jacobi method, according to manual, although i did not use it mysel
If you are not getting diagonalized matrices, you need to diagonalize them.
https://yutsumura.com/howtodiagonaliz ... planation/
btMatrix3x3 has a diagonalize() function, which uses Jacobi method, according to manual, although i did not use it mysel
 drleviathan
 Posts: 698
 Joined: Tue Sep 30, 2014 6:03 pm
 Location: San Francisco
Re: inertia vector from inertia tensor matrix
To clarify some points in the hope of being useful:
The "inertia tensor" of an object is the analogous to "mass", but for rotational motion. In linear dynamics you are probably familiar with the formula:
force = mass * acceleration
In its full 3D glory that is a vector equation: force and acceleration have three components while mass is a scalar. There is a similar equation for rotational dynamics:
torque = inertia_tensor * angular_acceleration
Again, that is a vector equation: torque and angular_acceleration have three components, however this time the "mass" term is a 3x3 matrix! (1)
The coefficients inside the 3x3 matrix depend on the reference frame. For a tumbling rigid body simulated in a static worldframe the coefficients will "tumble" over time, however in the body's localframe with origin at its center of mass, the coefficients of the inertia tensor are invariant (do no change). Within the infinite possibilities of centered localframes there are some rotations in which the inertia tensor is diagonal. These values along the diagonal are known as its "eigen values". For some symmetric objects (sphere, cube) the inertia tensor is always diagonal (the choice of localframe rotation does not matter) whereas most asymmetrical objects have diagonal inertia tensors at only a few choice rotations.
The Bullet API requires you to specify the three diagonal eigen values of the inertia tensor. In other words: it assumes you've specified the body geometry in the localframe such that its inertia tensor is diagonal. It later uses those invariant values to compute the "worldframe inverse inertia tensor" (whose coefficients "tumble" as the object rotates) as necessary when running the simulation.
The good news: for games it is usually not necessary to get the inertia tensor exactly right. As long as it is close enough: players will not be able to tell the difference between an accurate inertia tensor and the inertia tensor of its bounding box. Do it this way because it is easy.
However, if you are using Bullet to perform "accurate" rigid body dynamics for simulation purposes then it might be important to get it just right.
(1) Why does the rotation equation need a 3x3 matrix? Fundamentally: the linear mass is scalar because translations commute (the end result does not change depending on how operations are ordered) however rotations do NOT commute, hence the math must track how the components of torque "mix" into the various components of angular acceleration.
The "inertia tensor" of an object is the analogous to "mass", but for rotational motion. In linear dynamics you are probably familiar with the formula:
force = mass * acceleration
In its full 3D glory that is a vector equation: force and acceleration have three components while mass is a scalar. There is a similar equation for rotational dynamics:
torque = inertia_tensor * angular_acceleration
Again, that is a vector equation: torque and angular_acceleration have three components, however this time the "mass" term is a 3x3 matrix! (1)
The coefficients inside the 3x3 matrix depend on the reference frame. For a tumbling rigid body simulated in a static worldframe the coefficients will "tumble" over time, however in the body's localframe with origin at its center of mass, the coefficients of the inertia tensor are invariant (do no change). Within the infinite possibilities of centered localframes there are some rotations in which the inertia tensor is diagonal. These values along the diagonal are known as its "eigen values". For some symmetric objects (sphere, cube) the inertia tensor is always diagonal (the choice of localframe rotation does not matter) whereas most asymmetrical objects have diagonal inertia tensors at only a few choice rotations.
The Bullet API requires you to specify the three diagonal eigen values of the inertia tensor. In other words: it assumes you've specified the body geometry in the localframe such that its inertia tensor is diagonal. It later uses those invariant values to compute the "worldframe inverse inertia tensor" (whose coefficients "tumble" as the object rotates) as necessary when running the simulation.
The good news: for games it is usually not necessary to get the inertia tensor exactly right. As long as it is close enough: players will not be able to tell the difference between an accurate inertia tensor and the inertia tensor of its bounding box. Do it this way because it is easy.
However, if you are using Bullet to perform "accurate" rigid body dynamics for simulation purposes then it might be important to get it just right.
(1) Why does the rotation equation need a 3x3 matrix? Fundamentally: the linear mass is scalar because translations commute (the end result does not change depending on how operations are ordered) however rotations do NOT commute, hence the math must track how the components of torque "mix" into the various components of angular acceleration.
Re: inertia vector from inertia tensor matrix
Thank you both. I can't say I fully understand it all, but I will go study it and will also try it out.