POV-Ray : Newsgroups : povray.general : Slightly faster VRand_On/In_Sphere() : Re: Slightly faster VRand_On/In_Sphere() Server Time
4 Nov 2024 17:32:00 EST (-0500)
  Re: Slightly faster VRand_On/In_Sphere()  
From: Wolfgang Wieser
Date: 7 Nov 2003 15:35:36
Message: <3fac0217@news.povray.org>
JC (Exether) wrote:

> 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. 
> :-)
> 
Well... I just posted an article until it popped up in my mind that 
it was complete nonsense, so I canceled it again (hope that helps...)
Furthermore (as non-native speaker) I mixed up longitude and latitude 
again -- @#$%!!!

I had to take pencil and paper and have a closer look: 

>> 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
>
Okay, so the area size on a sphere between latitudes theta1 and theta2 
is (where theta is not really the latitude but measured downwards from 
the pole): 
  integral theta1..theta2 over 2*pi*sin(theta) d(theta)
which is
  area = 2*pi*(cos(theta1)-cos(theta2))

The probability for the vector to be inside that area is: 
  P(v in area) = P(cos(theta2)<= y < cos(theta1))
where y=2*rand(Stream)-1, i.e. uniformly distributed, so 
  P = ( cos(theta1)-cos(theta2) )/2

Now, if the probability is proportional to the area, the distribution 
is uniform. Looking at the formulas, this is evident: 
  P/area = 1/(4*pi)
...which is just what we expect and independent of theta1 and theta2. 

So I think that it really works. 

Cheers,
Wolfgang


Post a reply to this message

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