# Concept

Firstly, what is meant by saying capsule? Well, simply put, it is a cylinder that (instead of flat ends) has hemispherical ends. By cylinder I mean a circular one (not elliptical). Hemispheres have the same radius. It should also be mentioned that the given body is solid (not hollow).[attachment=24922:Capsule definition.png]
**Figure 1.** Capsule definition.

*H*is height of the cylinder part and

*R*is radius of the hemisphere caps. This is the coordinate system that has its origin in the center of the mass of the capsule and whose axes are the axes which we will be calculating moments of inertia for.

[attachment=24920:Capsule decomposition.png]
**Figure 2.** Capsule decomposition.

[attachment=24918:eq1.gif]

(**eq. 1)**

*V*represents the three dimensional region of integration and

*dm*is an infinitesimal amount of mass at some point in our capsule. The integrand is simply squared distance from the axis.

[attachment=24239:eq2.gif]

(**eq. 2)**

[attachment=24240:eq3.gif]

(**eq. 3)**

## Cylinder

Before we dive into integration here is the Cartesian coordiante system we will be using for cylinder:[attachment=24917:cylinder.png]
**Figure 3.** Cylinder and its position relative to coordinate system.

[attachment=24287:eq4.gif]

(**eq. 4)**

[attachment=24292:eq5.gif]

(**eq. 5)**

*Ixx*.

[attachment=24902:eq6.gif]

(**eq. 6)**

## Hemisphere caps

The following is how the hemisphere is defined relative to Cartesian coordinate system for the purpose of integration:[attachment=24923:hemishpere.png]
**Figure 4.** Hemisphere and its position relative to coordinate system.

[attachment=24854:eq7.gif]

(**eq. 7)**

[attachment=24855:eq8.gif]

(**eq. 8)**

*Ixx*:

[attachment=24856:eq9.gif]

(**eq. 9)**

[attachment=24914:hemisphere_CM.png]
**Figure 5.** Center of mass of a hemisphere.

*b*and use it in reverse Steiner's rule:

[attachment=24892:eq10.gif]

(**eq. 10)**

[attachment=24893:eq11.gif]

(**eq. 11)**

*Icm*is moment of inertia of an axis that goes through the center of mass and

*m*is hemisphere mass from eq. 8. Now it's finally possible to calculate

*Ixx*and

*Izz*for our hemisphere caps. We can now apply Steiner's rule to translate the axes from the center of mass of a hemisphere to the center of mass of the whole body (capsule):

[attachment=24901:eq12.gif]

(**eq. 12)**

## The tensor

[attachment=24897:eq13.gif]

(**eq. 13)**

*mhs*) is multiplied by two. This is, of course, because there are two hemispheres on both ends of the capsule. Also, note our previous assumption in which density is equal to one unit of measurement, which is why the mass is equal to volume. If needed

*mcy*and

*mhs*can simply be multiplied by some constant density and the results will be accurate. The given code is written in such way. The full tensor uses this values and is given by:

[attachment=24900:eq14.gif]

(**eq. 14)**

*mcy*and

*mhs*, by substituting those values equality can be easily shown. The parts that represent moments of inertia of a hemisphere are multiplied by two, because we have two of them.

# Code

The following code implementation is given in C-like language and is fairly optimized. [code] #define PI 3.141592654f #define PI_TIMES2 6.283185307f const float oneDiv3 = (float)(1.0 / 3.0); const float oneDiv8 = (float)(1.0 / 8.0); const float oneDiv12 = (float)(1.0 / 12.0); void ComputeRigidBodyProperties_Capsule(float capsuleHeight, float capsuleRadius, float density, float &mass, float3 ¢erOfMass, float3x3 &inertia) { float cM; // cylinder mass float hsM; // mass of hemispheres float rSq = capsuleRadius*capsuleRadius; cM = PI*capsuleHeight*rSq*density; hsM = PI_TIMES2*oneDiv3*rSq*capsuleRadius*density; // from cylinder inertia._22 = rSq*cM*0.5f; inertia._11 = inertia._33 = inertia._22*0.5f + cM*capsuleHeight*capsuleHeight*oneDiv12; // from hemispheres float temp0 = hsM*2.0f*rSq / 5.0f; inertia._22 += temp0 * 2.0f; float temp1 = capsuleHeight*0.5f; float temp2 = temp0 + hsM*(temp1*temp1 + 3.0f*oneDiv8*capsuleHeight*capsuleRadius); inertia._11 += temp2 * 2.0f; inertia._33 += temp2 * 2.0f; inertia._12 = inertia._13 = inertia._21 = inertia._23 = inertia._31 = inertia._32 = 0.0f; mass = cM + hsM * 2.0f; centerOfMass = {0.0f, 0.0f, 0.0f}; } [/code] It would seem that*centerOfMass*is useless, but I have left it here because it is important part of rigid body properties and often a requirement for physics engines.