POV-Ray : Newsgroups : povray.general : Explanation of recursive macros. Server Time
9 Aug 2024 01:23:33 EDT (-0400)
  Explanation of recursive macros. (Message 1 to 7 of 7)  
From: BigCeef
Subject: Explanation of recursive macros.
Date: 12 Sep 2000 15:17:25
Message: <39be8145@news.povray.org>
Hi,

I'd like to ask a favour. Having returned to POV, it has become clear to me
that my difficulties concentrating ( due to health reasons ) are really
causing me real problems. I'm trying to understand how those macros work
that build trees and the like, but I look at the code and simply cannot
decipher it.

Would some kind person be willing to explain to me how to, say, build a
branch that splits into twigs a couple of levels? Or point me toward a
tutorial that would serve my purposes?

---------

Also, any tutorials on using photons would be a help. Mainly, I don't
understand the ignore_photons command, but the whole area of photons is
difficult to experiment with, as I'm still stuck with a P200.

---------

Anyway, it's good to be back, and good to see so many of the names I'd got
so used to seeing...and I am SO pleased about MegaPOV..thanks Chris and
Nathan.

Thanks in advance,

Andy Cocker


Post a reply to this message

From: Gilles Tran
Subject: Re: Explanation of recursive macros.
Date: 12 Sep 2000 15:47:06
Message: <39BE87B6.90917B5C@inapg.inra.fr>
BigCeef wrote:

> Would some kind person be willing to explain to me how to, say, build a
> branch that splits into twigs a couple of levels? Or point me toward a
> tutorial that would serve my purposes?

Explaining I don't know, but the code below is as simple as possible so it may
be self-explanatory (I hope).
#version 3.1
camera{location  -z*4  direction 1.5*z  right     4/3*x  look_at  0}
light_source{<-1,1,-1>*100 rgb 1}
#macro Recurs(L)
union{
#if (L>0)
    #local M=L-1;
    cylinder{0,y,0.1}
    object{Recurs(M) rotate z*45 translate y}
    object{Recurs(M) rotate -z*45 translate y}
#end
}
#end
object{Recurs(4) scale 0.5 translate -y pigment{rgb x}}

G.


Post a reply to this message

From: BigCeef
Subject: Re: Explanation of recursive macros.
Date: 12 Sep 2000 17:55:49
Message: <39bea665@news.povray.org>
Hi Gilles,

I'm mid-way through another render at the moment, so I can't try this out,
but I'm encouraged by the fact that I think I understand what's going on in
the code.

Thanks for your prompt help,

Andy Cocker

"Gilles Tran" <tra### [at] inapginrafr> wrote in message
news:39BE87B6.90917B5C@inapg.inra.fr...
> Explaining I don't know, but the code below is as simple as possible so it
may
> be self-explanatory (I hope).
> #version 3.1
> camera{location  -z*4  direction 1.5*z  right     4/3*x  look_at  0}
> light_source{<-1,1,-1>*100 rgb 1}
> #macro Recurs(L)
> union{
> #if (L>0)
>     #local M=L-1;
>     cylinder{0,y,0.1}
>     object{Recurs(M) rotate z*45 translate y}
>     object{Recurs(M) rotate -z*45 translate y}
> #end
> }
> #end
> object{Recurs(4) scale 0.5 translate -y pigment{rgb x}}
>
> G.
>


Post a reply to this message

From: BigCeef
Subject: Re: Explanation of recursive macros.
Date: 12 Sep 2000 21:08:16
Message: <39bed380@news.povray.org>
Okay, I'm beginning to understand this. The line that says #local M=L-1; is
actually a loop, yes? I've only used while() loops before, so I didn't get
this at first.

I'm finding it hard to get my head round Recurs(M) being INSIDE Recurs(L).

Also, your code generated the following warning, which I've been unable to
remedy.

memory macro: 22: warning : Should have at least 2 objects in csg.
Degenerate CSG bounding box (not used!)

Well, there are more than 2 objects in the union. Huh?

--------
//my revised code (just experimenting..output object is a mess of cones)

#version 3.1
camera{location  -z*4  direction 1.5*z  right     4/3*x  look_at  0}

light_source{<-1,1,-1>*100 rgb 1}

#declare Scaler=0.75;

#macro Recurs(L)
union{

#if (L>0)
    #local M=L-1;
    //#local Scaler=0.75;
    #local Seedy=seed(M);
    cone {0,0.1,y,0.1*Scaler}
    sphere {0,0.12 pigment {rgb<1,.3,0>}}
    object{Recurs(M) rotate z*120  scale <Scaler,Scaler/1.1,Scaler>
translate y}
    object{Recurs(M) rotate -z*120  scale <Scaler,Scaler/1.1,Scaler>
translate y}
    object{Recurs(M) rotate -z*0  scale <Scaler,Scaler/1.1,Scaler> translate
y}
rotate <rand(Seedy)*20,rand(Seedy)*360,rand(Seedy)*20> rotate <-10,0,-10>
#end
}

#end


//----------------------------------------------------
object{Recurs(7) scale 0.5 translate -y*.5 pigment{rgb 1}}


Post a reply to this message

From: KalleK
Subject: Re: Explanation of recursive macros.
Date: 13 Sep 2000 03:09:49
Message: <39bf283d$1@news.povray.org>
BigCeef wrote:
> Also, your code generated the following warning, which I've been unable to
> remedy.
>
> memory macro: 22: warning : Should have at least 2 objects in csg.
> Degenerate CSG bounding box (not used!)
>
> Well, there are more than 2 objects in the union. Huh?

The macro calls itself. What Povray gets finally is a union of unions of
unions and so on. And it happens, that (L<= 0). In this case, it produces an
union with nothing in it.
union {
 #if (False)
  /* this part is ignored */
 #end
}
There are no objects in this union. That driggers the #warning.
I hope, i can help.
KK


Post a reply to this message

From: ryan constantine
Subject: Re: Explanation of recursive macros.
Date: 13 Sep 2000 03:30:25
Message: <39BF2CE0.2ABA057B@yahoo.com>
BigCeef wrote:
> 
> Okay, I'm beginning to understand this. The line that says #local M=L-1; is
> actually a loop, yes? I've only used while() loops before, so I didn't get
> this at first.

actually, that isn't a loop, just a counter decrement.  a 'recursive'
function is a special kind of function.  it calls itself.  this makes
what might look like a family tree.  you start with the father, and he
has an identical son, which has an identical son, which has an identical
son... and each time a new generation is born, the decrement is made. 
in real life, sons usually out live fathers.  but in recursive
functions, the last one made is the first to die. when each son dies, he
gives the objects he created to his father.  then that son dies and
gives his object to his father and so on until the original father is
the only one left and he has all of the objects assembled which he gives
to povray.

> I'm finding it hard to get my head round Recurs(M) being INSIDE Recurs(L).
> 
> Also, your code generated the following warning, which I've been unable to
> remedy.
> 
> memory macro: 22: warning : Should have at least 2 objects in csg.
> Degenerate CSG bounding box (not used!)
> 
> Well, there are more than 2 objects in the union. Huh?

the warning is made because one or more sons have one or no object to
contribute to the whole.


Post a reply to this message

From: BigCeef
Subject: Re: Explanation of recursive macros.
Date: 13 Sep 2000 21:56:03
Message: <39c03033@news.povray.org>
Thanks guys,

I'm slowly getting my head around this.
-------
Andy


"ryan constantine" <rco### [at] yahoocom> wrote in message
news:39BF2CE0.2ABA057B@yahoo.com...

> the warning is made because one or more sons have one or no object to
> contribute to the whole.


Post a reply to this message

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