POV-Ray : Newsgroups : povray.general : random placement of objects Server Time
23 Dec 2024 22:41:31 EST (-0500)
  random placement of objects (Message 1 to 3 of 3)  
From: netquest
Subject: random placement of objects
Date: 8 Jul 2003 13:10:01
Message: <web.3f0afa4b950a689e5f8006bd0@news.povray.org>
Hello,

I'm in the process of creating a number of basic objects using the *declare*
statement. Ultimately, I'd like to have a large collection of objects from
which a subset would be randomly selected and placed on a flat surface,
with each of these scenes being rendered and saved.  The objects should not
overlap.  Suggestions on how this may be accomplished would be appreciated.
 Currently, I'm only creating objects from the basic primitives with
different colours and textures and a known maximum size.

Thanks.


Post a reply to this message

From: Chris Amshey
Subject: Re: random placement of objects
Date: 8 Jul 2003 15:50:02
Message: <web.3f0b1fc6206e568c61b99e900@news.povray.org>
netquest wrote:
>Hello,
>
>I'm in the process of creating a number of basic objects using the *declare*

Roughly speaking,

#declare Xcount = -5;
#while (Xcount < 5)
 #declare Zcount = -5;
 #while (Zcount < 5)
   #if(rand(RObjects) > 0.5)
      object { ArrayOfObjects[floor(10*rand(RObjects))] }
   #end
   #declare Zcount = Zcount + MaxSize;
 #end
 #declare Xcount = Xcount + MaxSize;
#end

Of course, over the area you want, and you could use #switch instead of an
array, but basically, iterate over the two axis in steps big enough to avoid
a collision, and choose randomly whether or not to place an object.

For a less grid-like look, you could iterate in steps of twice-maxsize and
place an object at xcount,zcount +/- maxsize, (or combine the two randoms -
randomly place an object or not, randomly placed near the current point).

You get the idea, I hope. Don't forget to seed() your randoms and initialize
your array and so on.

--Chris


Post a reply to this message

From: Chris Amshey
Subject: Re: random placement of objects
Date: 9 Jul 2003 00:35:01
Message: <web.3f0b9a8e206e568c61b99e900@news.povray.org>
Chris Amshey wrote:

>      object { ArrayOfObjects[floor(10*rand(RObjects))] }
*cough* Of course, that object { } should include a translate to somewhere
resembling <Xcount, SomeHeight, Zcount> *cough* ...

(and of -course- I never make mistakes like that with real code and end up
staring at a convoluted mess wondering what went wrong... ;))


--Chris


Post a reply to this message

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