The Math Forum

Ask Dr. Math - Questions and Answers from our Archives
Associated Topics || Dr. Math Home || Search Dr. Math

Uniform Distribution of Random Points on a Sphere

Date: 07/14/2005 at 12:54:23
From: Pradip
Subject: random points on a sphere with uniform distribution

Is there a method to pick random points on a sphere which are 
uniformly distributed on the sphere? 

I've tried it by selecting theta between 0 and pi and phi between 0 
and 2*pi, but I get a higher density of points near the poles.

Date: 07/15/2005 at 07:05:05
From: Doctor George
Subject: Re: random points on a sphere with uniform distribution

Hi Pradip,

Thanks for writing to Doctor Math.  You are on the right track with
wanting to select angles.  I may be using different angle conventions
than you are, so check carefully.

The surface area of a sphere is 4*pi*r^2, so the probability density
function for uniform density over a sphere is

   1 / (4*pi*r^2)

This does not really help us generate a random variable because it
does not tell us what to do with x, y and z.  We know that we want
x^2 + y^2 + z^2 = r^2, so transforming to spherical coordinates (rho,
phi, theta) looks like a helpful thing to do.

Letting 0 <= phi < pi, 0 <= theta < 2*pi, we have

  x = rho sin(phi) cos(theta)
  y = rho sin(phi) sin(theta)
  z = rho cos(phi)

We need to use standard transformation techniques on the cummulative
density function, like this.

  Int{Int{Int{1/(4*pi*r^2) dxdydz}}}
  Int{Int{Int{1/(4*pi*r^2) rho^2 sin(phi) d(rho)d(phi)d(theta)}}}

Now factor the integrand to generate independent densities


This leaves us with

  f(theta) = 1/(2*pi)
  f(phi) = sin(phi)/2
  f(rho) = rho^2 / r^2

Since we are integrating over the surface

  rho = r
  f(rho) = 1

Now we just need to randomly generate theta and phi from their 
cumulative densities.

  F(theta) = theta / (2*pi)
  F(phi) = [1 - cos(phi)] / 2

Let u1 = F(theta) and u2 = F(phi) be independent uniform random 
variates on [0,1).  If we solve for theta and phi we get

  theta = 2*pi*u1
  phi = acos(1 - 2*u2)

Now use these random variates to generate x, y and z.

Does that make sense?  Please let me know how this works for you.
Write again if you need more help.

- Doctor George, The Math Forum 
Associated Topics:
College Higher-Dimensional Geometry

Search the Dr. Math Library:

Find items containing (put spaces between keywords):
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.