POV-Ray : Newsgroups : povray.beta-test : Function weirdness : Re: Function weirdness Server Time
31 Jul 2024 00:24:58 EDT (-0400)
  Re: Function weirdness  
From: Mike Williams
Date: 18 Sep 2001 01:45:19
Message: <1ItGvGAX4qp7Ew7n@econym.demon.co.uk>
Wasn't it Slime who wrote:
>I have this simple function...
>
>function {
>     #local normvec = vnormalize(x,y,z);
>     vlength(normvec)+f_noise3d(normvec.x,normvec.y,normvec.z)-1
>}
>
>I'm trying to get the normal vector of the current x,y,z coordinate being
>tested, but it appears to think i'm referring to the variables x=<1,0,0>,
>y=<0,1,0>, and z=<0,0,1>, so it gives me the error "Parse Error: Expected
>')', , found instead" on the line with the "local" statement.
>
>Is this a bug, or do I need to do this some other way? 


That all looks perfectly correct processing to me. x, y and z have
always meant the unit vectors when they appear in #declare and #local
statements, and I wouldn't expect that to change just because the
assignment happens inside a function block.

Unfortunately, you can't even do things like the following, because the
vlength() and vnormalize() are not supported in the syntax of user
defined functions (see 6.1.6)

function {
     vlength(vnormalize(x,y,z))
     + f_noise3d(vnormalize(x,y,z).x, vnormalize(x,y,z).y,
     vnormalize(x,y,z).z)-1
}


#declare F_normvec = function{vnormalize(x,y,z)}
function {
     vlength(F_normvec(x,y,z))
     + f_noise3d(F_normvec(x,y,z).x, F_normvec(x,y,z).y,       
     F_normvec(x,y,z).z)-1
}

You're allowed to do assignments within a function block, so that you
can do things like managing loops, but you can't use the assignments as
a sneaky way to perform operations that the function syntax itself
doesn't allow.



>Trying #local normlen = sqrt(x^2+y^2+z^2) also caused an error.

Try something like this:

#declare F_normlen=function{sqrt(x^2+y^2+z^2)}
function {F_normlen(x,y,z)}

You can also replace "vlength(vnormalize(x,y,z))" by "1", since a
normalized vector is always of unit length.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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