[In this reprinted #altdevblogaday in-depth piece, Crytek's technical lead Jaewon Jung shares what he believes is the ideal way for generating uniformly distributed points on a sphere.]
Recently, while I was working on a screen-space shader effect, I had to do some random sampling over the surface of a sphere. An effective sampling requires a uniform distribution of samples.
After a quick Googling, I found out a way to generate uniformly distributed samples [1], and it showed a decent result for my application. But, still unsure if that was an ideal way, I performed due research about it later. Following is the result of that short research.
Usually, in graphics application, one can limit it to the three-dimensional space. In that case, there are four possible approaches, all of which guarantee a uniform distribution (by the way, as for what the 'uniform distribution' exactly means, [6] has some explanations). If n-dimension support is required, one is out, so three remain. Let's take stock of each.
Rejection sampling ([2][4][5])
One simple way is something called 'rejection sampling'. For each x, y, z coordinates, choose a random value of a uniform distribution between [-1, 1]. If the length of the resulting vector is greater than one, reject it and try again.
Obviously, this method can be generalized to n-dimension. But the bigger the dimension gets, the higher the rejection rate gets, so the less efficient the technique becomes.
Normal deviate ([2][5])
This technique chooses x, y and z from a normal distribution of mean 0 and variance 1. Then normalize the resulting vector and that's it. [2] shows why this method can generate a uniform distribution over a sphere. In short,
500 points by rejection sampling
500 points by normal deviate
500 points by trigonometry method
500 points by coordinate approach
By the way, all of the images above were plotted by Winplot.
TL;DR
Just use the trigonometry method above and add a stratified sampling, if necessary. That'll be enough for the most of cases. ;)
References
as [5] explains. This also generalizes to n-dimension without a hassle. Trigonometry method ([1][3][4][5]) This one works only for a three-dimensional sphere(called 2-sphere in literatures, which means it has two degrees of freedom), but is an easiest one to intuitively grab how it works. [1] nicely explains why it works from Archimedes' theorem:
It works because the vector chosen (before normalization) has a density that depends only on the distance from the origin.
The exact steps are as below:
The area of a sphere equals the area of every right circular cylinder circumscribed about the sphere excluding the bases.
- Choose z uniformly distributed in [-1,1].
- Choose t uniformly distributed on [0, 2*pi).
- Let r = sqrt(1-z^2).
- Let x = r * cos(t).
- Let y = r * sin(t).




- http://repository.upenn.edu/cgi/viewcontent.cgi?article=1188&context=cis_reports
- http://www-alg.ist.hokudai.ac.jp/~jan/randsphere.pdf
- http://mathworld.wolfram.com/SpherePointPicking.html
- http://cgafaq.info/wiki/Uniform_random_points_on_sphere
- http://www.math.niu.edu/~rusin/known-math/96/sph.rand
- http://www.math.niu.edu/~rusin/known-math/95/sphere.faq