# What's wrong with my math?(calculating 2D moment of inertia)

## Recommended Posts

I'm working on a physics program and I'm having trouble with calculating moment of inertias. I have a function which takes a concave polygon, divides the polygon into triangles, and uses the parallel axis theorem to calculate the moment of inertia from the triangle moment of inertias.

I've derived and found this equation and checked it on the internet,the moment of inertia of a rectangle is

M*(a^2 + b^2)/12, where M is mass, and a and b are side lengths.

and I just looked up the equation for a triangle,

(base^3*height - base^2*height*a + base*height*a^2 + base*height^3)/36, where a is the distance along the base where the triangle peak is.

I have a test case with a polygon that weighs 6kg(or any unit really) and consists of the points (0,0), (2,0), (2,2), (0,2), a plain square. If I calculate the moment for this polygon with the rectangle equation I get, 6*(4+4)/12=4, but my function gives me 3.55555. After some frustration I decided to calculate the moment the way my function is supposed to.

Moment of inertia for one triangle about it's center = 8/36
Squared distance of each triangle center from square center = 4/9
Mass of each triangle = 3/2
Square moment of inertia = 4*(8/36 + 3/2*4/9) = .35555555

So it would appear that my function works, so my math must be wrong, but I think I either need to sleep or get somebody else to point out my problem.