POV-Ray : Newsgroups : povray.text.scene-files : random points on a sphere Server Time
31 Oct 2024 23:27:24 EDT (-0400)
  random points on a sphere (Message 1 to 1 of 1)  
From: nospam
Subject: random points on a sphere
Date: 21 Oct 2002 21:03:03
Message: <3db46b41.18804008@localhost>
/* random distribution of points on a sphere without
   clumping at poles
*/


#version 3.5;
#declare number_of_points = 3000;
#declare rseed = seed(75082868);


global_settings {
  assumed_gamma 2.2
  number_of_waves 11
}


camera {
  location 0
  direction <0, 0, 1.0>
  right <image_width / image_height, 0, 0>
  up <0, 1, 0>
  translate <0, 0, -10>
}


// in an attempt to randomly place objects "evenly" on
// a sphere we use the sine of the elivation to determine
// the probability of a point actually being plotted.  This
// way we prevent the problem of the clumping at the poles.
#declare xx = 0;
#while (xx < number_of_points)
  #declare eliv = (pi * 0.5) * rand(rseed); // elivation in radians
  #declare dummy = rand(rseed);
  #declare dummy = rand(rseed);
  #if (rand(rseed) < cos(eliv))   // cos is 1 at 0 deg., 0 at 90 deg.
    sphere {
      <0, 0, 0>, 0.05        // create point
      translate <-4, 0, 0>  // move point by radius of sphere
      #if (rand(rseed) > 0.5) // N or S hemisphere
        rotate z*-180*(eliv / pi)  // rotate point towards the pole
      #else
        rotate z*180*(eliv / pi)  // rotate point towards the pole
      #end
      #declare dummy = rand(rseed);
      rotate y*360*rand(rseed)
      #declare dummy = rand(rseed);
      pigment { color red 1 green 0.5 blue 0 }
      finish { ambient 0.4 diffuse 0.6 specular 1 roughness 0.05 }
    }
    #declare xx = xx + 1;
  #end
#end


union {
  sphere {
    0, 4
    pigment { color rgb 0.8 }
    finish { ambient 0.2 diffuse 0.8 }
  }
  // grid lines on sphere
  union {
    #declare roty = 0;
    #while (roty < 360)
      #declare roty = roty + (360 / 24);
      torus { 4, 0.01 rotate x*90 rotate y*roty }
    #end
    #declare eliv = 0;
    #while (eliv < 89)
      torus {
        4*cos(radians(eliv)), 0.01
        translate <0, 4*sin(radians(eliv)), 0>
      }
      #if (eliv > 1)
        torus {
          4*cos(radians(eliv)), 0.01
          translate <0, -4*sin(radians(eliv)), 0>
        }
      #end
      #declare eliv = eliv + (90 / 6);
    #end
    pigment { color rgb 0 }
    finish { ambient 0 diffuse 1 specular 1.4 roughness 0.04 }
  }
  rotate x*-50
  rotate y*9
}


light_source {
  <-3100, 2000, -2000>
  color rgb <0.45, 0.5, 0.55>
}
light_source {
  <2500, 2010, -960>
  color rgb <0.55, 0.5, 0.45>
}


/* actual end of this file */


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.