![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/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) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
> This is not a thread about the disadvantages of the function rand () of
> pov-ray, but a comment on one of its peculiarities.
> In my first post the objects are arranged in a spiral of seven arms through
> (or despite) the pseudorandom function. Now I used the same loop to
> distribute objects around a sphere.
> Code A generates the image with pattern that would correspond to the spiral
> of the first post (Note seven leaves).
>
> Interestingly, code B randomly distributed spheres of the whole area.
>
> B. Gimeno
>
> #include "colors.inc"
> #include "math.inc"
>
> camera {location <0,150,-150>
> look_at <0,0,0>
> }
> light_source {<50,300,-100> colour White}
> light_source {<-150,300,-100> colour White}
>
> #declare Tree = sphere {<0,0,0>2 pigment {White}} ;
>
> #local Num_Tree = 0 ;
> // ------------------------------------------------------
> #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
> // ------------------------------------------------------
>
>
>
In the case "A", you start ON the X axis and your first rotation been
around that axis does nothing. Well, it rotate a sphere on itself and
don't have a visible result. Just redefine Tree as:
cone{-y,2,y,0}//a cone with the same bounding box,
And you'll see the effect of the first rotation. All the trees will lay
flat on the sphere, ther axis tangent to it's "surface".
So, the first rotate is effectively a "throw away"
Net result: ONLY 2 effective rotations.
In the case "B", You start on the Y axis. Now, the first rotation DOES
move the object, then, unless you rotated by exactly 0 or 180, the
second rotation moves the object further. Then, you rotate around the Z
axis.
Net result: 3 successive rotations.
The redefined trees will all point outside.
The same would appens if you started at z*60. All 3 rotations would
affect your final position.
Alain
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Thank you! That is just the detail I missing, although not explain the
pattern of code A nor the spiral of the first image. Thank you
B. Gimeno
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
bgimeno schrieb:
> // ------------------------------------------------------
> #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
With the Tree object being translated to <60,0,0>, the first rotation
about the X axis effectively just rotates the object in place, without
changing its position.
Thus, you only have two random numbers affecting the placement of the
object.
> }
> #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
Here, the object starts at <0,60,0>, so first rotation about the X axis
already "messes up" the object's position.
Thus, in this case you have three random numbers affecting placement.
> }
> #local Num_Tree = Num_Tree +1 ;
> #end
> // ------------------------------------------------------
>
>
>
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
triple_r schrieb:
> If you want random points on a sphere, I suggest one of two methods.
3) use the VRand_On_Sphere macro from rand.inc
(Make sure to copy the macro definition to your code if you use it
frequently - POV-Ray isn't very speedy at executing macros stored in
include files.)
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
I would also add this detail. Although:
sphere {<0,0,0>3
translate x*60
rotate x*rand(rnd_tree)*360
rotate y*rand(rnd_tree)*360
rotate z*rand(rnd_tree)*360
pigment {White}
}
should produce the same result as:
sphere {<0,0,0>3
translate x*60
// rotate x*rand(rnd_tree)*360
rotate y*rand(rnd_tree)*360
rotate z*rand(rnd_tree)*360
pigment {White}
}
the use of this first superfluous rand() affects the values extracted by
the 2nd and 3rd rand(). In this case therefore we obtain values that don't
seem to follow any pattern.
Be recorded as comment on the peculiarities of the rand () function and
nothing else.
B. Gimeno
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Thu, 20 Aug 2009 14:08:55 +0200, "bgimeno" <bgimeno[at]persistencia[dot]org>
wrote:
> the use of this first superfluous rand() affects the values extracted by
>the 2nd and 3rd rand(). In this case therefore we obtain values that don't
>seem to follow any pattern.
>Be recorded as comment on the peculiarities of the rand () function and
>nothing else.
/*
Try this extract of your scene. By commenting out some #declare RotNo2's you
will get different results :)
/*
#include "colors.inc"
camera {location <0,150,-150>
look_at <0,0,0>
}
light_source {<50,300,-100> colour White}
light_source {<-150,300,-100> colour White}
#declare Tree = sphere {<0,0,0>2 pigment {White} } ;
#declare Num_Tree = 0 ;
// ------------------------------------------------------
#while (Num_Tree<5000)
#declare rnd_tree = seed (Num_Tree);
object {Tree
#declare rnd_tree = seed (Num_Tree);
translate x*60 // code C
// Comment out the lines below to get different effects
#declare RotNo2 = rand(rnd_tree);
#declare RotNo2 = rand(rnd_tree);
#declare RotNo2 = rand(rnd_tree);
#declare RotNo2 = rand(rnd_tree);
#declare RotNo2 = rand(rnd_tree);
rotate <0,rand(rnd_tree),rand(rnd_tree)>*360
}
#declare Num_Tree = Num_Tree +1 ;
#end
--
Regards
Stephen
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
> I would also add this detail. Although:
>
> sphere {<0,0,0>3
> translate x*60
> rotate x*rand(rnd_tree)*360
> rotate y*rand(rnd_tree)*360
> rotate z*rand(rnd_tree)*360
> pigment {White}
> }
>
> should produce the same result as:
>
> sphere {<0,0,0>3
> translate x*60
> // rotate x*rand(rnd_tree)*360
> rotate y*rand(rnd_tree)*360
> rotate z*rand(rnd_tree)*360
> pigment {White}
> }
> the use of this first superfluous rand() affects the values extracted by
> the 2nd and 3rd rand(). In this case therefore we obtain values that don't
> seem to follow any pattern.
> Be recorded as comment on the peculiarities of the rand () function and
> nothing else.
>
> B. Gimeno
>
>
This should NOT produce the same result.
Although the first random rotate is effectively a "do nothing", it DOES
fetch a number from the random stream.
If you remove the first rotate, the value it would have used will be
used by the second, now first, rotate.
In the first case, you featch 3 random numbers from the stream for each
iteration.
In the second case, you only featch 2.
Any change in the number of values accessed WILL change the end result.
Just adding one #declare Dummy=rand(rnd_tree); will totaly change the
result.
Alain
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
As a final message of this thread let me show you why this caught my
attention so trivial:
http://www.youtube.com/watch?v=G-2HIMGssfU
This was created in 2005-2006 with an AMD K-6 400Mhz with 128 Mb RAM and
does not seem that I will have time for a substantial improvement
I know, I know, I know. Improve the lighting, background and approach of the
camera. Any suggestions more?
B. Gimeno
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Thu, 20 Aug 2009 23:06:51 +0200, "bgimeno" <bgimeno[at]persistencia[dot]org>
wrote:
>As a final message of this thread let me show you why this caught my
>attention so trivial:
>
That's neat and it's Alexander's ragtime Band :)
--
Regards
Stephen
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |