[Numpy-discussion] Even Sphere Volume
Stéfan van der Walt
Sun Jul 5 18:40:55 CDT 2009
2009/7/5 Ian Mallett <firstname.lastname@example.org>:
> @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:
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 435 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090706/94f4385f/attachment-0001.obj
More information about the NumPy-Discussion