POV-Ray : Newsgroups : povray.off-topic : Random vector through a hemisphere? : Re: Random vector through a hemisphere? Server Time
11 Oct 2024 03:17:53 EDT (-0400)
  Re: Random vector through a hemisphere?  
From: John VanSickle
Date: 18 Feb 2008 17:36:46
Message: <47ba087e@news.povray.org>
Severi Salminen wrote:
> scott wrote:
>>> Another way is to generate a random vector:
>>>
>>> #local vResult=vrotate(x,<rand(Seed),rand(Seed),rand(Seed)>*360);
>> vResult is not uniformly distributed over the sphere with this approach
>> though...
> 
> I use this:
> 
> y = sqrt(rand(0..1))
> theta = acos(y)
> phi = 2*PI*rand(0..1)
> 
> x = sin(theta)*cos(phi)
> z = sin(theta)*sin(phi)
> 
> What I don't get is the sqrt(rand()). Why sqrt? Why not just rnd()? Does
> the sqrt give us the cosine distribution and should remove the need to
> later scale by taking cosine of the angle between normal and the light ray?

Actually, a plain rand() should work fine.  I did the calculus.

y = rand(0..1)
s = sqrt(1-y*y)
phi = 2*PI*rand(0..1)
x = s*cos(phi)
z = s*sin(phi)

Regards,
John


Post a reply to this message

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