POV-Ray : Newsgroups : povray.advanced-users : operator (or variable?) substitution in a function? : Re: operator (or variable?) substitution in a function? Server Time
6 Oct 2024 13:46:36 EDT (-0400)
  Re: operator (or variable?) substitution in a function?  
From: Mike Williams
Date: 26 Oct 2006 05:01:00
Message: <lQuq7GAFlHQFFw60@econym.demon.co.uk>
Wasn't it Kenneth who wrote:
>I'm using a function in an isosurface to create a "bent" vertical
>cylinder...
>
>isosurface{
>function{
>sqrt(pow(x + .2*sin(1*pi*y + 5),2) + pow(z,2)) - .05
>}
>}
>
>..... with the expression  +.2*sin(1*pi*y + 5)  being the "bender" (with a
>vertical displacement for the sine wave.)
>
>I'm using this same bending expression in other parts of the isosurface (in
>other equations) as well as in other isosurfaces. Currently, I just plug in
>the expression wherever I need it...which is tedious.
>
>In hopes of creating a single variable(?) that I could plug in instead, I
>tried...
>
>#declare bender = .2*sin(1*pi*y + 5);

One of the things that's going on is that "y" has two different meanings
in POV. When you're using it in a parse-time variable, like that, it's
interpreted as the vector <0,1,0>. When used inside a function
definition, x, y, and z represent the point in space at which the
function is evaluated.

Another thing that's going on is that you don't want "bender" to be
evaluated at parse time. That would effectively make it behave like a
constant during the render. You want it to be a function that varies
with y during the render, so that different parts of the object are bent
by different amounts.

#declare bender = function(y){ .2*sin(1*pi*y + 5)}

Then you can write things like

isosurface{
  function {
    sqrt( pow(x+bender(y),2) + pow(z,2)) -0.05
  }
}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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