SHARE
TWEET

Random points on sphere

Archon Feb 20th, 2012 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top