|
![](/i/fill.gif) |
"bgimeno" <bgimeno[at]persistencia[dot]org> wrote:
> // ------------------------------------------------------
> #while (Num_Tree<5000)
> #local rnd_tree = seed (Num_Tree);
> object {Tree
> translate x*60 // code A
> rotate <rand(rnd_tree),rand(rnd_tree),rand(rnd_tree)>*360
> }
> #local Num_Tree = Num_Tree +1 ;
> #end
> // ------------------------------------------------------
> #while (Num_Tree<5000)
> #local rnd_tree = seed (Num_Tree);
> object {Tree
> translate y*60 // code B
> rotate <rand(rnd_tree),rand(rnd_tree),rand(rnd_tree)>*360
> }
> #local Num_Tree = Num_Tree +1 ;
> #end
> // ------------------------------------------------------
That isn't really surprising. Keep in mind that rotating by <rand,rand,rand>
doesn't necessarily do what you think it does. It rotates by all three axes in
sequence, x, then y, then z, so if you start with a point ON the x-axis, at
least one rotation won't do anything. And there's certainly no guarantee
they'll be uniformly distributed. In other words, it doesn't mean the code
rotates around a random axis by a random angle, in fact it rotates around three
well-defined axes by random angles.
If you want random points on a sphere, I suggest one of two methods.
1) Use a random point in a box, call it p, and if vlength(p<1) it's inside a
sphere so you can use vnormalize(p) as your random point on the surface. This
is inefficient, but looks something like:
#declare p = <rand(),rand(),rand()>*2-1;
#while( vlength(p)>1 )
#declare p = <rand(),rand(),rand()>*2-1;
#end
#declare p = vnormalize(p);
2) The document I posted a link to has a better answer on p. 19:
r1 = rand()
r2 = rand()
x = 2 cos (2*pi*r1) * sqrt( r2*(1-r2) )
y = 2 sin (2*pi*r1) * sqrt( r2*(1-r2) )
z = 1-2*r2
This is just spherical coordinates, so I think you can rephrase it (according to
the document) as
vrotate( vrotate( y, 180/pi * acos( rand() ) * x ), 360*rand() * y )
I haven't tested this, but I think it would work.
- Ricky
Post a reply to this message
|
![](/i/fill.gif) |