POV-Ray : Newsgroups : povray.general : Help with function Server Time
26 Nov 2024 07:28:42 EST (-0500)
  Help with function (Message 1 to 6 of 6)  
From: Anthony D  Baye
Subject: Help with function
Date: 31 Mar 2011 04:20:01
Message: <web.4d943844cb1d54df9c4fb0ad0@news.povray.org>
can someone help me with the following transform:

#local s = 1 / (2 * (1 + sum(k,1,n, cos(2*pi*k/n)) ));

pov throws a nutty and says i don't have a semi-colon and I know i do.

the code is below.

Any help is appreciated.

Regards,
A.D.B.

#include "kolors.inc"
#include "math.inc"

light_source { <0.0, 0.0, -20.0> 1.0 }
camera {
     perspective
     location <0.0, 0.0, -20.0>
     up y
     right (image_width/image_height)*x
     look_at 0.0
     }

#default { pigment { White } finish { ambient 0.3 diffuse 0.6 } }

#macro nGon(n, r)
     prism {
          -0.0625, 0.0625, 2*n+1
          #local i = 0;
          #while(i <= 2*n)
               #if(i <= n)
                    r*<cosd( i * (360/n) ), sind( i * (360/n) )>
               #else
                    (r-0.015625) * <cosd( i * (360/n) ), sind( i * (360/n) )>
               #end
          #local i = i + 1;
          #end
               rotate -90.0*x
          }
#end

#macro sierpinski(n, r, E, T)

#local s = 1 / (2 * ( 1 + sum(k,1,n/4,cos(2*pi*k/n)) ));
object {
     union {
     union {
     #if(r >= E)
          #local i = 0;
          #while(i < n)
#local T1 = (1 - s ) * r * <cos(2*pi*(i+1)/n), sin(2*pi*(i+1)/n), 0>;
               sierpinski(n, r*s, E
                    transform { translate T1 })
          #local i = i + 1;
          #end
     #end
          }

     nGon(n, r)
     }
          transform { T }
     }

#end

sierpinski(6, 5, 1/32, transform { translate 0*x })


Post a reply to this message

From: Jim Holsenback
Subject: Re: Help with function
Date: 31 Mar 2011 08:15:29
Message: <4d947061$1@news.povray.org>
On 03/31/2011 05:16 AM, Anthony D. Baye wrote:
> can someone help me with the following transform:
>
> #local s = 1 / (2 * (1 + sum(k,1,n, cos(2*pi*k/n)) ));

Just a casual glance so I might be wrong, but I think you're misusing 
the sum function


Post a reply to this message

From: Robert McGregor
Subject: Re: Help with function
Date: 31 Mar 2011 10:45:01
Message: <web.4d9492df2c67487c86ff1d480@news.povray.org>
Jim Holsenback <jho### [at] povrayorg> wrote:
> On 03/31/2011 05:16 AM, Anthony D. Baye wrote:
> > can someone help me with the following transform:
> >
> > #local s = 1 / (2 * (1 + sum(k,1,n, cos(2*pi*k/n)) ));
>
> Just a casual glance so I might be wrong, but I think you're misusing
> the sum function

Yep, try something like this, with a function wrapper for sum:

#local fn = function(k,n) { sum(k,1,n, cos(2*pi*k/n)) }
#local s = 1 / (2 * (1 + fn(1,2)));

-------------------------------------------------
www.McGregorFineArt.com


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Help with function
Date: 31 Mar 2011 11:30:00
Message: <web.4d949cda2c67487c81c811d20@news.povray.org>
"Robert McGregor" <rob### [at] mcgregorfineartcom> wrote:
> Jim Holsenback <jho### [at] povrayorg> wrote:
> > On 03/31/2011 05:16 AM, Anthony D. Baye wrote:
> > > can someone help me with the following transform:
> > >
> > > #local s = 1 / (2 * (1 + sum(k,1,n, cos(2*pi*k/n)) ));
> >
> > Just a casual glance so I might be wrong, but I think you're misusing
> > the sum function
>
> Yep, try something like this, with a function wrapper for sum:
>
> #local fn = function(k,n) { sum(k,1,n, cos(2*pi*k/n)) }
> #local s = 1 / (2 * (1 + fn(1,2)));
>
> -------------------------------------------------
> www.McGregorFineArt.com

