Sphere Point Picking

DOWNLOAD Mathematica Notebook SphericalDistribution

To pick a random point on the surface of a unit sphere, it is incorrect to select spherical coordinates theta and phi from uniform distributions theta in [0,2pi) and phi in [0,pi], since the area element dOmega=sinphidthetadphi is a function of phi, and hence points picked in this way will be "bunched" near the poles (left figure above).

n random points can be picked on a unit sphere in the Wolfram Language using the function RandomPoint[Sphere[], n].

To obtain points such that any small area on the sphere is expected to contain the same number of points (right figure above), choose U and V to be random variates on (0,1). Then

theta=2piu
(1)
phi=cos^(-1)(2v-1)
(2)

gives the spherical coordinates for a set of points which are uniformly distributed over S^2. This works since the differential element of solid angle is given by

 dOmega=sinphidthetadphi=-dthetad(cosphi).
(3)

The distribution P_phi of polar angles can be found from

 P_phidphi=P_v|(dv)/(dphi)|dphi,
(4)

by taking the derivative of (2) with respect to v to get dphi/dv, solving (2) for v, and plugging the results back in to (4) with P_v=1 to obtain the distribution

 P_phi=1/2sinphi.
(5)
SpherePointPickingUTheta

Similarly, we can pick u=cosphi to be uniformly distributed (so we have du=sinphidphi) and obtain the points

x=sqrt(1-u^2)costheta
(6)
y=sqrt(1-u^2)sintheta
(7)
z=u,
(8)

with theta in [0,2pi) and u in [-1,1], which are also uniformly distributed over S^2.

SpherePointPickingMarsaglia

Marsaglia (1972) derived an elegant method that consists of picking x_1 and x_2 from independent uniform distributions on (-1,1) and rejecting points for which x_1^2+x_2^2>=1. From the remaining points,

x=2x_1sqrt(1-x_1^2-x_2^2)
(9)
y=2x_2sqrt(1-x_1^2-x_2^2)
(10)
z=1-2(x_1^2+x_2^2)
(11)

have a uniform distribution on the surface of a unit sphere. This method can also be extended to hypersphere point picking. The plots above show the distribution of points for 100, 1000, and 5000 initial points (where the counts refer to the number of points before throwing away).

SpherePointPickingCook

Cook (1957) extended a method of von Neumann (1951) to give a simple method of picking points uniformly distributed on the surface of a unit sphere. Pick four numbers x_0, x_1, x_2, and x_3 from a uniform distribution on (-1,1), and reject pairs with

 x_0^2+x_1^2+x_2^2+x_3^2>=1.
(12)

From the remaining points, the rules of quaternion transformation then imply that the points with Cartesian coordinates

x=(2(x_1x_3+x_0x_2))/(x_0^2+x_1^2+x_2^2+x_3^2)
(13)
y=(2(x_2x_3-x_0x_1))/(x_0^2+x_1^2+x_2^2+x_3^2)
(14)
z=(x_0^2+x_3^2-x_1^2-x_2^2)/(x_0^2+x_1^2+x_2^2+x_3^2)
(15)

have the desired distribution (Cook 1957, Marsaglia 1972). The plots above show the distribution of points for 100, 1000, and 5000 initial points (where the counts refers to the number of points before throwing away).

Another easy way to pick a random point on a sphere is to generate three Gaussian random variables x, y, and z. Then the distribution of the vectors

 1/(sqrt(x^2+y^2+z^2))[x; y; z]
(16)

is uniform over the surface S^2 (Muller 1959, Marsaglia 1972).

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.