-sphere

Let be an -dimensional hypersphere, or -sphere, of radius centered at the origin:

The volume and surface area of are given by formulas involving the Gamma function :

When the radius is left out it is implied to be one, so , and are the unit -sphere and its volume and surface area respectively.

Distance Metrics

There are two commonly used distance functions on the unit -sphere, the chord distance, , and arc length .

The chord length is simply the metric inherited from the surrounding space

The arc length, , or great-circle distance, is the length of the shortest path between two points on . In one dimension and is ill-defined because there is no connecting path on . A natural extension in this case is to define . We can compute as

While not technically a distance function, another popular function is the 'cosine distance':

We can geometrically interpret the various distances by considering the plane spanned by and intersecting :

Geometric interpretation of distances

The distances and are related by

for small distances they are good approximations of each other with an error of .

Distribution

Consider the uniform distribution on the -sphere. Uniform here taken to mean the natural Lebesgue measure. An elegant procedure to sample from this distribution is by generating standard normal random vectors and normalizing them:

def sample_sphere(count=1, n=1, r=1, rng=np.random.default_rng()):
    x = rng.standard_normal((count, n))
    return r * x / np.linalg.norm(x, axis=1)[:, np.newaxis]

Draw a pair of vectors , from the unit -sphere and consider their distance . Let's do this numerically by generating many distances and plotting the histogram. We do this for a number of dimensions to see how the distribution evolves:

Arc length distribution (numerical)

We see the exceptional bimodal behaviour in one dimension, in two dimensions the distances are uniformly distributed, and with higher dimensions the distribution converges to . The value is the distance from a pole to the equator. Intuitively as we increase the number of dimensions there will be more space orthogonal to a given vector.

My first guess was a Beta distribution with parameters . This matches the behaviour at dimensions and , and behaves similarly for higher dimensions. Unfortunately, for and higher it is very subtly wrong, as can be seen when we overlay it on a high resolution histogram

Arc length distribution

So let's find the true distribution. Given a point , the set of points a distance away from is a -sphere of radius , that is . The infinitesimal probability of hitting this set is (see appendix for derivation)

where is the Beta function

For consecutive values of the probability density function looks like

Arc length distribution

References

Appendix: Derivation

https://math.stackexchange.com/questions/1246748/distribution-of-an-angle-between-a-random-and-fixed-unit-length-n-vectors

Remco Bloemen
Math & Engineering
https://2π.com