POV-Ray : Newsgroups : povray.off-topic : Random vector through a hemisphere? : Re: Random vector through a hemisphere? Server Time
12 Jul 2025 11:05:17 EDT (-0400)
  Re: Random vector through a hemisphere?  
From: Severi Salminen
Date: 18 Feb 2008 03:38:27
Message: <47b94403@news.povray.org>
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?


Post a reply to this message

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