POV-Ray : Newsgroups : povray.advanced-users : Random tree position, without duplicates? : Re: Random tree position, without duplicates? Server Time
3 Jul 2025 04:01:36 EDT (-0400)
  Re: Random tree position, without duplicates?  
From: Edouard
Date: 4 Jun 2010 17:30:00
Message: <web.4c096fec295829f03694f4200@news.povray.org>
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 non-overlapping 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

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