Volume of sphere-cube intersection I am looking for a formula for the volume $V_i(r,L)$ of the intersection between a sphere of radius $r$ and a cube of edge $L$ with the same center.
For $r<\frac L 2$, $V_i$ is simply equal to the volume of the sphere:
$$V_i(r,L) = \frac 4 3 \pi r^3 \ \ \ \ r<\frac L 2$$
For $r>\frac{\sqrt 3} 2 L $, it is equal to the volume of the cube: 
$$V_i(r,L) = L^3 \ \ \ \ r>\frac {\sqrt 3} 2 L$$
For $\frac L 2 < r < \frac{\sqrt 2} 2 L$, it is equal to the volume of the sphere minus six times the volume of a spherical cap. The result is
$$V_i(r,L) =  \frac 4 3 \pi r^3 -\frac \pi 4(2r-L)^2(4r+L) \ \ \ \ \frac L 2 < r < \frac{\sqrt 2} 2 L$$
However, for $\frac{\sqrt 2} 2 L < r < \frac{\sqrt 3} 2 L$ I have not been able to think of an easy way to calculate $V_i(r,L)$.
 A: As John Hughes notes, you can fix the side of the cube or radius of the sphere and work in terms of the ratio. The strategy here is to fix the cube's edge length to be $2$, calculate the area of plane slices parallel to one face of the cube, then apply Cavalieri's theorem.

Theorem: The intersection of the square $[-1, 1]^{2}$ with the disk of radius $\rho$ centered at the origin has area
$$
A(\rho) = \begin{cases}
  \pi \rho^{2} & 0 \leq \rho \leq 1, \\
  \pi \rho^{2} - 4\rho^{2} \arccos(1/\rho) + 4\sqrt{\rho^{2} - 1} & 1 < \rho < \sqrt{2}, \\
  4 & \sqrt{2} \leq \rho.
\end{cases}
$$
The intersection of the cube $[-1, 1]^{3}$ with the ball of radius $r$ centered at the origin has volume
$$
V(r) = \int_{-\min(1, r)}^{\min(1, r)} A(\sqrt{r^{2} - x^{2}})\, dx
= 2\int_{0}^{\min(1, r)} A(\sqrt{r^{2} - x^{2}})\, dx.
$$

Trivial Cases/Sanity Checks:


*

*If $0 \leq r \leq 1$, then $0 \leq \sqrt{r^{2} - x^{2}} \leq 1$ for $|x| \leq r$, so $A(\sqrt{r^{2} - x^{2}}) = \pi(r^{2} - x^{2})$ and $V(r) = \frac{4}{3}\pi r^{3}$.

*If $\sqrt{3} \leq r$, then $\sqrt{2} \leq \sqrt{r^{2} - x^{2}}$ for $|x| \leq 1$, so $A(\sqrt{r^{2} - x^{2}}) = 4$ and $V(r) = 8$.
Interesting Cases (edited to fix mishap with limits of integration):


*

*If $1 < r \leq \sqrt{2}$ (dark gray), then


*

*$\sqrt{r^{2} - x^{2}} \leq 1$ for $\sqrt{r^{2} - 1} \leq |x| \leq 1$,

*$1 \leq \sqrt{r^{2} - x^{2}} \leq \sqrt{2}$ for $|x| \leq \sqrt{r^{2} - 1}$,


so the volume is
\begin{align*}
  V(r) &= 2\int_{0}^{1} A(\sqrt{r^{2} - x^{2}})\, dx \\
  &= 8\int_{0}^{\sqrt{r^{2} - 1}}  \bigl[-(r^{2} - x^{2})\arccos\left(\frac{1}{\sqrt{r^{2} - x^{2}}}\right) + \sqrt{r^{2} - 1 - x^{2}}\bigr]\, dx \\
  &\quad + 2\pi\int_{\sqrt{r^{2}-1}}^{1} (r^{2} - x^{2})\, dx.
