POV-Ray : Newsgroups : povray.general : looking for a way to create recursive objects in povray Server Time
29 Nov 2024 23:26:50 EST (-0500)
  looking for a way to create recursive objects in povray (Message 1 to 2 of 2)  
From: Rick D 
Subject: looking for a way to create recursive objects in povray
Date: 10 Mar 2005 18:05:13
Message: <5dj13150g5t1ncv90ipa6uran0kpgr4o16@4ax.com>
Hi all,

I have a question about the use of recursive object-unions in povray.

This is what i want to do:

***

My basic shape is made up from a sphere and 4 cylinders. And is
basically a ball with 8 pins sticking out of it (every 45 degrees, all
in one plane). See ascii diagram.

<pre>

\|/
-O-
/|\

</pre>

I've created a union of these objects and can now use it like this:

union   { my_basic_shape
rotate <0 ,0 ,0>
scale <1.0, 1.0, 1.0>
translate <0.0, 0.0, 0.0>
}        

***

The next thing i want to do is attach a scaled and rotated
my_basic_shape object-union to the end of each cylinder that sticks
out of the original my_basic_shape object-union. And repeat this for
the new objects, etc ..

***

With the povray knowledge i have at this moment i would have to hard
code each separate object. But i'm sure this sort of thing can be done
using some kind of automated loop with variables, but i haven't been
able to find information about this so far.

If anyone could help me out with this, or point me to a site with
relevant information or a similar example i would really appreciate
it.

Best regards,
Rick D.


Post a reply to this message

From: Mike Williams
Subject: Re: looking for a way to create recursive objects in povray
Date: 11 Mar 2005 01:31:08
Message: <tUroqDAgsTMCFwnP@econym.demon.co.uk>
Wasn't it Rick D. who wrote:
>Hi all,
>
>I have a question about the use of recursive object-unions in povray.
>
> . . .
>
>With the povray knowledge i have at this moment i would have to hard
>code each separate object. But i'm sure this sort of thing can be done
>using some kind of automated loop with variables, but i haven't been
>able to find information about this so far.

The magic word that you need to look up in the documentation is "macro". 

POV supports recursive macros. You can pass parameters to a macro that
you can use to (a) create a copy of the object at a size and position
controlled by those parameters and (b) call copies of itself to handle
the next smaller size (if it's not already at the lowest level).

Here's an example

#macro Recurse(Shape, Posn, Rotn, Depth, Max_Depth)
// draw the shape at this level
  object {Shape
    rotate Rotn
    scale 1/Depth       // scale calculation
    translate Posn
  }
// Check to see if we need to go deeper
  #if (Depth < Max_Depth) 
    // Call the stuff for the next level down
    Recurse (Shape, Posn+x/Depth, Rotn+y*20, Depth+1, Max_Depth)
    Recurse (Shape, Posn-x/Depth, Rotn+y*20, Depth+1, Max_Depth)    
    Recurse (Shape, Posn+y/Depth, Rotn+y*20, Depth+1, Max_Depth)    
    Recurse (Shape, Posn-y/Depth, Rotn+y*20, Depth+1, Max_Depth)    
    Recurse (Shape, Posn+z/Depth, Rotn+y*20, Depth+1, Max_Depth)    
    Recurse (Shape, Posn-z/Depth, Rotn+y*20, Depth+1, Max_Depth)    
  #end
#end

Recurse(My_Basic_Shape, <0,0,0>, <0,0,0>, 1, 5)


I call this macro with Depth=1, and it calls eight copies of itself with
Depth=2 and they each call eight copies with Depth=3 etc.

Change the scale, Posn and Rotn calculations to fit the particular
structure that you're trying to create.

If you need to use any variables in the calculations inside the macro,
use #local rather than #declare to avoid the possibility of the
variables being clobbered by other copies of the macro.


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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