POV-Ray : Newsgroups : povray.general : Slightly faster VRand_On/In_Sphere() : Slightly faster VRand_On/In_Sphere() Server Time
4 Nov 2024 17:37:39 EST (-0500)
  Slightly faster VRand_On/In_Sphere()  
From:
Date: 6 Nov 2003 01:56:34
Message: <3fa9f0a2$1@news.povray.org>
The following macro gives an uniform distribution within the sphere{0,1}
and is slightly faster (by 9%) than VRand_In_Sphere() from rand.inc:

#macro VRand_In_Sphere(Stream)
  #local Y = 2*rand(Stream)-1;
  vrotate ( (<sqrt(1-Y*Y),Y,0>*pow(rand(Stream),1/3)), 360*rand(Stream)*y )
#end


And this macro gives an uniform distribution on the surface of the
sphere{0,1}. It's slightly faster than VRand_On_Sphere() from rand.inc:

#macro VRand_On_Sphere(Stream)
  #local Y = 2*rand(Stream)-1;
  vrotate ( <sqrt(1-Y*Y), Y, 0>, 360*rand(Stream)*y )
#end


I suggest to replace the original rand.inc macros by these macros.

   Sputnik


Post a reply to this message

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