# Calculating the moment of inertia of a 2D capsule

This topic is 527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello... I am trying to calculate the moment of inertia around the center of mass of a 2D capsule which I divided into a rectangle and two semicircles. C is the center of mass and the axis of rotation passes through this point.

I know that the moment of inertia for a semicircle around an axis perpendicular to its plane passing through the center of its full circle is 1/2 MR² where M is the mass of the semicircle and R is the radius (correct me if I am wrong). Here, for the two semicircles, it is points A and B. For a rectangle, the moment of inertia passing through its centroid is 1/12 M(L² + W²) where M is mass of the rectangle and L and W are its dimensions. Here, the centroid is the same as center of mass C.

According to the Parallel Axis Theorem, the moment of inertia around an axis parallel to the existing axis is the existing moment of inertia added to the mass multiplied with the squared perpendicular distance between the two axes. Here, for the semicircles, around C it would be 1/2 MR² + M(AC² or BC²).

The total moment of inertia for the capsule would be the sum of its constituent moments of inertia, so it would be Rectangle's + 2 * (Semicircle's). Based on this, this is what I did, but I don't think I got it right because my capsule is jittering all over the place and not rotating as intended.

float momentOfInertiaOfRectangle = (massOfRectangle / 12.0f) * ((extentLength * extentLength) + (extentWidth * extentWidth));
float momentOfInertiaOfSemiCircle = massOfSemicircle * ((0.5f * m_CapsuleRadius * m_CapsuleRadius) + (extentLength * extentLength * 0.25f));
float totalMomentOfInertia = momentOfInertiaOfRectangle + (momentOfInertiaOfSemiCircle * 2.0f);

Please tell me if I did anything wrong and clarify this for me. Thank you.

##### Share on other sites

One problem is that momentOfInertiaOfSemiCircle is the moment of inertia of the (full) circle.

When I get home I'll try to derive you step-by-step.

Edited by Irlan Robson

##### Share on other sites

Here is the step-by-step calculation of the capsule inertia. I have the code in 3D so I downscaled it to 2D for your convenience. Of course you can simplify it but the decoupled approach is nice for clarification. You can also look use this image as a reference (originally from Dirk's paper).

	float32 r = m_radius;
float32 r2 = r * r;

float32 w = 2.0f * r;
float32 w2 = w * w;

float32 h = b3Length(B - A);
float32 h2 = h * h;

// Rectangle inertia about the capsule center of mass
b3MassData Ic_Rectangle;
{
// Rectangle mass
float32 area = w * h;
float32 mass = density * area;

// Rectangle inertia about the center of mass (same as capsule center of mass)
Ic_Rectangle.center = 0.5f * (A + B);
Ic_Rectangle.mass = mass;
Ic_Rectangle.I = mass * (w2 + h2) / 12.0f;
}

// Semicircle inertia about the capsule center of mass
b3MassData Ic_Semicircle;
{
// Circle area and mass
float32 circleArea = B3_PI * r2;
float32 circleMass = density * circleArea;
float32 circleI = circleMass * 0.5f * r2;

// Semicircle area and mass
float32 area = 0.5f * circleArea;
float32 mass = 0.5f * circleMass;

// Semicircle inertia about the base
float32 Io = 0.5f * circleI;

// Paralell axis theorem
// I = Ic + m * d^2
// Ic = I - m * d^2

// Semicircle center of mass distance to the base
float32 d1 = (3.0f / 8.0f) * r;

// Semicircle inertia about its center of mass
float32 Ic = Io - (mass * d1 * d1);

// Semicircle center of mass distance to the capsule center of mass
float32 d2 = d1 + 0.5f * h;

// Semicircle inertia about the capsule center of mass
float32 I = Ic + (mass * d2 * d2);

Ic_Semicircle.center.Set(0.0f, d2);
Ic_Semicircle.mass = mass;
Ic_Semicircle.I = I;
}

// Capsule inertia about the capsule center of mass taking two semicircles into account
b3MassData Ic_Capsule;
Ic_Capsule.center = Ic_Rectangle.center;
Ic_Capsule.mass = Ic_Rectangle.mass + 2.0f * Ic_Semicircle.mass;
Ic_Capsule.I = Ic_Rectangle.I + 2.0f * Ic_Semicircle.I;



##### Share on other sites

That's awesome! Thank you so much, Irlan Robson!  :D Now it makes so much sense. I'm going to try and implement this and update this post when it works. Thank you very much!

@Dirk Gregorius: I think I've seen your paper before but I guess I had trouble flattening it to 2D. Thank you, guys.  :)

##### Share on other sites

It is not a paper! These are my personal sketches when I derived this for myself. That is why it is a bit short. Still glad it helped :)

##### Share on other sites

Oh, I thought it was part of a much larger research paper or something. Helped me nonetheless. By the way... Update: I got it working. It behaves as intended now. I finally understood what was wrong. I thought the parallel axis theorem worked with any two parallel axes. One of them has to be through center of mass, got it.  :D

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631765
• Total Posts
3002213
×