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 04:32:26 EDT (-0400)
  Re: Implicit loops in function(x,y,z)  
From: Warp
Date: 14 Jul 2008 11:13:23
Message: <487b6d13@news.povray.org>
slehar <sle### [at] gmailcom> wrote:
> which creates a whole 3-D array of values in the density function. But all that
> looping occurs implicitly or invisibly in POV-Ray, which causes
> endless confusion.

  No 3D array is created from your function. Your function is simply evaluated
for points in space when it's needed.

  For example, if you are using that function as a media density, when a
ray hits the media container, the inside of the container is sampled along
that ray. In other words, points on that ray are calculated, and your
function is evaluated for those points.

  Your function is not evaluated *explicitly* in a loop. It's just evaluated
any time a value from it is required for some spatial point (regardless of
which point it is or how it was calculated).

> #declare densityfunc = function( x, y, z) {
>   #declare xSqr = x*x;
>   #declare ySqr = y*y;
>   sqrt(xSqr+ySqr)
> }

  This is a completely different issue.

  I know that it's confusing for the 'function' syntax to be *similar*
to the SDL. However, inside a "function" block the language used is
completely separate and distinct from the SDL. It has nothing to do
with the SDL.

  Your #declare lines are SDL and thus are *not* parsed as part of your
function. They are evaluated as SDL. In the SDL namespace 'x' has a
completely different meaning than in your function namespace. (In SDL
'x' is a constant which value is <1, 0, 0>).

  If you want to avoid confusion, don't use 'x', 'y' or 'z' as your
function parameters, but use something else, for example:

#declare densityfunc = function(X, Y, Z) { ... };

  X, Y and Z have no default meaning in SDL, so they will cause less
confusion and clearer error messages.

  SDL code can be used to build functions, but once they have been built,
the function itself knows nothing about the SDL. The function will be
the same as if you had manually replaced every SDL command and identifier
with their equivalent interpreted value.

> So sometimes x is the vector <1,0,0>, and other times it is ...-2,-1,0,1,2....

  Don't use "x" as the name of your function parameter, if you want to
avoid confusion. Use something else, as I suggested above.

-- 
                                                          - Warp


Post a reply to this message

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