2009/7/5 Ian Mallett <geometr...@gmail.com>:
> @Stéfan: I thought of the first method.  Let's hear the second approach.

Please see the attached example.

I start off by drawing random azimuth and elevation angles, as well as a radii:

N = 1000
max_radius = 5

az = np.random.uniform(low=0, high=np.pi * 2, size=N)
el = np.random.uniform(low=0, high=np.pi, size=N)
r = np.random.uniform(size=N)

You can imagine your volume consisting of a large number of concentric
spherical surfaces (almost like those Russian nested dolls).  We'd
like to have all of those surfaces equally densely packed, but their
surfaces increase in area by the third power with radius.  To counter
this effect we do

r = r ** (1/3.)

Now, imagine the elevation contours (like latitude on the earth) for
one of those spherical surfaces.  If we choose them equally spaced,
we'll have a much higher concentration of points near the north and
south poles.  Instead, we choose them according to

el = np.arccos(1 - 2*el)

so that we have more contours close to the equator (where the contours
are longer and  need more points).

>From a statistical point of view, the derivation is done using
transformation of random variables:

http://en.wikipedia.org/wiki/Probability_integral_transform
http://en.wikipedia.org/wiki/Inverse_transform_sampling

Regards
Stéfan

Attachment: random_sphere.py
Description: Binary data

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to