How to compute the volume of intersection between two hyperspheres

Let's suppose you are given the coordinates of the center and radius of each sphere. Then you can compute the distance between their centers.

The volume of the intersection depends only on this distance $d$ and the two radii $r_1$, $r_2$.

If $d \ge r_1+r_2$ then the sphere interiors do not intersect and the volume is zero.

If $d \le |r_1-r_2|$, then one sphere is inside the other and the volume is that of the smaller sphere.

Otherwise, the volume consists of two spherical caps, glued at a hyperplane.
The cap sizes can be found by considering the triangle with sides $r_1$, $r_2$, $d$, which appears on any planar cross-section including the line through the centers. The altitude to side $d$ is where the two caps are glued. The cap base heights are at the (signed) distances from the endpoints of side $d$ to this altitude: $$c_1 = \frac{d^2+r_1^2-r_2^2}{2d}$$ $$c_2 = \frac{d^2-r_1^2+r_2^2}{2d}$$

Now we just need to compute the cap volumes. EDIT: This cannot be done using elementary functions. The volume of a spherical cap can be expressed in terms of the gamma function $\Gamma$ and the regularized incomplete beta function $I$. For a clean derivation, see Concise Formulas for the Area and Volume of a Hyperspherical Cap, Shengqiao Li, Asian Journal of Mathematics and Statistics 4(1), 66-70, 2011.

$$ V^{cap}_n(r,a \ge 0) = \frac{1}{2} \frac{\pi^{n/2}}{\Gamma(\frac{n}{2}+1)}r^n I_{1-a^2/r^2}(\frac{n+1}{2},\frac{1}{2}) $$ $$ V^{cap}_n(r,a < 0) = \frac{\pi^{n/2}}{\Gamma(\frac{n}{2}+1)}r^n - V^{cap}_n(r,-a) $$

The final answer is then $V^{cap}_n(r_1,c_1)+V^{cap}_n(r_2,c_2)$.


It seems to me that the answer written above by Matt is incorrect. Specifically, the expression that is believed to be the exact value of $V_n^{cap}(r,a)$ is in fact only an underestimation which gets farther from the correct value as $n$ is increased. Formally the radius of $V_n^{cap}$ for a specific $x$ should be $$\sqrt{r^2-(r-x)^2}=\sqrt{2rx-x^2},$$ instead of just $x$.

Thus, the integral for this expression should look as follows $$V_n^{cap}(r,a)=\int_a^r V_{n-1}\left(\sqrt{2rx-x^2}\right)dx,$$ although I'm not sure how it can integrated.


Following the idea of using caps, The Wikipedia article has a mention of a nice asymptotic result: If $h$ is the height of the cap and $r$ is the radius of the hypersphere, then $V^{cap}_n\rightarrow V_n(1-F((1-h/r)\sqrt{n}))$ for large $n$, where $F$ is the integral of the standard gaussian.

In our case $h=\frac{2r-d}{2}$ and we are interested in the intersection which is $2V_n^{cap}$, so we get $2V^{cap}_n\approx V_n\,2(1-F(\frac{d}{2r}\sqrt{n}))$.

This shows that the intersection, even normalized by $V_n$ goes to $0$ as the dimension gets large. Pretty cool.