POV-Ray : Newsgroups : povray.newusers : Duplicating objects : Re: Duplicating objects Server Time
29 Jul 2024 08:22:24 EDT (-0400)
  Re: Duplicating objects  
From: Warp
Date: 5 Apr 2006 12:10:06
Message: <4433ebde@news.povray.org>
ChaoZ <nomail@nomail> wrote:
> 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).

  Well, packing objects close to each other (but so that they don't intersect
each other) is one of the algorithmical problems which have been studied
for long and there are many possible solutions (neither of which might be
perfect in all possible situations).
  You can find more information eg. here:

http://en.wikipedia.org/wiki/Sphere_packing

  Of course what you want to do is not to pack the spheres as tightly as
possible, but a bit more loosely and with some randomness. This, of course,
starts requiring more heuristical algorithms.

  One naive and quite inefficient approach is to put spheres (well,
circles really, as they are all located on the same plane) at random
locations, but with each new sphere check if it intersects any of the
other spheres already created. To make this check, simply put the location
of the center of each sphere in an array, and when creating a new sphere
go through the array and check if the vlength() of the center of the new
sphere and any of the values in the array is less than 2, and only if
none of the values in the array meet this criterion, create the new
sphere (and put its center coordinates in the array).
  This is quite a slow approach, but works. Its disadvantage is that
it really puts the spheres randomly on the plane and you will not get
any nice patterns (which is what you might want).

  As for rotating the sphere before putting it in its final location,
simply create the sphere centered at the origin, rotate it, and than
translate it to its final location.

-- 
                                                          - Warp


Post a reply to this message

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