POV-Ray : Newsgroups : povray.general : Help with function : Re: Help with function Server Time
29 Jul 2024 14:17:25 EDT (-0400)
  Re: Help with function  
From: Anthony D  Baye
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

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