POV-Ray : Newsgroups : povray.newusers : Duplicating objects : Re: Duplicating objects Server Time
29 Jul 2024 08:18:18 EDT (-0400)
  Re: Duplicating objects  
From: Trevor G Quayle
Date: 5 Apr 2006 12:05:01
Message: <web.4433e9a0dc79859e6c4803960@news.povray.org>
"ChaoZ" <nomail@nomail> wrote:
> Hello again,
>
> I'm trying to create a scene a whole bunch of spheres on a plane in a tight,
> but somewhat random formation (the spheres, with radius of 1, cannot
> intersect each other). Each sphere is textured and also needs to be rotated
> to a random position around the y axis. (perhaps even within a specific
> range, i.e. between -30 to +30 degrees).
>
> Since I'm still somewhat new, I don't really know how to automate this
> process. I know I can define the sphere as a function and plug in values
> for each one, but is there a way to automate this?
>
> Thanks.

You will need to make use of loops and arrays.

Use a loop to generate each object, i.e.:

#local i=0; #while (i<nSpheres)
  sphere{0,1 texture{SphereTex} rotate SphereRot translate SphereLoc}
#local i=i+1; #end

Create each sphere at the origin (0,0,0), them apply the texture and rotate
before translating it to its position.

In order to check for intersection, you can use a brute-force method.  For
each sphere, save its location to an array, for each subsequent sphere
generation, you need to check its distance to all previous spheres, if an
intersection is found, discard that position and regenerate a new one
before moving on to the next.
Be warned however, that this will work fine for smaller number of spheres,
But, if you have a very large number of spheres, this can be come very time
consuming as the intersection check time grows exponentially, and the odds
that it will intersect a previous sphere grows as well.  To speed up in
this case, you would need to use a more efficient sort and seek algorithm
(which I will not go into here)

-tgq


Post a reply to this message

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