Get the height of a BoundingCapsule

I wondered if anyone can tell me how to compute the height of a BoundingCapsule.

I tried like this, but it is not getting the correct results (its not a cylinder after all:)):

capsule.getVolume()/FastMath.pow(FastMath.PI*capsule.getRadius(),2);


Sorry, found it out myself. Did it like this (maybe someone has an idea involving less computing?


float radius=capsule.getRadius();
float volume=capsule.getVolume();
//subtract the volume of the round edges (a sphere with radius radius)
volume-= ( ((4.0f/3.0f) * FastMath.PI ) * FastMath.pow(radius,3) );
//compute the height of the remaining cylinder
float height=(volume/(FastMath.PI*FastMath.pow(radius,2)));
//add the diameter of the sphere we too off
height+=(radius*2);