# Why are points uniformly distributed on a sphere in 3D uniformly distributed in component coordinates?

I've generated uniformly random points on a sphere (in 3D). As expected, all azimuthal angles are drawn with equal probability and it's less likely to draw points close to the poles:

However, when I histogram the Cartesian coordinates, I see that the draws are uniformly distributed in all dimensions:

Why are the points uniformly distributed in the x, y, and z dimensions? I don't find that intuitive. Slices near the poles have less surface area than slices near the equator. Therefore, I expect more points on the equatorial slice, and for the points to cluster around the mean when I project them onto a single dimension (like the distribution of theta):

I tried 3 different methods to generate uniformly random points on the surface of the sphere because I was convinced I was doing something wrong, but they all gave the same results:

import numpy as np
from numpy.random import uniform

n = 500_000

# method 1: trigonometry
# based on http://stackoverflow.com/a/6390021/4212158
azimuth_angle = uniform(0, 2 * np.pi, n)
inclination_angle = np.arccos(1 - 2 * uniform(0, 1, n))
radius = 1.0  # unit sphere
x = radius * np.sin(inclination_angle) * np.sin(azimuth_angle)
y = radius * np.sin(inclination_angle) * np.cos(azimuth_angle)

# method 2: rescaled Gaussian samples
# http://stackoverflow.com/a/33977530/4212158
gaussian_points = np.random.randn(3, n)
x, y, z = gaussian_points / np.linalg.norm(gaussian_points, axis=0)
azimuth = np.arctan2(y, x)
inclination = np.arccos(z)

# method 3: another trig method
# credit http://stackoverflow.com/a/14805715/4212158
z = uniform(-1, 1, n)
azimuth = uniform(0, 2 * np.pi, n)
x = np.sqrt(1 - z**2) * np.cos(azimuth)
y = np.sqrt(1 - z**2) * np.sin(azimuth)
inclination = np.arccos(z)

import matplotlib.pyplot as plt

fig1, axarr = plt.subplots(3, sharex=True)

axarr[0].hist(x, bins=50, density=True)
axarr[0].set_title("x")
axarr[1].hist(y, bins=50, density=True)
axarr[1].set_title("y")
axarr[2].hist(z, bins=50, density=True)
axarr[2].set_title("z")
plt.suptitle("Histogram of xyz coordinate draws")
plt.xlabel("Distance from origin")
plt.ylabel("Probability")
plt.show()

fig2 = plt.figure()
plt.scatter(azimuth, inclination, c="black", marker=".", alpha=0.02)
plt.title("Azimuthal vs inclination angles of points uniformly distributed on surface of unit sphere")
plt.show()

fig3 = plt.plot()
plt.hist(inclination, bins=50, density=True)
plt.title("Distribution of inclination angles")
plt.ylabel("Probability")
plt.show()

• I call this the "tennis can theorem." (It was known to Archimedes, but not by that name.) The total surface area of tennis balls packed tightly in a cylindrical can equals the surface area of the can itself (not counting its caps). In fact, more is true: were you to make two orthogonal slices through can and balls both, then the surface area of the can and the surface area of the ball(s) you cut out would be equal. BTW, the situation for general spheres in $\mathbb{R}^D$ is fully characterized at stats.stackexchange.com/questions/85916.
– whuber
Jul 5, 2016 at 19:26
• If you were to pick points inside the sphere (not on it), then the cartesian cooridnate distribution would not be uniform. It would be approaching the Gaussian as the number of dimension increases, if you look at the hypersphere rather than a usual 3d sphere Jul 5, 2016 at 19:59
• @Aksakal As the dimension increases, almost all the points inside the sphere grow extremely close to its boundary, so asymptotically the two problems are the same. BTW, in $\mathbb{R}^1$ the points inside the sphere are uniformly distributed.
– whuber
Jul 5, 2016 at 20:39
• @Aksakal Of course it's not uniform! It's uniform only in $\mathbb{R}^1$--but that is a sufficient counterexample to your original statement that it "would not be uniform". If you simply modify my answer to the previously referenced thread,--which in fact is in terms of the stacked disks--you will discover the distribution of x-coordinates within the interior of the unit sphere in $\mathbb{R}^D$ is the same as their distribution on the surface of the unit sphere in $\mathbb{R}^{D+2}$. With $D=1$ we obtain a nice answer to this question.
– whuber
Jul 5, 2016 at 21:03
• @whuber, ok I see that I misunderstood your $R^1$ as the projection of hypersphere to $R^1$ (like in OP's question) while you actually meant the sphere in $R^1$. We're on the same page now Jul 5, 2016 at 21:15

Here's where your intuition fails you: slice the surface into rings of equal width along $x$ axes. Although the width along $x$ is the same $\Delta x$, the width of the surface of each band gradually increases as you move from $x=0$ to $x=1$, because the surface turns from horizontal to vertical. The angle change is just enough to compensate for shorter circumference of the rings closer to the poles.

Here's my crappy diagram. You see how $dx$ is the same, but $AB$ is shorter than $CD$ (because it's at angle to $x$-axis) while $AA'$ is longer than $CC'$. In the end the surface of $AB$ band ends up being the same as $CD$ band. Magic!

Let me know if you want more detail or math. It's easy to show. Also exploring the difference between picking point on a sphere and inside a sphere is very interesting. Try getting the distributions of Cartesians for the latter case.

Here's MATLAB code and plots for these two cases and 3 dimensions.

rng(0,'twister')
rvals = 2*rand(1000,1)-1;
elevation = asin(rvals);

azimuth = 2*pi*rand(1000,1);

[x,y,z] = sph2cart(azimuth,elevation,3);
figure
subplot(2,2,1)
plot3(x,y,z,'.')
axis equal
title 'on sphere'

subplot(2,2,2)
hist(x)
title 'distribution of x on sphere'