I am assuming that b2GetBodyInertia calculates the rotational inertia (or moment of inertia) about the body's center of mass. Is this correct?
I created a thin rod using Box2D and calculated the rotational inertia - see code below.
set display mode 1280, 1024, 32, 1
maximize window
global worldID
worldID = b2CreateWorld(0,0,1)
b2SetScale 100,360/(2*3.1415),1,1
global bodyID
bodyID = b2CreateBody(worldID,b2BodyType_Dynamic(),screen width()/2,screen height()/2)
global shapeID
shapeID = b2CreatePolygonShapeAsBox(400,1,200,0,0)
global fixtureID
fixtureID = b2CreateFixture(bodyID,shapeID,0.1)
b2SetDebugDraw 1,0,0,0,0
do
cls rgb(255,255,255)
ink rgb(0,0,0),rgb(255,255,255)
print "Body Inertia: ",b2GetBodyInertia(bodyID)
b2DrawWorld worldID,1
b2StepWorld worldID,1.0/60.0
LOOP
b2DeleteFixture fixtureID
b2DeleteShape shapeID
b2DeleteBody bodyID
b2DeleteWorld worldID
end
The rotational inertia of a thin rod about its center of mass I should be I = ML^2/12, where M is the mass of the rod and L is the length of the rod. I know that this is for a linear mass distribution and I technically don't have one. However, this should be close.
1) Using this formula with kg and m, I get (1/12)*(40 kg)*(4m)^2 = 53 kgm^2.
2) Using this formula with kg and pixels, I get (1/12)*(40 kg)*(400 pixels)^2 = 533333 kgpixels^2.
3) Using b2GetBodyInertia, I get 650.
Since I used the b2SetScale command, I would expect methods 2) and 3) to agree. Unfortunately, they don't. What am I overlooking?