POV-Ray : Newsgroups : povray.binaries.images : seven arms Server Time
31 Jul 2024 16:22:45 EDT (-0400)
  seven arms (Message 1 to 10 of 20)  
Goto Latest 10 Messages Next 10 Messages >>>
From: bgimeno
Subject: seven arms
Date: 15 Aug 2009 03:04:04
Message: <4a865de4@news.povray.org>
While experimenting with the function rand () to simulate a random 
distribution of trees, (moving object at a random distance from origin and 
then doing it orbit on the y-axis, when I found this.
I've noticed a pattern when attempting to distribute objects on a square 
grid. But why this circular distribution?

Does anyone know why there are 7 arms and not 5 or 13 or something more 
random?


#include "colors.inc"
#include "math.inc"
camera {location <0,20,-30>
        look_at <0,0,0>
       }
light_source {<50,100,-10> colour White}

plane {y,0
      texture {
             pigment {checker colour White colour Orange}
             }
      }


#declare Tree =
union {cylinder {<0,0,0>,<0,1,0>,.1 pigment {Red}}
           sphere {<0,1,0>.4 pigment {Green}}
          }

#local Num_Tree = 0 ;
#while (Num_Tree<1000)
  #local rnd_tree = seed (Num_Tree);
  #if (rand (rnd_tree)<.95 )
    object {Tree
            translate <50*rand(rnd_tree),0,0>
            rotate y*360*rand(rnd_tree)
            }
   #end
  #local Num_Tree = Num_Tree +1 ;
#end


pd. I found it while editing the code to upload the image. The key is in the 
use of the same rand value to control the density of generating objects. But 
interesting anyway.
pd2 google searchs results: "the seven arms of Shiva", "the seven arms of 
the Menorah", "an Octopus with only seven arms"...
B. Gimeno


Post a reply to this message


Attachments:
Download 'random_trees.jpg' (98 KB)

Preview of image 'random_trees.jpg'
random_trees.jpg


 

From: Chris B
Subject: Re: seven arms
Date: 15 Aug 2009 06:05:45
Message: <4a868879$1@news.povray.org>
"bgimeno" <bgimeno[at]persistencia[dot]org> wrote in message 
news:4a865de4@news.povray.org...
> While experimenting with the function rand () to simulate a random 
> distribution of trees, (moving object at a random distance from origin and 
> then doing it orbit on the y-axis, when I found this.
> I've noticed a pattern when attempting to distribute objects on a square 
> grid. But why this circular distribution?
>
> ... snip ...
>
> #local Num_Tree = 0 ;
> #while (Num_Tree<1000)
>  #local rnd_tree = seed (Num_Tree);
>  #if (rand (rnd_tree)<.95 )
>    object {Tree
>            translate <50*rand(rnd_tree),0,0>
>            rotate y*360*rand(rnd_tree)
>            }
>   #end
>  #local Num_Tree = Num_Tree +1 ;
> #end
>
>
> pd. I found it while editing the code to upload the image. The key is in 
> the use of the same rand value to control the density of generating 
> objects. But interesting anyway.
> pd2 google searchs results: "the seven arms of Shiva", "the seven arms of 
> the Menorah", "an Octopus with only seven arms"...
>

Take your pick:
Answer A: Yes it's controlled by ancient deities.
Answer B: You're using the seed function wrong.

Answer B continued:
Because the seed function is being called from within the #while loop you 
are simply stepping sequentially through the seeds rather than taking 
successive numbers from a random number stream. If you move the seed 
definition outside the loop and use a single number as the seed you should 
avoid this problem ie use:
#local rnd_tree = seed (0);
and move it so that it's set before starting the #while loop.

This characteristic of the seed/rand functions was discussed in some detail 
in a long thread quite a while ago:
http://news.povray.org/povray.binaries.images/thread/%3Cweb.4a0d5729a7098c1c34d207310@news.povray.org%3E/
I don't remember seeing anything there that explains what it is that will 
give you 7 arms rather than a different number of arms, so this is maybe 
where Answer A and Answer B mysteriously come together.

The other thing to note is that even when you fix this, your algorithm still 
gives a cluster at the centre of the circle, but the reason for this is 
categorically mathematical :o)

Regards,
Chris B.


Post a reply to this message

From: triple r
Subject: Re: seven arms
Date: 15 Aug 2009 10:45:01
Message: <web.4a86c937fa341737958421d50@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> The other thing to note is that even when you fix this, your algorithm still
> gives a cluster at the centre of the circle, but the reason for this is
> categorically mathematical :o)

This document has a couple solutions, right around pages 12-13 (not to mention a
lot of other useful stuff!):

http://www.cs.kuleuven.be/~phil/GI/

In short, to get around the problem use a random angle and a random radius, but
take the square root of the radius before you use it, i.e.:

translate <50*sqrt(rand(rnd_tree)),0,0>

 - Ricky


Post a reply to this message

From: Warp
Subject: Re: seven arms
Date: 15 Aug 2009 12:26:06
Message: <4a86e19e$1@news.povray.org>
triple_r wrote:
> In short, to get around the problem use a random angle and a random radius, but
> take the square root of the radius before you use it, i.e.:
> 
> translate <50*sqrt(rand(rnd_tree)),0,0>

  To some it might sound that the square root "trick" is completely
arbitrary and that it just happens to give "close enough" results to be
acceptably believable.

  However, the fact is that the square root is the mathematically exact
solution to the problem. The reason is simple: The density of the
elements does indeed change by (exactly) the square of the distance from
the center, and thus to counter that you take the square root, in which
case you get an even distribution along the whole surface.


Post a reply to this message

From: Reactor
Subject: Re: seven arms
Date: 15 Aug 2009 14:55:00
Message: <web.4a870387fa341737fb6da2e10@news.povray.org>
"bgimeno" <bgimeno[at]persistencia[dot]org> wrote:
> While experimenting with the function rand () to simulate a random
> distribution of trees...

> #local Num_Tree = 0 ;
> #while (Num_Tree<1000)
>   #local rnd_tree = seed (Num_Tree);
>   #if (rand (rnd_tree)<.95 )
>     object {Tree
>             translate <50*rand(rnd_tree),0,0>
>             rotate y*360*rand(rnd_tree)
>             }
>    #end
>   #local Num_Tree = Num_Tree +1 ;
> #end
>


I don't understand the reason for this line, as it doesn't really do anything:
>   #if (rand (rnd_tree)<.95 )

The only effect is throw the count of trees off, since it pulls a number from
the stream, compares it, either places a tree or doesn't, but updates the
counter regardless.

-Reactor


Post a reply to this message

From: bgimeno
Subject: Re: seven arms
Date: 15 Aug 2009 15:30:19
Message: <4a870ccb$1@news.povray.org>

news:web.4a870387fa341737fb6da2e10@news.povray.org...
> I don't understand the reason for this line, as it doesn't really do 
> anything:
>>   #if (rand (rnd_tree)<.95 )
>
> The only effect is throw the count of trees off, since it pulls a number 
> from
> the stream, compares it, either places a tree or doesn't, but updates the
> counter regardless.
>
> -Reactor

Certainly not, at least in this image. But I usually use this trick (with 
other values) in scenes where I use a condition for the random generation of 
objects

B. Gimeno


Post a reply to this message

From: Warp
Subject: Re: seven arms
Date: 16 Aug 2009 07:29:22
Message: <4a87ed92$1@news.povray.org>
Reactor wrote:
> I don't understand the reason for this line, as it doesn't really do anything:
>>   #if (rand (rnd_tree)<.95 )
> 
> The only effect is throw the count of trees off, since it pulls a number from
> the stream, compares it, either places a tree or doesn't, but updates the
> counter regardless.

  Rather than placing exactly 1000 trees, it places a bit less.

  Of course you are right in that if what he wants is to place less than
1000 trees, then why not use a number which is less than 1000 to begin
with? The number of trees will always be the same from render to render
regardless of whether it's done with that #if or with a direct value
less than 1000.


Post a reply to this message

From: bgimeno
Subject: Re: seven arms (57 Kb)
Date: 19 Aug 2009 01:18:27
Message: <4a8b8b23@news.povray.org>
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
// ------------------------------------------------------


Post a reply to this message


Attachments:
Download 'random_test.jpg' (57 KB)

Preview of image 'random_test.jpg'
random_test.jpg


 

From: Thomas de Groot
Subject: Re: seven arms (57 Kb)
Date: 19 Aug 2009 04:00:51
Message: <4a8bb133$1@news.povray.org>
That's curious! I had not expected that. Any idea why?

Thomas


Post a reply to this message

From: Stephen
Subject: Re: seven arms (57 Kb)
Date: 19 Aug 2009 05:14:11
Message: <6ign85ld0t8q0tb8iumlo7bsope2jq3t5j@4ax.com>
On Wed, 19 Aug 2009 10:00:52 +0200, "Thomas de Groot"
<tDOTdegroot@interDOTnlANOTHERDOTnet> wrote:

>That's curious! I had not expected that. Any idea why?
>

Not an answer but it could be a hint.
If you split the rotate *360 into separate rotate x, rotate y, rotate z and
order them separately then adding the translation to the first rotate gives a
similar result. 


#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}} ;


#local Num_Tree = 0 ;       

// ------------------------------------------------------
#while (Num_Tree<5000)
  #local rnd_tree = seed (Num_Tree);
  object {Tree
          translate y*60       // code C 
                   
          
          rotate rand(rnd_tree) *y*360
          
          rotate rand(rnd_tree) *z*360  
          
          rotate rand(rnd_tree) *x*360
          
          }
  #local Num_Tree = Num_Tree +1 ;
#end


-- 

Regards
     Stephen


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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