The Marvelous Trick: Computing the Volume of an n-Dimensional Ball

This morning a classmate asked me about the relationship between the gamma function and the volume of a ball in $n$-dimensional space. I remembered wanting to look into this before but never actually got around to it. Since she brought it up, let's finally finish this unfinished business.

The Standard Approach

Simply put, the volume of an $n$-dimensional ball is the following $n$-fold integral:

$$V_n(r)=\int_{x_1^2+x_2^2+\dots+x_n^2\leq r^2}dx_1 dx_2\dots dx_n$$

Taking a more geometric approach, we can slice the ball with a family of parallel hyperplanes ($n-1$-dimensional slices), decomposing the $n$-dimensional ball into a series of approximate thin cylinders. This gives us a recursive formula:

$$V_n (r)=\int_{-r}^r V_{n-1} \left(\sqrt{r^2-t^2}\right)dt$$

Setting $t=r\sin\theta_1$, we get

$$V_n (r)=r\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} V_{n-1} \left(r\cos\theta_1\right)\cos\theta_1 d\theta_1$$

Iterating once gives

$$V_n (r)=r^2\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} V_{n-2} \left(r\cos\theta_1\cos\theta_2\right)\cos\theta_1\cos^2\theta_2 d\theta_1 d\theta_2$$

Iterating $n-1$ times gives

$$\begin{aligned}V_n (r)=&r^{n-1}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\dots\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} V_1\left(r\cos\theta_1\cos\theta_2\dots \cos\theta_{n-1}\right)\times\\ &\cos\theta_1\cos^2\theta_2\dots\cos^{n-1}\theta_{n-1} d\theta_1 d\theta_2\dots d\theta_{n-1}\end{aligned}$$

where $V_1 (r)=2r$ is a line segment of length twice the radius. From this,

$$V_n (r)=2r^{n}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\dots\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \cos^2\theta_1\cos^3\theta_2\dots\cos^{n}\theta_{n-1} d\theta_1 d\theta_2\dots d\theta_{n-1}$$

Carrying out this integral eventually yields the formula for the volume of an $n$-dimensional ball — the integral itself is certainly solvable (it's just a product of $n-1$ one-dimensional integrals). But this whole procedure is quite cumbersome, and connecting it to the gamma function requires a fair amount of additional work. All in all, it's a standard method that's hard to remember and not particularly elegant.

The Marvelous Approach

There's a wonderfully clever trick using the Gaussian integral that lets us directly connect the volume of a ball to the gamma function. The whole process feels like a stroke of genius, and it gives one the sense of "this is the only way to do it — there's no other route." Apparently this trick is well known among physics students; I came across it via Baidu Wenku], with the original source being Thermodynamics and Statistical Mechanics by Greiner (German author), Example 5.2, the statistical calculation of the entropy of an ideal gas.

This marvelous approach starts by computing the Gaussian integral in two different ways:

$$G(n)=\int_{-\infty}^{+\infty}\dots\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty} \exp\left(-x_1^2-x_2^2-\dots-x_n^2\right)dx_1 dx_2 \dots dx_n\tag{1}$$

On the one hand, treating $(1)$ as an $n$-fold iterated integral — since we already know (see here])

$$\int_{-\infty}^{+\infty}\exp(-t^2)dt=\sqrt{\pi}$$

and $(1)$ is simply the product of $n$ such integrals, we have

$$G(n)=\pi^{n/2}\tag{2}$$

On the other hand, treating $(1)$ as an $n$-fold integral: since the integrand depends only on the variable through the radial length $r=\sqrt{x_1^2+x_2^2+\dots+x_n^2}$, it's natural to think of spherical coordinates — in $n$-dimensional space, these might be called "hyperspherical coordinates." We don't need to write out the hyperspherical coordinates in full; it's enough to note that the integral over the ball can be decomposed into first integrating over "spherical shells," and then integrating over the radius.

$$G(n)=\int_{0}^{+\infty}dr\int_{S_n(r)}\exp\left(-r^2\right)dS_n\tag{3}$$

Here $S_n(r)$ denotes the surface (and surface area — where there's no risk of confusion, I won't distinguish between the two) of the $n$-dimensional ball of radius $r$. But notice that since the integrand depends only on $r$, integrating over the sphere's surface is equivalent to just multiplying the original function by the sphere's surface area. So the result of $(2)$ is

$$G(n)=\int_{0}^{+\infty}dr\exp\left(-r^2\right)S_n(r)\tag{4}$$

Although we don't yet know the formulas for the volume and surface area of an $n$-dimensional ball, we can be certain that the volume of an $n$-dimensional ball must be proportional to $r^n$, i.e.,

$$V_n (r)=V_n(1)r^n$$

The surface area of the ball is the first derivative of its volume (thinking of it as a decomposition into spherical shells), so

$$S_n (r)=n V_n(1)r^{n-1}$$

Substituting into $(4)$, we get

$$\begin{aligned}G(n)=&n V_n(1)\int_{0}^{+\infty}r^{n-1}\exp\left(-r^2\right)dr\\ =&\frac{1}{2}n V_n(1)\int_{0}^{+\infty}(r^2)^{n/2-1}\exp\left(-r^2\right)d(r^2)\\ =&\frac{1}{2}n V_n(1)\int_{0}^{+\infty}z^{n/2-1}\exp\left(-z\right)dz\quad\left(z=r^2\right)\\ =&\frac{1}{2}n V_n(1)\Gamma\left(\frac{n}{2}\right)\end{aligned}\tag{5}$$

Combining this with $(2)$ gives

$$\pi^{n/2}=G(n)=\frac{1}{2}n V_n(1)\Gamma\left(\frac{n}{2}\right)$$

from which

$$V_n(1)=\frac{\pi^{n/2}}{\frac{1}{2}n\Gamma\left(\frac{n}{2}\right)}=\frac{\pi^{n/2}}{\Gamma\left(\frac{n}{2}+1\right)}$$

and finally

$$V_n(r)=\frac{\pi^{n/2}}{\Gamma\left(\frac{n}{2}+1\right)}r^n$$

And just like that, we've obtained the formula for the volume of an $n$-dimensional ball! Differentiating with respect to $r$ gives the surface area formula for the $n$-dimensional sphere:

$$S_n(r)=\frac{2\pi^{n/2}}{\Gamma\left(\frac{n}{2}\right)}r^{n-1}$$

Putting the two methods together, we obtain

$$\frac{\pi^{n/2}}{\Gamma\left(\frac{n}{2}+1\right)}=2\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\dots\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \cos^2\theta_1\cos^3\theta_2\dots\cos^{n}\theta_{n-1} d\theta_1 d\theta_2\dots d\theta_{n-1}$$

A Brief Remark

This trick is remarkably elegant and concise. The Gaussian integral and the change to spherical coordinates are both things physics students know intimately, and with just a little twist of insight, the result falls right out. It really does feel like the kind of clever idea that only a physics student could come up with!

What's even more delightful is that this idea feels so magical that one is tempted to use it for more things — but after a little investigation, the conclusion is clear: there's nothing more it can do! In other words, the whole procedure seems tailor-made for exactly this one purpose: computing the volume of an $n$-dimensional ball! Truly "there's no other way to do it"! Marvelous indeed~~

English translation of a post from 科学空间 | Scientific Spaces by 苏剑林. Original: https://kexue.fm/archives/3154
Translated automatically with claude-sonnet-5; all equations are reproduced verbatim from the source. Copyright remains with the original author.