POV-Ray : Newsgroups : povray.newusers : trace function question : Re: trace function question Server Time
29 Jul 2024 02:29:42 EDT (-0400)
  Re: trace function question  
From: Chris B
Date: 17 Jan 2007 05:41:58
Message: <45adfd76$1@news.povray.org>
"serfurj" <nomail@nomail> wrote in message 
news:web.45adc1ac1c5723b375f97caf0@news.povray.org...
> Jim Charter <jrc### [at] msncom> wrote:
>> serfurj wrote:
>> > Hi, I'm trying to make the following script place the cylinders evenly 
>> > on
>> > the sphere, but they're showing up clustered.  Any idea why?  How can I
>> > place them evenly on the sphere?
>> > ...
>> > #declare Start = <rand(R1), rand(R1), rand(R1)>;
>>

This creates a random distribution of points in a space within a cube from 
<0,0,0> to <1,1,1>. Some of those points will be inside a sphere of radius 1 
centred at the origin and some will be outside. With the trace function you 
used, the starting points outside the sphere would hit the surface of the 
sphere in the +X, +Y, +Z quadrant and those inside the sphere would strike 
the opposite side of the sphere (-X,-Y,-Z).

If you scale your start points up and displace them (rand(R1)*2-1), you get 
a random distribution within a cube <-1,-1,-1> to <1,1,1>, which would be 
closer to what you want, but would still not map to the surface of the 
sphere in a uniform way, because you get more points on the sphere where you 
have the edges (and particularly the corners) of the box and less towards 
the centre of the boxes surface.

>>
>> You might get to adequately even results most quickly by using the
>> "vrotate" function
>>
>> ie #local Start = vrotate ( <0,0,-2>, <rand(S)*360,rand(S)*360,0> )
>> *remember that the triplet specifying the rotation is in degrees
>>

This will give you a distribution a bit like the lines of longitude and 
latitude on a globe with a greater density at the poles than around the 
equator. This is because the x rotation is uniform, so you get as many 
points at a latitude of 80 degrees (clustered around a small circle) as you 
would at the equator (a larger circle).

>
> Not sure I understand it yet, but that was what I was looking for.  Thanks
> for the help!
>

If you want a uniform distribution you probably want   #declare Start = 
vrotate ( <0,0,-2>, <asind(rand(R1)*2-1),rand(R1)*360,0> );
This compensates by adjusting the distribution of the random numbers used 
for the x rotation, providing more points in the middle (xRotation=0) and 
less as you reach the extremes (xRotation=90 and xRotation= -90). It does 
this by taking the arcsin of a random number between -1 and 1.

Regards,
Chris B.


Post a reply to this message

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