-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 :
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:
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
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
References
- S. Li (2011). Concise Formulas for the Area and Volume of a Hyperspherical Cap. https://dx.doi.org/10.3923/ajms.2011.66.70
- Panagiotis Sidiropoulos (2014). N-sphere chord length distribution. https://arxiv.org/abs/1411.5639v1
- J.C. Baez, G. Egan, J.D. Cook, D. Piponi (2018). Random Points on a Sphere (Part 1) https://johncarlosbaez.wordpress.com/2018/07/10/random-points-on-a-sphere-part-1/
Appendix: Derivation