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.