Jump to content
  • Advertisement
Sign in to follow this  
Komal Shashank

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
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 this post

Link to post
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 this post

Link to post
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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!