Volume of a spherical cap (source code)

= Volume of a spherical cap
{title2=$V=\pi h^2(R-h/3)$}

For a solid <spherical cap> of height $0\leq h\leq2R$ cut from a <sphere> of <radius> $R$,
$$
\boxed{V=\pi h^2\left(R-\frac h3\right).}
$$
Centre the <sphere> at the origin with the cap on the side $z\geq R-h$. Its cross-section at height $z$ is a <circle> of squared <radius> $R^2-z^2$. A <volume integral> in <cylindrical coordinates> gives
$$
V=\int_{R-h}^{R}\int_0^{2\pi}\int_0^{\sqrt{R^2-z^2}}r\,dr\,d\phi\,dz=\pi\int_{R-h}^{R}(R^2-z^2)\,dz=\pi h^2(R-h/3).
$$
The formula includes caps larger than a <hemisphere>, when $h>R$, and the whole solid <sphere>, when $h=2R$. For the retained region $z\geq-d$ with $0<d<R$, set $h=R+d$ to obtain $V=\pi(2R^3/3+R^2d-d^3/3)$. Multiplying by uniform <mass density> gives its <mass>.