# Calculating density of an object

I'm using Box2D for physics in my game, and one of the things it needs to know when creating a shape for a physics body is the shape's density. I had no idea what value I should specify, so I went to the header file where it's defined, and it says:

The density, usually in kg/m^2.

I took that to mean that you could find the density for an object by dividing its weight by its size in metres squared. If I do that for a square crate, which I want to weigh 20 kilograms and have a width of 0.72 metres:

float32 weightInKg = 20;
float32 metresSquared = 0.72 * 0.72;
float32 density = weightInKg / metresSquared;


The density is 38.5802. Is this correct? It also results in a computed mass of 20, which is correct, as the Box2D documentation says the mass is in kg. I've got gravity set to zero if that matters, as the game is top-down.

If I do a similar calculation for the character, a human whose shape is a circle with a radius of 0.5 metres:

float32 weightInKg = 80;
float32 metresSquared = pi * (0.5 * 0.5);
float32 density = weightInKg / metresSquared;


The density is 101.859. Again, this doesn't seem correct. I've read that a density of 1.0 makes sense for a human in the context of Box2D, so if that were true, I'm just slightly over. I've also read that the average density of the human body is 985 kg/m3, but I'm not even sure if my density calculation is correct, so I'm not sure how that figure translates to kg/m2.

• I think less mass makes sense, seeing as I want the sizes to still be realistic. Is there some specific formula I should use for that, or just do something like float32 weightInKg = weight * 0.5? – Mitch May 3 '15 at 9:37