...

Hypersphere in an n-Cube: Projection, Radial Shell Map and Volume Fractions (2D)

Look at the unit n-ball from the side of the data: a 2D projection of random points of the n-cube, a heat map of where the ball's volume sits as n grows, measured against exact radial and Gamma-function results.
Switch to 3D
Random cube points sampled-
Fraction inside the ball (measured)-
Exact fraction V_n / 2^n-
V_n from Gamma function-
V_n estimated: 2^n x fraction-
Cube corner distance √n-
Volume in outer shell: 1-(1-ε)^n-
Mean radius n/(n+1)-
Density of the radius r of points inside the ball: blue exact n r^(n-1), yellow measured. Orange line: shell edge 1-ε.
Volume fraction inside radius r: r^n. Green chosen n, grey n = 2, 5, 10, 20. The gap between the orange dot and 1 is the shell volume.
Independent numerical checks
Each line compares two separate calculations; a FAIL would show here.
The science

Idea. Geometry in many dimensions is a real branch of mathematics with practical uses (data science, statistical physics, coding theory). It behaves very differently from the 2D and 3D intuition. This page works with the unit ball |x| <= 1 in n dimensions and the cube [-1,1]^n that contains it. It is ordinary geometry; no "extra dimension of space" is claimed to exist or to be reachable.

  • Volume of the unit n-ball: V_n = pi^(n/2) / Gamma(n/2 + 1), also V_n = (2 pi / n) V_(n-2) with V_0 = 1, V_1 = 2. Examples: V_2 = pi, V_3 = 4 pi / 3, V_5 = 8 pi^2 / 15 = 5.26 (the maximum), and V_n then falls towards zero.
  • The cube has volume 2^n, so the ball fills only the fraction V_n / 2^n: 78.5 % for n = 2, 52.4 % for n = 3, 0.25 % for n = 10, about 2.5e-8 for n = 20. The corners of the cube are at distance sqrt(n) from the centre, so they stick out further and further beyond the ball of radius 1.
  • Thin shell: volume scales as r^n, so the fraction of the ball inside radius 1 - eps is (1 - eps)^n; for n = 20 and eps = 0.1 about 88 % of the volume is in the outer 10 % shell. A random point of the ball has mean radius n/(n+1).

Monte Carlo. Random points are drawn uniformly in the cube and counted when sum x_i^2 <= 1. The estimate is 2^n x (hits / samples) with standard error from the binomial law. For n above about 12 the hit probability is so small that few or no hits occur, which is the "curse of dimensionality": naive sampling stops working and smarter methods are needed.

Independent checks. (1) Gamma-function formula (Lanczos approximation) against the exact recurrence, n up to 20. (2) Measured hit fraction against the exact fraction as a z-score when at least 30 hits exist. (3) Among the sampled hits, the fraction in the outer shell and the mean radius against the closed forms.

Simplifications. Only three coordinates of an n-dimensional point can be displayed, so the 3D picture is a projection. Random numbers come from a seeded pseudo-random generator.

Cube frame, glass ball, sample points and plinth were modelled and textured in Blender; sampling and plots run in Three.js r160 and plain JavaScript.

2D view: top-down / diagram rendering with sprites rendered in Blender (Cycles) from the 3D page's model parts; all numbers come from the same solver as the 3D page.

Made with 🟠 Blender