On the right side of the image there is a long box with inertia visulaized in red about any axis (forming an ellipsoid as expected).
On the left side, the same box is composed from 7 cubes, but the mass properties should be exactly the same.
I calculate inertia about an axis by iterating and summing up over all 7 bodies, code below.
On the very right of the image the numbers show that on principal axis the inarta values match for both,
but the visualization shows a more doughnut like inertia.
Question: Does the doughnutshape indicate a bug of mine?
Or is the ellipsoid shape just an approximization to keep inertia representable by few numbers?
I expect the latter, but if i'm wrong it might be the source of all my problems...
- Code: Select all
inline float NonuniformInertiaBodiesGetGlobalInertia (const sVec3 &axis, const sVec3 &com, Body **bodies, const int numBodies) // unproofed
{
float inertia = 0;
for (int i=0; i<numBodies; i++)
{
sVec3 bcom; BodyGetCenterOfMass (bodies[i], bcom);
float bmass, Ixx, Iyy, Izz;
BodyGetMassMatrix (bodies[i], bmass, Ixx, Iyy, Izz);
sVec3 d = bcom - com;
inertia += bmass * sVec3(d - axis * axis.Dot (d)).SqL(); // sql = squared length
sMat4 matrix; BodyGetMatrix (bodies[i], matrix);
sVec3 localAxis = matrix.Unrotate (axis);
localAxis[0] /= Ixx;
localAxis[1] /= Iyy;
localAxis[2] /= Izz;
inertia += 1.0f / localAxis.Length();
}
return inertia;
}