

SharkD <mik### [at] gmailcom> wrote:
> Is there a good way to, for instance, place a number of trees randomly
> without having them overlap?
>
> Currently, I use an array to store the positions and compare each new
> tree to all the previous ones. This is however very slow.
I'd start with a halton sequence (I find myself using them everywhere...) and
seeing if it does a better job of not overlapping the trees:
#macro halton( index, base )
#local out = 0.0;
#local fraction = 1.0 / base;
#local i = index;
#while( i > 0 )
#local remainder = mod( i, base );
#local out = out + (fraction * remainder);
#local i = int(i / base);
#local fraction = fraction / base;
#end
out
#end
#macro halton2D( n )
#local baseX = 2;
#local baseY = 3;
< halton( n, baseX ), halton( n, baseY ), halton( n, baseZ ) >
#end
You additionally take the values returned by the halton2D() macro, and test them
against a pigment function to decide whether to place a tree  this would give
you nonoverlapping randomness on the small scale, and some clumping of trees on
the larger scale. My guess is that that would look quite natural, but you'd have
to give it a try to find out.
Cheers,
Edouard.
Post a reply to this message

