POV-Ray : Newsgroups : povray.general : Function of a function, or function as a function parameter : Re: Function of a function, or function as a function parameter Server Time
16 Apr 2024 18:40:06 EDT (-0400)
  Re: Function of a function, or function as a function parameter  
From: Chris R
Date: 12 Jan 2024 09:50:00
Message: <web.65a151569ff14ccc17021f505cc1b6e@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I'm working on some other patterns, and I have some general functions that I
> want to use.
>
> The problem is that those functions are things like derivatives, which are
> functions OF other functions.
>
> Is there a way that I can cleanly and elegantly implement a function declaration
> that will allow me to do this?
>
> Otherwise it seems that I'm going to have to either
> a) write a macro to #undef the f'(x) function and redefine it for every function
> that I want to operate on
>
> and/or
>
> b) wind up defining individual functions for every function I want to take the
> function OF - which leads to the morass of multiple functions that I need to
> keep track of - so I can remember which one I need, avoid copy-paste errors, and
> avoid name collisions - I _disdain_.
>
> Because if I need multiple derivatives at render time, then the macro
> work-around is out.
>
> - BE

I'm not sure I completely understand what you are trying to avoid, but here's an
example of a function-manipulating macro I created that takes a function as a
parameter:

//-----------------------------------------------------------------------------
// Translate_fn(FN,T)
//
#macro Translate_fn(FN,T)
    #local _t   = <1,1,1>*T;
    #local _tx  = _t.x;
    #local _ty  = _t.y;
    #local _tz  = _t.z;

    function {
        FN(x-_tx,y-_ty,z-_tz)
    }
#end

// End Translate_fn
//-----------------------------------------------------------------------------

Usage:
#local _my_function = function(x,y,z) { x*y - z }
#local _my_trans_function = Translate_fn(_my_function, <1,1,1>)

Obviously translation is a lot simpler than taking a derivative, so I may be
missing your point here.

-- Chris R.
-- Happily rendering since 2014


Post a reply to this message

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