
Boost : 
From: Jeffrey Faust (jefffaust_at_[hidden])
Date: 20070605 17:17:46
Lewis Hyatt wrote:
> Henrik Sundberg wrote:
>
>> I doubt that the trigversion gives a good distribution:
>>
>> inlineVectortrig(uniform_01<generator_type>&random) {
>> constfloatphi=2*M_PI*random();
>> constfloatcos_theta=2*random()1;
>> constfloatsin_theta=sqrt(1cos_theta*cos_theta);
>> returnVector(cos_theta,sin_theta*cos(phi),sin_theta *sin(phi));
>> }
>>
>> The result ought to be more dense at the poles.
>>
>
> The posted trig method is correct, it chooses a horizontal cutting plane
> uniformly. You can show that the surface area of a sphere contained
> between two zcoordinates only depends on the difference between the two
> coordinates, not their location, so this generates the correct distribution.
>
> However, the "naive" method is incorrect, the resulting points are not
> uniformly distributed over the sphere. The correct version of the
> "naive" method is given here:
> http://mathworld.wolfram.com/SpherePointPicking.html
>
> Lewis
>
> _______________________________________________
>
Also see here for a discussion for 4 different techniques (and a proof
for the trig version!):
http://www.math.niu.edu/~rusin/knownmath/96/sph.rand
Jeff Faust
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk