Inertia tensor

User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Inertia tensor

Post by frca »

Hi,
is it possible to somehow set my own inertia tensor for certain rigid body? I don't quite understand the meaning of calculateLocalInertia. The result is just a vector, not tensor. It seems impossible to set my user computed inertia tensor for a body. Am I missing something?
Thank you.

PS:
I am a newbie to the Bullet library and to this forum. I am interested in physics simulation, especially vehicle dynamics, as can be seen here. :wink:
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Inertia tensor

Post by Dirk Gregorius »

If the inertia tensor is defined w.r.t. the principal axes it is diagonal. Hence you can store it as 3D vector. IIRC Bullet doesn't compute the principal axes, but simply throws away the non-diagonal elements. This is not uncommon for physic engines. You can usually approximate the inertia tensor with a tight fitting box as suggested by Baraff long time ago in one of his papers.


HTH,
-Dirk
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Inertia tensor

Post by Erwin Coumans »

Dirk Gregorius wrote:[...] IIRC Bullet doesn't compute the principal axes, but simply throws away the non-diagonal elements.
-Dirk
Dirk, thanks for trying to help out, but your answer is not entirely correct.

Bullet defines the rigid body local coordinate frame to be equal to the center of mass and aligned with the principle axis of inertia. So for rigid bodies with basic shapes such as a btBoxShape, only the diagonal needs to be stored. Non-diagonal elements are zero and no values are 'thrown away'.
frca wrote: It seems impossible to set my user computed inertia tensor for a body. Am I missing something?
If the inertia tensor of your collision shape is not diagonal, you need to re-align the collisionshape using a btCompoundShape, and apply the inverse inertia transform to the child shape. btCompoundShape::calculatePrincipalAxisTransform computes the principle axis transform given a collection of child shapes, child transforms and their respective masses.

See attached BasicDemo, that shows how to use this calculatePrincipalAxisTransform to apply this inverse transform into a btCompoundShape, to realign the collision shape(s) so that the center of mass and principle axis of inertia is aligned with the local transform of the rigid body.
Thanks,
Erwin
You do not have the required permissions to view the files attached to this post.
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: Inertia tensor

Post by frca »

The problem that comes again and again to my mind is: What if I wanted to represent more complex rigid body's structure; let's say by a volumetric map where each voxel would represent for example actual density. I doubt that the structure of this complexity would be representable by a "diagonal" inertia tensor. Is there a way to do this in the bullet library? It shouldn't be problem to compute the inverted inertia tensor of this structure and the center of mass of the body out of it. But how to assign it to the body when the m_invInertiaLocal member is private?
Thanks
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Inertia tensor

Post by Dirk Gregorius »

You can always find the principal axes. Just accumulate the inertia of each individual voxel and then find the principal axes. An example can be found in btMatrix3x3::diagonolize(). And an explanation of the applied Newton rotation can be found here: http://www.melax.com/diag.html

For a general discussion look here:
http://en.wikipedia.org/wiki/Moment_of_inertia


Cheers,
-Dirk
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: Inertia tensor

Post by frca »

And the three diagonal elements of the resulting diagonal matrix -- m[0], m[4], m[8] -- are then used as the localInertia parameter (in that order) in btRigidBodyConstructionInfo constructor? I need to make sure that I got it right even if this question may be dumb :mrgreen:
Thanks