Library · Geometric Probability · Chapter 59
Expected distance in a ball
Problem 59.1
Let be points chosen independently and uniformly at random in the closed unit ball in . What is the expected distance ?
Solution. By rotational symmetry, condition on at distance from the origin; WLOG take . The marginal density of is for (the Jacobian of the radial-coordinate change in the unit ball). Similarly, has density for .
For fixed , the angle between and has density on (standard spherical coordinates). Hence Substitute , so : The inner integral evaluates (by the standard antiderivative ) to For , , so the conditional expectation simplifies to
Combine over . By symmetry in , we may write where the factor of comes from ( from the symmetry, and from the two radial densities). Carry out the inner integral: the integrand being (keeping the density factor). Then So
The closed form is the three-dimensional companion of the disc constant . The appearance of a rational number in 3D — versus a -involving number in 2D — reflects the difference in the angular integrals: in 2D the angular integral produces an elliptic integral (yielding ), while in 3D the angle has the simple measure that integrates to elementary functions.
import numpy as np
# Two uniform points in unit ball via rejection sampling
def sample_ball(n):
out = np.empty((3, n))
filled = 0
while filled < n:
c = np.random.uniform(-1, 1, (3, 2*n))
mask = (c*c).sum(axis=0) <= 1
good = c[:, mask][:, :n-filled]
out[:, filled:filled+good.shape[1]] = good
filled += good.shape[1]
return out
p1, p2 = sample_ball(10**6), sample_ball(10**6)
d = np.linalg.norm(p1 - p2, axis=0)
print(f"sim: {d.mean():.5f} exact: {36/35:.5f}")
# sim: 1.02838 exact: 1.02857