POV-Ray : Newsgroups : povray.general : more interesting functions is isosurface Server Time
29 Nov 2024 15:58:22 EST (-0500)
  more interesting functions is isosurface (Message 1 to 7 of 7)  
From: Paul Bourke
Subject: more interesting functions is isosurface
Date: 11 Sep 2005 00:42:26
Message: <pdbNOSPAM-75E6A0.14422411092005@news.povray.org>
Is it possible to use more interesting user defined float functions
in an isosurface?

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.

Direct email replies welcome.
-- 
Paul Bourke
pdb(NOSPAM)@swin.edu.au


Post a reply to this message

From: Slime
Subject: Re: more interesting functions is isosurface
Date: 11 Sep 2005 00:57:22
Message: <4323b932$1@news.povray.org>
> 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

From: Warp
Subject: Re: more interesting functions is isosurface
Date: 11 Sep 2005 02:54:33
Message: <4323d4a9@news.povray.org>
Slime <fak### [at] emailaddress> wrote:
> Unfortunately, you can't really have loops

  You say this and then later you give an example of a looping function
(using recursion)... :P

  It's true that user-defined functions don't have a loop structure per se
(like 'for', 'while', etc), but usually you can use recursion to achieve
the same thing (even though the lack of assignable variables makes it a
bit cumbersome sometimes).

-- 
                                                          - Warp


Post a reply to this message

From: Christoph Hormann
Subject: Re: more interesting functions is isosurface
Date: 11 Sep 2005 03:25:01
Message: <dg0ls5$3gu$1@chho.imagico.de>
Paul Bourke wrote:
> Is it possible to use more interesting user defined float functions
> in an isosurface?
> 
> 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.

In addition to the technique Slime outlined you can of course use #while 
etc. in functions to generate functions (whithout actual render time 
loops of course).  In some cases this can be an efficient way to 
generate complicated functions (if your loop parameters do not depend on 
the function parameters).

My waves include file:

http://www.tu-bs.de/%7Ey0013390/pov/water/water_inc.html

gives an example for this.

Christoph

-- 
POV-Ray tutorials, include files, Landscape of the week:
http://www.tu-bs.de/~y0013390/ (Last updated 24 Jul. 2005)
MegaPOV with mechanics simulation: http://megapov.inetart.net/


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: more interesting functions is isosurface
Date: 11 Sep 2005 08:53:33
Message: <432428D0.4050607@trf.de>
Paul Bourke wrote:
> Is it possible to use more interesting user defined float functions
> in an isosurface?
> 
> 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.
> 
> Direct email replies welcome.

In POV-Ray 3.6 (or was it only 3.6.1, I don't remember for sure, I tested 
with 3.7 beta), real recursive functions work as an experimental feature. 
You still get a possible error reported, but possible errors are non-fatal, 
so the parser does continue.  Thus, this should work:

#declare f = function(n) { select(n - 2.01, 1, f(n - 1) + f(n - 2)) }
#declare n = 1;
#while(n < 20)
  #debug str(f(n), 0, 0)
  #debug "\n"
  #declare n = n + 1;
#end

As far as declaring variables inside functions is concerned (as others have 
mentioned), sum and prod "declare" an iteration variable, and thus with sum 
or prod one can get a _few_ local variables (they are truly local and not 
computed more than once) when using them together with a suitable final 
value for the iteration.

	Thorsten


Post a reply to this message

From: Hosiah
Subject: Re: more interesting functions is isosurface
Date: 21 Sep 2005 21:05:01
Message: <web.43320316c5f99febde857b690@news.povray.org>
When it comes to tutorials for ISOsurfaces, I highly recommend:

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

It covers the topic in fascinating depth! But I don't recall anything
specific about using controlled loops in an ISOsurface declaration.


Post a reply to this message

From: Warp
Subject: Re: more interesting functions is isosurface
Date: 22 Sep 2005 00:53:38
Message: <433238d2@news.povray.org>
Hosiah <lev### [at] linuxquestionsnet> wrote:
> When it comes to tutorials for ISOsurfaces, I highly recommend:

> http://www.econym.demon.co.uk/isotut/

> It covers the topic in fascinating depth! But I don't recall anything
> specific about using controlled loops in an ISOsurface declaration.

  Perhaps that tutorial would benefit from an additional section called
"recursive functions".

-- 
                                                          - Warp


Post a reply to this message

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