|
![](/i/fill.gif) |
> When defining the function for an isosurface I would lke to be able
> to use #while loops, for example, to compute a series to some specified
> precision.
Unfortunately, you can't really have loops (although there is a summation
function which can help in some cases) or variables, but some things can be
faked if necessary, especially with recursion.
Here are some handy tricks:
The functional equivalent of precomputing a variable for multiple later uses
is this:
#declare func1 = function(x,y,z, precomputed){...}
#declare func2 = function(x,y,z) {func1(x,y,z, computeSomething(x,y,z))}
An if/else type of thing can be done with select():
select(
x-3, // "if x is less than 3", or more precisely "if x minus 3 is less
than zero"
x, // then
-x // else
)
And this can be used with recursion, which can be used to replace a while
loop. For instance, Warp once wrote this code to create a mandel fractal
(from "Re: Difference Small objects and Glass Cube" on Tuesday, September
14, 2004 11:28 AM in povray.general):
#declare MandIter =
function(n, Re, Im, Zr, Zi)
{ select(n>50 | Zr*Zr+Zi*Zi > 4, 0,
MandIter(n+1, Re, Im, Zr*Zr-Zi*Zi+Re, 2*Zr*Zi+Im), n/50)
}
#declare Mandel = function(Re, Im) { MandIter(0, Re, Im, Re, Im) }
> Direct email replies welcome.
I think it's best to reply via the newsgroup so the community benefits from
the knowledge passed on.
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
![](/i/fill.gif) |