Though the docs don't seem to say so explicitly, it appears that the sum() and
prod() functions need to be in a function.


You actually don't need to pass the 'k' component in Robert's example:

#local fn = function(n){sum(k,1,n/4,cos(2*pi*k/n))}

Better yet, include the whole thing inside the function:

#local fn = function(n){1/(2*(1+sum(k,1,n/4,cos(2*pi*k/n))))}

Then you only need to call fn(n) in place of #declaring s.

Also note, declare this before your macro.  As the macro gets called more than
once, it will try to redefine fn() and give you an error unless you #undef it
each time, but this is unecessary if you keep it outside the macro.

-tgq


Post a reply to this message

From: Anthony D  Baye
Subject: Re: Help with function
Date: 31 Mar 2011 14:35:01
Message: <web.4d94c8ce2c67487cd7f39bd00@news.povray.org>
"Trevor G Quayle" <Tin### [at] hotmailcom> wrote:
> "Robert McGregor" <rob### [at] mcgregorfineartcom> wrote:
> > Jim Holsenback <jho### [at] povrayorg> wrote:
> > > On 03/31/2011 05:16 AM, Anthony D. Baye wrote:
> > > > can someone help me with the following transform:
> > > >
> > > > #local s = 1 / (2 * (1 + sum(k,1,n, cos(2*pi*k/n)) ));
> > >
> > > Just a casual glance so I might be wrong, but I think you're misusing
> > > the sum function
> >
> > Yep, try something like this, with a function wrapper for sum:
> >
> > #local fn = function(k,n) { sum(k,1,n, cos(2*pi*k/n)) }
> > #local s = 1 / (2 * (1 + fn(1,2)));
> >
> > -------------------------------------------------
> > www.McGregorFineArt.com
>
> Though the docs don't seem to say so explicitly, it appears that the sum() and
> prod() functions need to be in a function.
>
>
> You actually don't need to pass the 'k' component in Robert's example:
>
> #local fn = function(n){sum(k,1,n/4,cos(2*pi*k/n))}
>
> Better yet, include the whole thing inside the function:
>
> #local fn = function(n){1/(2*(1+sum(k,1,n/4,cos(2*pi*k/n))))}
>
> Then you only need to call fn(n) in place of #declaring s.
>
> Also note, declare this before your macro.  As the macro gets called more than
> once, it will try to redefine fn() and give you an error unless you #undef it
> each time, but this is unecessary if you keep it outside the macro.
>
> -tgq

ok, it works, mostly.  I just added an ifndef around the transform declaration.

I also replaced the nGon() macro call with a simple sphere{ 0.0, 0.03125 }

only one thing:  I would expect to get a mengher sponge at n=4, but all I get is
a white grid.

Regards,
A.D.B.


Post a reply to this message

From: Jim Holsenback
Subject: Re: Help with function
Date: 31 Mar 2011 15:33:23
Message: <4d94d703$1@news.povray.org>
On 03/31/2011 12:25 PM, Trevor G Quayle wrote:
> "Robert McGregor"<rob### [at] mcgregorfineartcom>  wrote:
>> Jim Holsenback<jho### [at] povrayorg>  wrote:
>>> On 03/31/2011 05:16 AM, Anthony D. Baye wrote:
>>>> can someone help me with the following transform:
>>>>
>>>> #local s = 1 / (2 * (1 + sum(k,1,n, cos(2*pi*k/n)) ));
>>>
>>> Just a casual glance so I might be wrong, but I think you're misusing
>>> the sum function
>>
>> Yep, try something like this, with a function wrapper for sum:
>>
>> #local fn = function(k,n) { sum(k,1,n, cos(2*pi*k/n)) }
>> #local s = 1 / (2 * (1 + fn(1,2)));
>>
>> -------------------------------------------------
>> www.McGregorFineArt.com
>
> Though the docs don't seem to say so explicitly, it appears that the sum() and
> prod() functions need to be in a function.

Yep ... when I had a quick look at the docs the example does appear to 
be eluding to that point, but yes it's a bit thin, and that's why I 
wasn't 100% on my initial advice.

I've been asked to capture some information from the "Light Attenuation" 
thread in this same news group and see if I can glean something from 
that discussion and get it into the docs ... I'll add prod/sum to my to 
do list as well.

Jim


Post a reply to this message

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