# What p.d.f. over angles is equivalent to a uniform distribution over a hypersphere?

Eric Weisstein's Sphere Point Picking points out that sampling uniformly from each angle $$\phi$$ and $$\theta$$ in spherical coordinates does not sample from the uniform sphere because it clusters near the poles. I am interested in which distribution over the angles does sample uniformly over the area element.

For the spherical case, he notes that the random variables $$\phi$$ and $$\theta$$ that do correspond to sampling from the uniform sphere are:

$$\theta = 2\pi u \\ \phi = \cos^{-1}(2v -1)$$

where $$u$$ and $$v$$ are random variables uniformly distributed over [0, 1].

I would like to know how this extends to n-dimensional hyperspheres. Is there a similar expression for the distribution of the angles $$\boldsymbol{\theta}$$ when sampling from a uniform hypersphere?

Very grateful for any help!

(I'm aware that there are simpler ways to sample from the unit hypersphere such as this. I'm specifically interested in the probability density function of the angles.)

• It is not clear to me what your "angles" are for $S^n$ for $n>2$. Can you be more specific, relating your angles to some other standard parameterization, say that by $(x_1,\ldots x_n): \sum x_i^2=1$? Commented Aug 13, 2019 at 2:10
• @kimchilover - en.wikipedia.org/wiki/N-sphere#Spherical_coordinates Commented Aug 13, 2019 at 3:11
• @mr_e_man Oh, in that case don't the absolute values of the sines of the angles have Beta distributions? Commented Aug 13, 2019 at 3:56

If you're using hyperspherical coordinates, the area element of the $$n$$-sphere can be written $$\sin^{n-1}(\phi_1)\sin^{n-2}(\phi_2)\ldots \sin(\phi_{n-1})d\phi_1\ldots d\phi_n$$ where $$\phi_1,\ldots\phi_{n-1}$$ range from $$0$$ to $$\pi$$ and $$\phi_n$$ ranges from $$0$$ to $$2\pi.$$
So this gives you the pdf's of the angles right there: $$\phi_n$$ is uniform, $$\phi_{n-1}$$ has a pdf proportional to $$\sin(\phi_{n-1}),$$ etc.
I don't see a particularly nice way to express the inverse CDF though, which is what you need to get the expression in terms of a uniform. For instance, the way it works for $$\phi_{n-1}$$ is that $$F(\phi_{n-1}) = \frac{\int_0^{\phi_{n-1}}\sin(\phi_{n-1})d\phi_{n-1}}{\int_0^\pi \sin(\phi_{n-1})d\phi_{n-1}} = \frac{1}{2}(1-\cos(\phi_{n-1}))$$ which has inverse function $$F^{-1}(u) = \arccos(1-2u)$$ which agrees with what you were told for the polar angle in the three dimensional case.
But for $$\phi_{n-2}$$ we have $$F(\phi_{n-2}) = \frac{\int_0^{\phi_{n-2}}\sin^2(\phi_{n-2})d\phi_{n-2}}{\int_0^\pi \sin(\phi_{n-2})d\phi_{n-2}} = \frac{1}{\pi}(\phi_{n-2}-\frac{1}{2}\sin(2\phi_{n-2}))$$ which doesn't have any nice inverse in closed form I'm aware of. That said, the CDFs all have closed forms an it is easy enough to invert them numerically.