# 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).*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.

(**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.

(**eq. 2)**

(**eq. 3)**

## Cylinder

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

(**eq. 4)**

(**eq. 5)**

*Ixx*.

(**eq. 6)**

## Hemisphere caps

The following is how the hemisphere is defined relative to Cartesian coordinate system for the purpose of integration:
**Figure 4.** Hemisphere and its position relative to coordinate system.

(**eq. 7)**

(**eq. 8)**

*Ixx*:

(**eq. 9)**

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

(**eq. 10)**

(**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):

(**eq. 12)**

## The tensor

(**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:

(**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.```
#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};
}
```

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.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account## Sign in

Already have an account? Sign in here.

Sign In Now