That's very easy, it's a function of an XYZ loop....
You would be actually doing a marching cubes kind of logic, and an ISOsurface logic for a spherical volume.
The first result is this programming query (in metacode):
var cubecount:
ForLoop(x,y,z){
If space(x,y,z) corresponds to DistanceFunction(x,y,z) == 1;
Then cubecount +=1:
question 2 is the same using >=1
For a sphere on zero of radius 1. (distancefunction is xposvectormagnitude, same thing if the sphere is origin is 0; otherwise the sphere pos equation is for the xyz loop is:
This code makes a 3d printable off axis voxel ball if you want:
num = 45.9874;
for (x =[-num-5:num+5])
{
for (y =[-num-5:num+5])
{
for (z =[-num-5:num+5])
{
if ((x+1.24)*(x+1.24)+(y+1.66)*(y+1.66)+(z+1.88)*(z+1.88)<=num)
translate([x,y,z])
cube(1);
}
}
}
https://www.thingiverse.com/thing:3075040
The same holds, that in $\mathbb{R}^n$, $A = r \frac {V_b}{n}$, where $A$ is the volume of your simplex, and $V_b$ is the volume of your boundary.
To see why this works, simply show that a simplex with base of volume $B$ and height $r$ has volume $ r \frac {B}{n}$, and then add up over all faces.
Hint: The constant $\frac {1}{n}$ comes from $\int x^{n-1}\, dx = \frac {x^n}{n}$.
Best Answer
The volume of a n-sphere with radius $\displaystyle R$ is $\displaystyle \frac{\pi^{\frac{n}{2}}}{\Gamma{(\frac{n}{2}+1)}} R^n$. The volume of a n-cube with side $\displaystyle S$ is $\displaystyle S^n$, and its longest diagonal is $\displaystyle S \sqrt{n}$. In this case we have $S \sqrt{n}=2R$ and then $\displaystyle S=\frac{2R}{\sqrt{n}}$, which leads to a n-cube volume equal to $\displaystyle \frac{(2R)^n}{n^{\frac{n}{2}}}$.
The ratio of the inscribed n-cube volume to the total n-sphere volume is then
$$\displaystyle \frac{(2R)^n \, \Gamma{(\frac{n}{2}+1)} }{n^{\frac{n}{2}} \pi^{\frac{n}{2}} R^n}$$
which can be simplified in
$$\displaystyle \frac{2^n \, \Gamma{(\frac{n}{2}+1)} }{(n\pi)^{\frac{n}{2}}}$$
The first values for $n=2,3,4,5...$ are $\displaystyle \frac{2}{\pi}$, $\displaystyle\frac{2}{\sqrt{3}\pi}$,$\displaystyle\frac{2}{\pi^2}$, $\displaystyle\frac{12}{5 \sqrt{5} \pi^2}$, and so on. Note that, as $n \rightarrow \infty$, the ratio converges to zero.