POV-Ray : Newsgroups : povray.general : Slightly faster VRand_On/In_Sphere() : Re: Slightly faster VRand_On/In_Sphere() Server Time
3 Aug 2024 20:18:30 EDT (-0400)
  Re: Slightly faster VRand_On/In_Sphere()  
From: JC (Exether)
Date: 7 Nov 2003 09:56:27
Message: <3fabb29b@news.povray.org>
Well, after understanding the message and going into its math a bit 
more, I came to following conclusions.

I think we can agree that if Frank's VRand_On_Sphere is uniform on the 
sphere then VRand_In_Sphere is uniform within the sphere.

So I considered VRand_On_Sphere which is a bit easier.
First remark I made is that the repartition is not obviously uniform.  :-)

What seem to happen here is that we have a combination of two 
non-uniform transformations that may lead to a uniform repartition.

<sqrt(1-Y*Y), Y, 0> is non uniform in terms of length of the circle, 
there will be more points in the middle of the circle and less at the 
top and bottom, but then the rotation is not uniform either as it will 
spread the points of the top and bottom on smaller surfaces.

The remaining question is : does the one exactly counter the other ?

I haven't answered this one yet, and I would really like to avoid doing 
it with my rusty math, isn't any math student around willing to do it ?? 
There's just a few arcos integrals and stuff like that implied I think.  :-)

JC


> 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.