Uniform Distribution on a Sphere: Part 4 (The Easy Way)

(This post continues where we left off in Parts 3a and 3b and provides an alternative solution to the problem that is more useful in practice.)

We saw that using spherical coordinates to generate random points on the surface of a sphere required us to transform one of our angles to obtain a uniform distribution. In Part 3a we performed this transformation with the help of map projections, and in Part 3b we found it directly by using calculus. What would happen if we wanted to generalize this procedure to higher dimensions?

First of all, this may sound crazy. The sphere is in three-dimensional space, right? How could we even think about it in four dimensions let alone more? We won’t be able to visualize any of these things, but we will generalize the idea of the familiar sphere into any number of dimensions.

Think of the unit sphere we have seen so far. It is the collection of points in three-dimensional space such that each point is one unit distance from the origin[1]. We’ve also seen that this surface is two-dimensional—i.e., we only need two numbers (latitude and longitude) to specify any point on the sphere. Therefore we call this particular sphere S^2, where the “2” signifies that it is a two-dimensional surface. We also say that this surface is embedded in \mathbb{R}^3, a space where each point is described by three real numbers (coordinates)—i.e., the space is three-dimensional. If we consider the n-dimensional space \mathbb{R}^n, the points that are one unit away from the origin again make up the unit sphere that we will call S^{n-1}. So again for n=3 we have our familiar sphere S^2. For n=2 we have the unit circle S^1 in \mathbb{R}^2. Ask yourself: what is S^0 in \mathbb{R}, the real numbers?[2] We can also go the other way and now consider the unit sphere in any number of dimensions. Even though we cannot plot these things, some problems in applied mathematics require generating uniform points on these higher dimensional surfaces.

We could try to extend the approach taken in the earlier posts. That is, we could define points in \mathbb{R}^n by their distance from the origin and n-1 angles. We call these hyperspherical coordinates. Just as in the case of the familiar sphere, moving from the lower dimensional space of spherical angles to the surface in higher dimensional space will create distortion. We will need to analyze the distortion and correct it. This gets more complicated as we increase the number of dimensions. Instead we would prefer a simple technique that would apply generally to S^{n-1} in \mathbb{R}^n.

So instead let’s consider a vector (point) \vec{x} in \mathbb{R}^n. We say that it has coordinates x_1 to x_n. The (Euclidean) norm of the vector is simply the length of the straight line connecting the point (x_1,\ldots,x_n) to the origin. By using the distance formula we find that


where \|\vec{x}\| is the norm of \vec{x}. Notice that if we multiply \vec{x} by a constant c—i.e, we multiply each coordinate by c—the norm \|c\vec{x}\|=c\|\vec{x}\|. Also note that our definition of the sphere S^{n-1} means that if we define a new vector \vec{u}=\vec{x}/\|\vec{x}\| it will lie on the sphere since \|\vec{u}\|=1. This is called normalizing the vector \vec{x} to unit length.

Now we will consider a random vector \vec{X}[3] in \mathbb{R}^n that has random coordinates X_1 to X_n. We choose to generate each coordinate by using a standard normal (Gaussian) distribution. This distribution has the familiar shape of the bell curve. Also notice that we are generating each coordinate independently—i.e., the value of one coordinate has no effect on the value of any other coordinate. I claim that the random vector \vec{U} given by \vec{U}=\vec{X}/\|\vec{X}\| has the uniform distribution on the surface of the sphere S^{n-1}.

To prove this claim we need to show that:

  1. The random vector \vec{U} lies on the sphere
  2. The distribution of \vec{U} is uniform

From the description of non-random vectors above we can easily see that \|\vec{U}\|=1, and so it must lie on the sphere. In order to show that it is distributed uniformly, we will use a different characterization of uniformity than earlier. Look at Figure 1, the result of the solution presented in Part 3.

Uniform points on a sphere
Figure 1: Top view (left) and front view (right) of uniform points on the surface of S^2

Notice that both images look roughly the same. From these pictures we are not able to distinguish which viewpoint is which. Mathematically we say that the uniform distribution on the sphere is invariant under rotations. If we rotate the sphere (or our viewpoint) in space, the distribution remains exactly the same. This makes sense in terms of our previous equal mass/equal area rule. Consider one of the rectangular patches in the above image. If we hold that patch fixed in our view and rotate the sphere under it, this is equivalent to moving the patch somewhere else on the sphere without changing its area. The equal mass/equal area rule then tells us that each time we rotate the sphere, the expected mass in our view does not change. Conversely if the expected mass in view doesn’t change as we rotate the sphere, then the distribution must be invariant under rotations.

Armed with our new characterization of uniformity, we can now show that \vec{U} is indeed uniformly distributed on the sphere. First notice that if we rotate any vector its length remains the same.[4] Since \vec{U} is defined only in terms of \vec{X} and its length, it suffices for us to show that the distribution of \vec{X} does not change under rotations. In other words, the probability density f_{\vec{X}}(\vec{x}) at any point \vec{x} remains the same if we rotate \vec{x}. Since each coordinate X_i of \vec{X} is chosen independently, the density function of \vec{X} is the product of the density functions of all the X_i.[5] By looking up the density of the standard normal distribution[6] we find that


where \prod is the “product” symbol. We have shown that f_{\vec{X}}(\vec{x}) only depends on \|\vec{x}\|. Since this quantity does not change when we rotate \vec{x} then we have also shown that the density function of \vec{X} is invariant under rotations. This is exactly what we needed to do, and so we conclude that the distribution of \vec{U} is uniform over the surface of the sphere.

The explanation of this solution may not have seemed any simpler than the ones in Parts 3a and 3b, but notice that the method of generation is much simpler. For any dimension n, all we must do is take n draws from a standard normal distribution and normalize[7]. All mathematics and statistics software have this capability and can perform the operations quickly. It is really a clever trick and allows the solution of this problem easily for spheres in any dimension.

That concludes this series of posts. If you have made it the entire way, I hope that you have learned something about this particular problem as well as its connection to cartography. Thanks for reading!

  1. [1] Mathematicians like to work with dimensionless quantities. That is, we don’t specify whether it’s one inch, meter, etc. It’s just one away from the origin.
  2. [2] The points on the real line that are one away from the origin (zero) are 1 and –1. Therefore S^0 is just these two points.
  3. [3] Recall that we use capital letters to refer to random variables.
  4. [4] This fact is something we could prove, but the proof does not add to the discussion. We will just consider it true based on our intuition of rotations.
  5. [5] In the interest of space, I will not explain this. If you are unfamiliar with probability, you should take this as fact.
  6. [6] f_{\mathcal{N}}(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2}
  7. [7] This is sometimes called projecting the points onto the sphere.