POV-Ray : Newsgroups : povray.general : HELP Using macro to visualise mathematical functions : Re: HELP Using macro to visualise mathematical functions Server Time
2 Aug 2024 08:13:07 EDT (-0400)
  Re: HELP Using macro to visualise mathematical functions  
From: Shay
Date: 30 Nov 2004 15:09:48
Message: <41acd38c$1@news.povray.org>
The Ugly wrote:

> 
> Just to set things straight: There is no way to sort of build in the
> "function(n) { ... }" bit into the macro so that the user just has to type
> "X*X" instead of "function(x) { x*x }" when calling it?
> 
> 

There is, but the method is a bit ugly. There is a macro in
"strings.inc" called Parse_String. You can see how it works in the docs,
but in effect it turns a string (which can be passed as a macro
parameter) into the code inside the string. You can use it like this:

#include "strings.inc"
#local Formula = "x*x"; // notice that this is a string
#local TempFunction = function(x){ Parse_String(Formula) }

Another thing to watch out for is that function names cannot be reused
unless they are undefined first. So, if your macro is called more than
once, you will need to make sure that the declaration from the first
time is undeclared. This looks like this in POV-Ray:

#ifdef ( TempFunction )
   #undef TempFunction
#end

Now the name TempFunction can be used again.

I'll let you figure out how to rewrite the macro. Let us know if you
need any help. Remember that the macro call will need the Formula as a
string. That is: MyFunc(1,"x*x")

  -Shay


Post a reply to this message

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