P
pereges
I came across a code that calculates N uniformly distributed points on
the sphere. z is a random number between -1 and 1 and to calculate it
we use drand48 function which returns a uniformly distributed value
between 0 and 1. What I don't understand is how it actually works ?
What does he actually mean by "uniformly distributed values" ?
void SpherePoints(int n, double X[], double Y[], double Z[])
{
int i;
double x, y, z, w, t;
for( i=0; i< n; i++ ) {
z = 2.0 * drand48() - 1.0;
t = 2.0 * M_PI * drand48();
w = sqrt( 1 - z*z );
x = w * cos( t );
y = w * sin( t );
printf("i=%d: x,y,z=\t%10.5lf\t%10.5lf\t%10.5lf\n", i, x,y,z);
X = x; Y = y; Z = z;
}
}
the sphere. z is a random number between -1 and 1 and to calculate it
we use drand48 function which returns a uniformly distributed value
between 0 and 1. What I don't understand is how it actually works ?
What does he actually mean by "uniformly distributed values" ?
void SpherePoints(int n, double X[], double Y[], double Z[])
{
int i;
double x, y, z, w, t;
for( i=0; i< n; i++ ) {
z = 2.0 * drand48() - 1.0;
t = 2.0 * M_PI * drand48();
w = sqrt( 1 - z*z );
x = w * cos( t );
y = w * sin( t );
printf("i=%d: x,y,z=\t%10.5lf\t%10.5lf\t%10.5lf\n", i, x,y,z);
X = x; Y = y; Z = z;
}
}