\end{align*}
(The second integral evaluates to $\frac{2}{3}\pi\bigl[(3r^{2} - 1) - (2r^{2} + 1)\sqrt{r^{2} - 1}\bigr]$, of course. I haven't verified explicitly that $V(r)$ evaluates to $\frac{4}{3}\pi r^{3} - 2\pi(r - 1)^{2}(2r + 1)$; the integral is elementary, but integrating by parts and making the obvious trig substitution gives a rational function of sine that looks tedious to integrate.)

*If $\sqrt{2} < r < \sqrt{3}$ (light gray), then


*

*$1 \leq \sqrt{r^{2} - x^{2}} \leq \sqrt{2}$ for $\sqrt{r^{2} - 2} \leq |x| \leq 1$,

*$\sqrt{2} \leq \sqrt{r^{2} - x^{2}} \leq \sqrt{3}$ for $|x| \leq \sqrt{r^{2} - 2}$,


so the volume is
\begin{align*}
  V(r) &= 8\sqrt{r^{2} - 2} \\
  &\quad+ 8\int_{\sqrt{r^{2}-2}}^{1} \bigl[-(r^{2} - x^{2})\arccos\left(\frac{1}{\sqrt{r^{2} - x^{2}}}\right) + \sqrt{r^{2} - 1 - x^{2}}\bigr]\, dx.
\end{align*}
Again, this integral is elementary, and can be evaluated exactly (in principle).
A: Since you speak of an "easy way" to compute the volume in this third case, I can only say this: I don't think that there is an easy way. My thoughts and (modest) initial efforts to solve this follow, but they don't finish with an actual formula, so read on only for inspiration, not a solution. 
First, fix the sphere radius $r$ at $1$. You'll get an answer $U(L)$ in terms of $L$, but for any $(L,r)$ pair, the answer will just be
$$
Vol(L, R) = r^3 U(L/r) 
$$
so that simpler answer will implicitly provide the more complex one 
The "interesting case" is when the corner of the cube "pokes out" of the sphere, but any two adjacent "poking out" bits don't poke out far enough to reveal the entire edge between them on the outside of the sphere. 
To address this case, I want to rotate the whole problem, so that one vertex of the cube lies at $P = c(0,1,0)$, where $c = \sqrt{3}L/2$, and one edge of the cube lies in the $yz$ plane with $z > 0$, i.e., $\theta = 0$ in polar coordinates (where $y = 1$ is the north pole, where $\phi = 0$, and at $(0, 0, 1)$ we have $\theta = 0, \phi = \pi/2$, just to establish the coordinates I'll be using. 
Now looking down on the north pole, we see the three edges of the protruding corner of the cube; in polar coordinates, they lie along the planes $\theta = 0, \theta = 2\pi/3, \theta = 4\pi/3$. I'm going to compute the volume $V$ of one of the three "wedges" of this protruding piece. 
The volume of the whole protrusion will be $3V$, and the volume of all protrusions will $24V$, so the total cube-sphere intersection will be the cube volume $L^3$, with these protrusion subtracted, i.e., 
$$
U(L) = L^3 - 24 V.
$$
So what is $V$? It's an integral, in polar coordinates, of the radius-function $h(\theta, \phi)$ for the cube minus the radius function for the sphere, which is just the constant $1$. The limits of the integral are 
$$
0 \le \theta \le 2\pi/3
$$
and 
$$
0 \le \phi \le ???
$$
To figure out that missing bound, I'm going to write the equation, in polar coordinates, for the cube-face that lies between $\theta = 0$ and $\theta = 2\pi/3$, i.e., the face on which $x$ is always positive, and which contains $c(0,1,0)$.
The unit normal to this plane is 
$$
n = \begin{bmatrix} 
\frac{1}{\sqrt{2}} \\
\frac{1}{\sqrt{3}} \\
\frac{1}{\sqrt{6}} 
\end{bmatrix}
$$
The plane equation is then 
$$
X \cdot n = L,
$$
When you convert this to polar coordinates, you get a rather messy expression for the radius of the vector $X$, which is what I've called $h(\theta, phi)$. Setting this messy expression to $r = 1$ determines the curve of intersection between the cube-face and the sphere, which you can solve for $\phi$ in terms of $\theta$, getting some expression 
$$
\phi = q(\theta)
$$
And now 
$$
V = \int_{\theta=0}^{\frac{2\pi}{3}} \int_{\phi = 0}^{q(\theta)} s ~d\theta.
$$
$$
V = \int_{\theta =0}^{\frac{2\pi}{3}}\int_{\phi = 0}^{q(\theta)}  (h(\theta, \phi) - 1) J(\theta, \phi) ~d\phi ~d\theta.
$$
where $J$ is the appropriate Jacobian ($\sin \phi ? \cos \phi ?$) for this set of polar coordinates. 
