POV-Ray : Newsgroups : povray.general : recursion problem Server Time
5 Nov 2024 09:22:55 EST (-0500)
  recursion problem (Message 1 to 5 of 5)  
From: Lenx
Subject: recursion problem
Date: 16 Apr 2003 11:56:21
Message: <3e9d7d25@news.povray.org>
i am quiet new to recursion, and i have some problems with it.
now i tried to do some recursion in pov like a pyramid, what worked, but i
want to do more.

what i want to create now is a box, with on the top corners of that box a
new box (eg 10 times smaller than the first box).
on top of the 4 new little boxes you have the same thing.
i want to do this for about 4 levels with recursion. can anyone piont me to
some tutorial or maybe has a similar macro i can learn from?
my problem is that i don't know how to put 4 boxes on the top, and that
while the recusion is looped once. next loop again.. and go on. I can do it
with one box, but there it stops.

i have a similar problem for a programming task for school. maybe i can
solve it when i understand the pov version :-]

regards, lenx


Post a reply to this message

From: ABX
Subject: Re: recursion problem
Date: 16 Apr 2003 12:05:52
Message: <cjvq9v8a8ttau03mf3t0j9ru47gkaahrmd@4ax.com>
On Wed, 16 Apr 2003 17:57:54 +0200, "Lenx" <len### [at] pandorabe> wrote:
> can anyone piont me to
> some tutorial

http://www.google.com/search?q=recursion+tutorial

> or maybe has a similar macro i can learn from?

http://povplace.addr.com/tips/recursion.htm

ABX


Post a reply to this message

From: Remco de Korte
Subject: Re: recursion problem
Date: 16 Apr 2003 17:49:10
Message: <3E9DCFBF.E33F7F56@onwijs.com>
Lenx wrote:
> 
> i am quiet new to recursion, and i have some problems with it.
> now i tried to do some recursion in pov like a pyramid, what worked, but i
> want to do more.
> 
> what i want to create now is a box, with on the top corners of that box a
> new box (eg 10 times smaller than the first box).
> on top of the 4 new little boxes you have the same thing.
> i want to do this for about 4 levels with recursion. can anyone piont me to
> some tutorial or maybe has a similar macro i can learn from?
> my problem is that i don't know how to put 4 boxes on the top, and that
> while the recusion is looped once. next loop again.. and go on. I can do it
> with one box, but there it stops.
> 
> i have a similar problem for a programming task for school. maybe i can
> solve it when i understand the pov version :-]
> 
> regards, lenx

You need a level counter. 

Remco


Post a reply to this message

From:
Subject: Re: recursion problem
Date: 16 Apr 2003 20:27:07
Message: <3e9df4db$1@news.povray.org>
//  Hi Lenx,
//
//  here is a complete scene with the recursion you wanted; I hope
//  you can understand how it works. Simply render this whole text with
//
//     +W800 +H600 -F +D +A0.1
//
//  in the command line. (5 seconds at 1 GHz)
//
//     Sputnik



#macro RecursiveBox (Layers, MidX, BottomY, MidZ, SideLength)

  // draw a box
  box { <MidX-SideLength/2, BottomY           , MidZ-SideLength/2>,
        <MidX+SideLength/2, BottomY+SideLength, MidZ+SideLength/2> }

  #if (Layers>1) // if there are more boxes to be stacked ...

    // ... then calculate some auxiliary values and ...
    #local NewBY = BottomY + SideLength;
    #local NewSL = SideLength/3; // also try 4, 2.5, 2.2, 10
    #local Offset = SideLength/2-NewSL/2; // also try "+" instead of "-"
    // ... put four cube-stacks at the corners of the box
    RecursiveBox (Layers-1, MidX-Offset, NewBY, MidZ-Offset, NewSL)
    RecursiveBox (Layers-1, MidX-Offset, NewBY, MidZ+Offset, NewSL)
    RecursiveBox (Layers-1, MidX+Offset, NewBY, MidZ-Offset, NewSL)
    RecursiveBox (Layers-1, MidX+Offset, NewBY, MidZ+Offset, NewSL)

    #end//if

  #end//macro


// activate the RecursiveBox-macro
union { RecursiveBox (6,  0,-11,0,  9)
  texture { pigment { color rgb <1, .7, .3> } }
  }


//light and camera
light_source { <-10, 20, -7>, 1 }
camera { location <-3, 8, -10> look_at 0 }


Post a reply to this message

From: Lenx
Subject: Re: recursion problem
Date: 17 Apr 2003 05:50:21
Message: <3e9e78dd$1@news.povray.org>
thank you all, i got something working yesterday, this is my code:

//------------------macro---------------------
#macro Recurse(currentlevel, currentscale)

object{  box{ <-50,0,-50> <50,10,50> pigment{ rgb 1}}   scale
<1/currentscale,1,1/currentscale>  pigment{ rgb 1 } }

#if (currentlevel<recursionmax)

   union{
      Recurse(currentlevel+1, currentscale*scalemultiplier)
      translate
<-50/(currentscale*scalemultiplier),0,-50/(currentscale*scalemultiplier)>
      translate <50/currentscale,10/currentscale,50/currentscale>
      }
   union{
      Recurse(currentlevel+1, currentscale*scalemultiplier)
      translate
<50/(currentscale*scalemultiplier),0,-50/(currentscale*scalemultiplier)>
      translate <-50/currentscale,10/currentscale,50/currentscale>
      }
   union{
      Recurse(currentlevel+1, currentscale*scalemultiplier)
      translate
<-50/(currentscale*scalemultiplier),0,50/(currentscale*scalemultiplier)>
      translate <50/currentscale,10/currentscale,-50/currentscale>
      }
   union{
      Recurse(currentlevel+1, currentscale*scalemultiplier)
      translate
<50/(currentscale*scalemultiplier),0,50/(currentscale*scalemultiplier)>
      translate <-50/currentscale,10/currentscale,-50/currentscale>
      }

#end
#end

//----------calling the macro----------
#declare scalemultiplier=3;
#declare recursionmax=4;
Recurse(0,1)
//-------------end of code-------------


now i am looking to do something like recursion into recurion (my mind is
getting twisted though)
i hope i can come up with the scene i have in mind soon.

regards, lenx (still breaking his head on the
mouse-has-to-find-cheese-in-a-maze problem in java)


Post a reply to this message

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