There is a number of similar questions already (e.g. this one), but as far as I can see, none quite cuts it for me.
In $n$-dimensional euclidean space, a hypercube $H$ with side lengths $2A$ is centered around the origin. So is a hypersphere $S$ with radius $x$. What is the fraction of volume of the hypercube $H$ that is also inside the hypersphere $S$, that is, what is the volume of $H\cap S$?
As calculating the fraction with respect to the hypercube is trivial by just dividing by its volume in the end, it boils down to calculating the volume of the intersection. My first idea was to separate three different cases:
- If $x<A$ the hypersphere is fully contained in the hypercube. Then, the volume is simply the volume of the hypersphere, for which there are analytical formulae.
- If $x^2> n \cdot A^2$, the hypercube is fully contained in the hypersphere. In this case, the volume is simply that of the hypercube, that is, $(2A)^n$.
- For intermediate values of $x$, the intersection is given as the volume of the hypersphere minus $2n$ hyperspherical caps, for which there is also a closed form solution (e.g. here)
After my calculation consistently gave wrong results, I was forced to admit that the case (3) is more difficult than I thought, because as soon as the opening angle of the hypercaps is larger than $\pi/4$, they start to intersect along the edges of the hypercube, whereas the corners are still outside the intersection volume. For $n=3$, this can be seen in this graphic, which was generated by wolframalpha.
Thus, the solution proposed in (3) double-counts these volumes.
I can't seem to come up with general solution to calculate this, because counting (and calculating) the intersection areas is very tedious.
Is there any closed-form, analytic solution available for this problem?