POV-Ray : Newsgroups : povray.general : how to prevent overlapping random objects? : Re: how to prevent overlapping random objects? Server Time
26 Sep 2024 17:44:49 EDT (-0400)
  Re: how to prevent overlapping random objects?  
From: Alain
Date: 15 Aug 2010 18:06:00
Message: <4c6864c8$1@news.povray.org>

> Hi,
> I created a bunch of cylinders with a while loop and the rand() function.
> But some of the cylinders are overlapping like in this picture:
> http://alien23.de/test4/cylinders.jpg
>
> The code I used was this:
>
> #declare  zufall_1= seed (1199);
> #declare  zufall_2= seed (342);
>
> #declare ab=.09;  /// abstand
>
> #declare Loop_x =0;
>
> #declare Loop_x_end =9;
>
> union {
> #while (Loop_x<  Loop_x_end)
>          #declare Loop_y =0;
>          #declare Loop_y_end =9;
>          #while (Loop_y<  Loop_y_end)
>
>   #if (even (Loop_y))
>                  object { cyl  translate
> <-.08+Loop_x*ab+rand(zufall_1)/15+Loop_x*.05 ,
> Loop_y*ab+rand(zufall_1)/15+Loop_y*.035 , 0>    }
>
>             #else
>                object { cyl  translate<.1+Loop_x*ab-rand(zufall_1)/1+Loop_x*.05
> , Loop_y*ab+rand(zufall_1)/16+Loop_y*.025 , 0>  }
>             #end
>
>          #declare Loop_y=Loop_y+1;
>          #end
>
> #declare Loop_x=Loop_x+1;
> #end
> }
>
> ------------------------------------------------------
> By now I've spent hours trying out other values for the cylinders' translation.
> But when I use other values together with rand() I can prevent the cylinders
> from overlapping but then everything looks too orderly.
>
> So I basically want the bunch of cylinders to look like in the picture just
> without the 4 or 5 overlapping cylinders.
>
> I know it might work with the trace function to check whether they overlap and
> so I read through Jonathan Hunt's pebbles.pov where he uses this.
> But I found it very difficult and I don't know how too adapt the trace function
> to my scene.
>
> Or maybe it is possible to put all the translation data into an output file, and
> manually edit the overlapping cylinders and then reimport it? But I have no clue
> how to do this either.
>
>
> Best wishes,
>
> Simone
>
>
>
>
>
>
Yet another possibility:

First, you need to create two set of cylinders. One will be the one that 
is visible, the second will never be viewed and you never give it any 
texture.
The cylinders in the second set will be twice the radius of the first 
and slightly longer.

Next, as you create your cylinders, you make inside teste against the 
previour large cylinders. If the test is positive, it means that you 
have overlaping objects. Ignore that coordinate and chose another.

The extra computing should be acceptable in your case as you don't seem 
to have that many cylinders, 81 to 100 cylinders is still "small".

Then, you can also place the cylinders in a regular gird and jitter them 
somewhat. It can be acceptable if you have comparatively small cylinders 
in a large gird. Here, you only need to set the random displacement just 
large enough so that the cylinders can at most just touch.



Alain


Post a reply to this message

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