POV-Ray : Newsgroups : povray.newusers : Duplicating objects Server Time
1 Nov 2024 05:21:39 EDT (-0400)
  Duplicating objects (Message 1 to 5 of 5)  
From: ChaoZ
Subject: Duplicating objects
Date: 5 Apr 2006 11:40:01
Message: <web.4433e3e993410dd093a9a8530@news.povray.org>
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.


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Duplicating objects
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

From: Warp
Subject: Re: Duplicating objects
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

From: Alain
Subject: Re: Duplicating objects
Date: 7 Apr 2006 19:23:50
Message: <4436f486$1@news.povray.org>
ChaoZ nous apporta ses lumieres en ce 05/04/2006 11:36:
> 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.
> 
> 
If you can cope with a regular, but displaced, placement, like aproximating a gird.
Use a pair of #while(<condition>) loops to place your spheres along a regular gird.
The trick is to 
use some random displacement when placing them.
As others suggested, define your spheres a the origin: sphere{0,1} Apply any texture
you want, then 
your rotation.
Next, generate the final coordinates adding some random values and use those to
translate your 
spheres to their final positions. You can use random jitter larger than your gird mesh
size, you 
then only need to test against at most 4 other objects to prevent intersections.

-- 
Alain
-------------------------------------------------


Post a reply to this message

From: Chris B
Subject: Re: Duplicating objects
Date: 8 Apr 2006 05:15:07
Message: <44377f1b$1@news.povray.org>
"ChaoZ" <nomail@nomail> wrote in message 
news:web.4433e3e993410dd093a9a8530@news.povray.org...
> 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.
>

Hi Chaoz,

I had the same problem to solve about a year ago and came up with a couple 
of macros. I've posted a copy on povray.binaries.scene-files.

They use the techniques that Warp and Trevor described in their responses. I 
don't find it particularly slow for my own purposes, but if you need a large 
number of spheres in a very tight formation, then the parsing time could go 
up quite a bit.

The example I've posted tries to fit 500 spheres onto a surface that isn't 
really big enough. It therefore detects a lot of 'collisions' and rejects a 
lot of points.
It ends up testing 2531 positions to find 356 positions before it reaches 
the 'maximum tries' control variable (which defaults to 100). This takes 
about 8 seconds. You obviously have to have some sort of control to stop it 
looping indefinitely, because it's possible to use settings where it's not 
physically possible to get that number of objects in the space available, 
but you can increase the 'maximum tries' setting to get a tighter 
configuration.

The macros give you a few added extras, so the surface doesn't have to be 
flat and you can set control variables to keep objects away from edges. You 
can create a 'platform' shape using CSG to bunch your objects as you wish. 
e.g. you can define bits of non-contiguous surface using 'union'.

Anyway, feel free to use this if it meets your purposes.

Regards,
Chris B.


Post a reply to this message

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