TITLE: Volume of intersection of the $n$-ball with a hyperplane
QUESTION [5 upvotes]: Let $\mathcal{B}_n$ be the $n$-ball of radius $r>0$ and centre $\mathbf{x}_0$, i.e., $\mathcal{B}_n=\{\mathbf{x}\in\mathbb{R}^n\colon \|\mathbf{x}-\mathbf{x}_0\| \leq r\}$. 
The volume of $\mathcal{B}_n$ is given by 
$$
V_n(r)=\frac{\pi^\frac{n}{2}}{\Gamma(\frac{n}{2}+1)} r^n.
$$
Moreover, let $\mathcal{H}:\mathbf{w}^\top\mathbf{x}+b=0$ be a hyperplane in $\mathbb{R}^n$. I would like to find the volume of the fraction of $\mathcal{B}_n$ "cut" by $\mathcal{H}$.
If $d$ is the distance between the centre of the ball, $\mathbf{x}_0$, and the hyperplane, $\mathcal{H}$, then the desired volume,$V_\mathcal{H}$, is 
$$
\begin{cases}
0 & \text{if } d\ge r, \\[8pt]
\dfrac{V_n(r)} 2 & \text{if } d=0, \\[8pt]
0 < V_{\mathcal H} \le V_n(r) & \text{if } d<r.
\end{cases}
$$
That is, if $d< r$, the desired volume is given as $V_\mathcal{H}=q(\mathbf{w},b,\mathbf{x}_0,r)V_n(r)$. I would like find this $q$ as a function of $\mathbf{w}$, $b$, $\mathbf{x}_0$, and $r$. I need to use this formula in a computationally expensive process, thus I need it to be "cheap". Any idea? Thank you very much.

REPLY [2 votes]: Assuming you want to compute the $n$-dimensional volume of the intersection of the half-space with the ball.
First of all, reduce the problem to a "standard form".
Suppose $\mathbf e_1,\dots,\mathbf e_n$ is the orthonormal basis in $\mathbb R^n$,
and $\mathbf e^1,\dots,\mathbf e^n$ is dual to it.
Move and rotate the space that the half-space becomes
$$\{\mathbf x\in\mathbb R^n : \mathbf e^n(\mathbf x) = x^n \ge 0\}$$
and the ball's center
$$\mathbf r_0 = - \lambda \mathbf e_n \text{ where } 0 \le \lambda \le r$$
The ball now becomes
$$(\mathbf x + \lambda \mathbf e_n)^2 \le r^2$$
In coordinate form
$$|x^1|^2 + \cdots + |x^{n-1}|^2 + |x^{n} + \lambda|^2 \le r^2$$
$$|x^{n} + \lambda|^2 \le r^2 - |x^1|^2 - \cdots - |x^{n-1}|^2$$
The volume $V'_n$ is just the part of the ball contained in the half-space defined by the $n$-th coordinate hyperplane (i.e. above it).
And may be computed as the integral of the function
$$f(x^1, \dots, x^{n-1}) := x^{n} = \sqrt{r^2 - |x^1|^2 - \cdots - |x^{n-1}|^2} - \lambda$$
over the $n-1$-dimensional disk/ball $D$, whose radius is $r' = \sqrt{r^2 - \lambda^2}$. So
$$V'_n = \int_D \sqrt{r^2 - |x^1|^2 - \cdots - |x^{n-1}|^2}dx^1\dots dx^{n-1} - \lambda \int_D dx^1\dots dx^{n-1}$$
$$V'_n = \int_D \sqrt{r^2 - |x^1|^2 - \cdots - |x^{n-1}|^2}dx^1\dots dx^{n-1} - \lambda V_{n-1}(r')$$
This integral, like for the case of the volume of the whole ball, may be reduced to $n-1$-dimensional version.
And thus may be computed by a recursive formula.