Advertisement
Archon

Random points on sphere

Feb 20th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. //randomize vectors
  2. const double range = 1.;
  3. for (int i = 0; i != NUM_VECTORS; ++i){
  4.    D3 &v = vectors[i];
  5.    double x;
  6.    do{
  7.       x = v.x = 2*range * rand() / RAND_MAX - range;
  8.       v.y = 2*range * rand() / RAND_MAX - range;
  9.       v.z = 2*range * rand() / RAND_MAX - range;
  10.       normalize(v);
  11.    }while(x/v.x > 1);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement