POV-Ray : Newsgroups : povray.advanced-users : Random tree position, without duplicates? : Re: Random tree position, without duplicates? Server Time: 28 Sep 2020 22:47:09 GMT
 Re: Random tree position, without duplicates?
 From: Edouard Date: 5 Jun 2010 21:10:01
```Jim Charter <jrc### [at] msncom> wrote:
> Edouard wrote:
> > SharkD <mik### [at] gmailcom> wrote:
> >> On 6/4/2010 5:31 PM, Edouard wrote:
> >>> "Edouard"<pov### [at] edouardinfo>  wrote:
> >>>
> >>> Opps - I mean:
> >>>
> >>> #macro halton2D( n )
> >>>   #local baseX = 2;
> >>>   #local baseY = 3;
> >>>
> >>>   <  halton( n, baseX ), halton( n, baseY ), 0>
> >>> #end
> >>
> >> Could you provide an example of how to use it? Thanks.
> >
> > I'll try!
> >
> > The halton macro returns a number from 0..1, and halton2D() returns a vector
> > where the X is 0..1, Y is 0..1 and the Z = 0.
> >
> > You call halton2D() with an incrementing integer, so it works best in a loop.
> >
> > If you had a macro called PlaceTree(), you could loop through values from
> > halton2D calling the tree macro like this:
> >
> > #declare n = 1;
> > #while( n < number_of_trees_wanted )
> >   #declare position = halton2D( n );
> >   // position is <0..1, 0..1, 0> - scale the vector here
> >   // to the size you need for PlaceTree
> >   PlaceTree( position )
> >   #declare n = n + 1;
> > #end
> >
> > Does my explanation make sense?
> >
> > Cheers,
> > Edouard.
> >
> >
> This is very useful! I see that the increasing integer eliminates the
> overlap of points.  Is there a relationship between the size of the
> object and the size of the increment that can be used to prevent
> objects intersecting?

Unfortunately not - all it does is generate numbers that have a distribution
that looks random, but have the property that they don't clump together. As you
generate more numbers, each new item fills a position that was empty, and as you
generate more and more numbers in the sequence, space gets filled denser and
denser.

If your objects aren't too closely packed, a halton sequence is a very easy
replacement for rand(), and may work well. I posted it mainly because it should
be very easy to try out for the problem described.

Cheers,
Edouard.
```