POV-Ray : Newsgroups : povray.advanced-users : Implicit loops in function(x,y,z) : Implicit loops in function(x,y,z) Server Time
3 Jul 2024 05:09:14 EDT (-0400)
  Implicit loops in function(x,y,z)  
From: slehar
Date: 14 Jul 2008 11:00:00
Message: <web.487b67e61050228f75a90cb0@news.povray.org>
I am having endless trouble trying to define a density function that varies as a
function of (x,y,z) position, due to confusion over a kind of "implicit loop"
concept in POV-Ray. Does anyone know a manual page or user post on this
subject, or even what this "implicit loop" concept is officially called? (I
made up that term for lack of a better one)

The issue involves a parameterized function like:

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

The actual values of (x,y,z) are (<1,0,0> <0,1,0> <0,0,1>), but the term "x*x"
in the density function does NOT mean <1,0,0> * <1,0,0>, but rather, x
represents a whole array of values, something like:

..... -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 ...

and the density function above is equivalent to a loop in a regular programming
language something like:

double Array[zSize][ySize][xSize];

for(iz=0; iz<zSize; iz++){
  for(iy=0; iy<ySize; iy++){
    for(ix=0; ix<xSize; ix++){
      Array[z][y][x] = sqrt((x[ix]*x[ix]) + (y[iy]*y[iy]));
    }
  }
}

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. For example this code

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

produces Parse Error: Expected 'operand', vector function 'vector identifier'
found instead.

The problem is that the #declare xSqr = x*x sets xSqr = <1,0,0>*<1,0,0> (=
<1,0,0>) which is now a *vector* and not the value of x at some location in the
density function!

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


Post a reply to this message

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