[Tex/LaTex] Hypersphere inscribed within hypercube


Let's consider a hypersphere of radius r inscribed in a hypercube with sides of length 2r. Than take the ratio of the volume of the hypersphere of radius r to the hypercube with side length l = 2r. We observe the following trends.

In two dimensions we have

enter image description here

and in three dimensions we have

enter image description here

For a general case, as the dimensionality d increases asymptotically, we get

enter image description here

This means that as the dimensionality increases, the most of the volume of the hypercube is in the corners, whereas the center is essentially empty. In very high dimensions the figure looks like porcupine, as illustrated in the figure below (figure is taken from Zaki, 2013).

enter image description here

Subfigure (a) represents hypersphere inscribed withih hypercube in two dimensions. Subfigures (b) and (c) represent the same concept in three and four dimensions, respectively. In d dimensions there are 2^d corners and 2^(d - 1) diagonals. The radius of the inscribed circle reflects the difference between the volume of the hypercube and the inscribed hypersphere in d dimensions.

My question: How to start with reproduction of this figure? Should I use Metapost or TiKZ? Thanks in advance for any pointers or suggestions?

Best Answer

Here's an attempt in Metapost.

enter image description here

The picture shows d=2, d=3, d=4, and d=6. It was easier to compute and store the ratios than fiddle about doing them in MP each time. Obviously it does not work for d<2, and for d>8 you basically get a completely black disc.

prologues := 3;
outputtemplate := "%j%c.eps";

ratio2  = 0.78540 ; 
ratio3  = 0.52360 ; 
ratio4  = 0.30843 ; 
ratio5  = 0.16449 ; 
ratio6  = 0.08075 ; 
ratio7  = 0.03691 ; 
ratio8  = 0.01585 ; 
ratio9  = 0.00644 ; 

vardef hs_in_hc(expr d, r) = % d = dimensions, r = outer radius 
   save s, inner_circle, outer_circle;
   s = 8/(2**d); % there are 8 points on a fullcircle path
   path outer_circle, inner_circle;
   outer_circle = fullcircle scaled 2r;
   inner_circle = outer_circle rotated 22.5s scaled (0.9*ratio[d]);
     fill inner_circle withcolor .8 white;
     draw inner_circle;
     draw point 0 of outer_circle -- point 0 of inner_circle
        for i=s step s until 8-eps: 
          -- point i of outer_circle 
          -- point i of inner_circle 
        -- cycle;
     for i=0 step s until 8-eps: 
       draw origin -- point i of outer_circle dashed withdots scaled .5;
    ) enddef;


  draw hs_in_hc(2,50);
  draw hs_in_hc(3,50) shifted 100 right;
  draw hs_in_hc(4,50) shifted 200 right;
  draw hs_in_hc(6,50) shifted 300 right;



eps is defined in plain Metapost to be a small positive number. The value is actually 0.00049. I used it above in order to ensure that the loop stops just before it gets to 8. The smallest possible positive number in Metapost is epsilon, which is defined to be 1/256/256.

Related Question