POV-Ray : Newsgroups : povray.advanced-users : operator (or variable?) substitution in a function? Server Time
8 Jul 2024 18:56:10 EDT (-0400)
  operator (or variable?) substitution in a function? (Message 1 to 4 of 4)  
From: Kenneth
Subject: operator (or variable?) substitution in a function?
Date: 25 Oct 2006 23:40:01
Message: <web.45402cb96b2c582d870dc4da0@news.povray.org>
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);

but I get the error message at that line, "Float expected but vector or
color expression found."

I have a vague idea why this isn't working (having to do with y being a kind
of undefined generic operator, but which POV-Ray is seeing as a color
operator--I think). But is there a workaround to what I'm trying to do? Or
is operator substitution like this not possible? (I don't know where to
look in the POV docs to find the answer.)

Ken W.


Post a reply to this message

From: Mike Williams
Subject: Re: operator (or variable?) substitution in a function?
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

From: Kenneth
Subject: Re: operator (or variable?) substitution in a function?
Date: 27 Oct 2006 01:25:00
Message: <web.454196aa5e545f214f827d3b0@news.povray.org>
Mike Williams <nos### [at] econymdemoncouk> wrote:
#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>.

A new discovery for me.  Thanks.
>
> 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.

Yes, I did have a vague notion that this might be happening... but was
hoping not!  ;-)

> 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.

I understand completely. (Though I have to admit, I'm still a bit fuzzy on
which things happen during parsing and which during rendering.  But your
explanation has helped close that gap.)
>
> #declare bender = function(y){ .2*sin(1*pi*y + 5)}

Excellent!  Thanks so much. I wouldn't have thought of that. I also see that
I need to use brackets (around the expression) rather than parentheses.
Because it's a function. Ohhhh....
>
> Then you can write things like
>
> isosurface{
>   function {
>     sqrt( pow(x+bender(y),2) + pow(z,2)) -0.05
>   }

Just what I was looking for.  Thanks for "opening my eyes."  This technique
will be VERY useful.

Ken


Post a reply to this message

From: Kenneth
Subject: Re: operator (or variable?) substitution in a function?
Date: 27 Oct 2006 02:55:00
Message: <web.4541ac2a5e545f214f827d3b0@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> Mike Williams <nos### [at] econymdemoncouk> wrote:

BTW, Mike, I forgot to add: Your isosurface tutorials are really excellent.

For those who haven't seen them yet, here's the link...

http://www.econym.demon.co.uk/isotut/index.htm

Ken W.


Post a reply to this message

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