# Uniform Distribution on a Sphere: Part 3a (The Solution by Mapping)

(This post continues where we left off in Part 2.)

I have split the solution into two posts. First I show how we could use results from cartography to solve our problem. Then I show how to derive those same results directly using some calculus. While I try to explain the calculus, I realize that I may not be able to reach everyone who is unfamiliar with the concepts. I hope that the first part at least can give all readers a sense of the solution in what I think is a more relatable way than the standard treatment.

Recall the discussion about map projections in Part 2. We showed that mapping our grid of spherical coordinates $\theta$ and $\phi$ onto the sphere was the equivalent of mapping the equirectangular projection of the Earth onto the globe. That is, the distortion of area observed in our rectangular grid (going from 2D to 3D) and on the map (going from 3D to 2D) were the same except in reverse. This tells us that if we are able to find a map projection that preserves area, we could use it to generate uniform points on the sphere. How? Well we know how to draw uniform points on our rectangular map. By definition these points will observe our equal mass/equal area rule. Since equal areas on the map will now correspond to equal areas on the globe, the points on the surface of the sphere will also follow the equal mass/equal area rule. Again, by definition, this means our points will be uniformly distributed on the surface of the sphere.

Now there are many projections that satisfy the equal-area requirement, but we will also specify that we want a cylindrical projection. A cylindrical projection (discussed in footnote 3 of the previous post) guarantees that the lines of latitude on our map will be horizontal and the lines of longitude will be vertical. In other words our map will be rectangular. This is desirable because it is easy generate uniformly random points on a rectangle. We do as we have done before and pick two numbers uniformly at random from each axis to describe every point.

An entire family of cylindrical equal-area projections exist, and they are differentiated by what we'll call a stretch factor. Essentially this stretch factor chooses the width to height ratio of the map. To make the formulas simpler later, we will choose a stretch factor of 1.[1] This specific projection is known as the Lambert cylindrical projection. Figure 1 shows this projection along with the equirectangular projection and the globe. Notice that the Lambert projection adds north-south distortion to the map by compressing the map increasingly as we move toward the poles. This may seem counterproductive in terms of map design, and indeed it distorts the shapes of the countries even further when compared to the globe (look at Greenland). However this distortion is exactly the opposite of the east-west distortion introduced by the equirectangular projection. This results in an equal-area projection at the expense of shape. For our purposes this is fine as we only care about area, but mapmakers may choose other projections that maintain equal area while distorting shape in a way that is more preferable.

Figure 1: (a) Equirectangular projection; (b) Lambert equal-area cylindrical projection; (c) globe

Now we want to use the Lambert cylindrical projection choose uniform points on the sphere. Recall that for the equirectangular projection, we set our x-axis as the angle $\theta$ (longitude) and our y-axis as the angle $\phi$ (co-latitude[2]). For the Lambert projection we keep the x-axis as $\theta$, but now we use the cosine of $\phi$ for the y-axis.[3] Since the cosine will take values from $-1$ to $1$, we will now draw from that interval at random instead of from $0$ to $\pi$. Figure 2(a) shows our distribution of points using this scale. They appear uniform. If we convert our y-axis from $\cos\phi$ back to $\phi$ we get the distribution in Figure 2(b). We notice that the points thin out as we get closer to $\phi=0$ and $\phi=\pi$—the poles of the globe. This is a good sign as before we saw that our points on the sphere bunched up at the poles. If we plot the points in Figure 2(b) on the surface of the sphere, we get Figure 3. Unlike before our points now appear uniform. In fact, the top view and the front view are indistinguishable. This is what we would except as the sphere is symmetric with respect to rotations. We have solved the original problem.

Figure 2: (a) Uniform points in $\theta$ and $\cos\phi$; (b) Those same points in $\theta$ and $\phi$

Figure 3: Top view (left) and front view (right) of points uniformly distributed in $\theta$ and $\cos\phi$

Let’s say, however, that we didn’t have the benefit of referring to a catalog of map projections. How would we be able to solve the problem directly? Continue on to Part 3b for the solution using calculus.

If you would prefer to skip the calculus, you can move directly to Part 4 that discusses an entirely different approach to the problem and its extension into higher dimensions.

1. [1] This results in a width to height ratio of $\pi$. A later note will explain why.
2. [2] Remember that $\phi$ is the inclination angle where 0° (0 radians) is the north pole. Latitude is the elevation angle where 0° is the equator. To convert from one to the other subtract the angle from 90° ($\pi/2$ radians). We will continue to use co-latitude as this is typically how spherical coordinates are defined.
3. [3] This explains why the resulting map has a width to height ratio of $\pi$. Along the x-axis we have the angles $0$ to $2\pi$ radians representing the 360° you can travel around the globe. On the y-axis, we used to have the angles $0$ to $\pi$ radians, but will now have the range from $-1$ to $1$ as $\cos 0=1$ and $\cos \pi = ?1$. The resulting width to height ratio is $2\pi/2=\pi$.