POV-Ray : Newsgroups : povray.advanced-users : Implicit loops in function(x,y,z) : Re: Implicit loops in function(x,y,z) Server Time
3 Jul 2024 05:14:32 EDT (-0400)
  Re: Implicit loops in function(x,y,z)  
From: Mike Williams
Date: 15 Jul 2008 01:50:16
Message: <gg$T6rCHpDfIFw14@econym.demon.co.uk>
Wasn't it slehar who wrote:
>
>So it seems you can't do logical tests on the values of the parameters in a
>function either!
>
>#declare densityfunc = function(px,py,pz) {
>  #if(px > 0 | py < 0)
>    atan2(py,px)
>  #else
>    pi - atan2(py,px)
>  #end
>}
>
>Parse Error: ... undeclared identifier 'px'
>
>That makes it kind of difficult to use functions like atan2() that can behave
>differently in different quadrants. How would you get around this kind of
>thing? How can I make the function use one equation in some quadrants and a
>different equation in other quadrants?

#if doesn't work inside a function. You have to use select().
   select((px>0|py<0),pi-atan2(py,px),atan2(py,px))
[Hint, "true" is -1, "false" is 0]

However, since px and py are constants (they don't vary with the 
location within the function) you can write

   #if(px > 0 | py < 0)
     #declare A = atan2(py,px);
   #else
     #declare A = pi - atan2(py,px);
   #end

function { ...  A ... }

And as a side effect, the function evaluates faster because you're not 
performing all those atan() calculations for every point evaluated by 
the function.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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