> 1. Is this equally good as the above - at least it looks to be. And a
> bit faster.
>
> double y = sqrt((double) rand()/RAND_MAX);
> double phi = 2*M_PI* (double)rand()/RAND_MAX;
> double x = sqrt(1-y*y)*cos(phi);
> double z = sqrt(1-y*y)*sin(phi);
Looks ok to me.
> What is the proper way to actually test the uniformity?
Either mathematically proving it, or write a test program that measures the
density of points over the surface.
> I also tried that:
>
>
> do{
> x = (double) 2.0*rand()/RAND_MAX -1.0;
> z = (double) 2.0*rand()/RAND_MAX-1.0;
> }
> while(x*x+z*z > 1.0);
>
> y = sqrt(1.0-(x*x+z*z));
>
> And the results are very close to the 2 other methods.
This result is different to the above and not spread uniformly over the
surface of the sphere (it is uniform only in the xz plane).
Post a reply to this message
|