[Numpy-discussion] Even Sphere Volume
Stéfan van der Walt
stefan at sun.ac.za
Sun Jul 5 19:40:55 EDT 2009
2009/7/5 Ian Mallett <geometrian at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: random_sphere.py
Type: application/octet-stream
Size: 436 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090706/94f4385f/attachment.obj>
More information about the NumPy-Discussion
mailing list