POV-Ray : Newsgroups : povray.newusers : How do you write Functions? Server Time
2 Nov 2024 15:26:02 EDT (-0400)
  How do you write Functions? (Message 1 to 5 of 5)  
From: Felbrigg
Subject: How do you write Functions?
Date: 9 Mar 2004 12:41:52
Message: <404e01e0$1@news.povray.org>
Can anyone give me a simple explanation of how to write a function for use
in an isosurface or a pattern.  I've seen many examples and even some
tutorials, yet none are clear on the basic input / output of a function POV.

For instance.  Do all functions return a float, if so is it always between 0
and 1?  Some functions seem to require parameters other dont, whats the rule
here.  I'm a programer by trade so coding as a rule is not a mystery.  Just
how to a start writing my own.


Post a reply to this message

From: Christoph Hormann
Subject: Re: How do you write Functions?
Date: 9 Mar 2004 13:00:02
Message: <c2l0mb$82v$1@chho.imagico.de>
Felbrigg wrote:
> Can anyone give me a simple explanation of how to write a function for use
> in an isosurface or a pattern.  I've seen many examples and even some
> tutorials, yet none are clear on the basic input / output of a function POV.
> 
> For instance.  Do all functions return a float, if so is it always between 0
> and 1?  Some functions seem to require parameters other dont, whats the rule
> here.  I'm a programer by trade so coding as a rule is not a mystery.  Just
> how to a start writing my own.

The various tutorials available should already make this pretty clear, 
apart from that the docs will explain everything else:

http://www.povray.org/documentation/view/140/

There are examples in there for functions with specified parameters, 
float/vector/color functions and everything else.

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 07 Mar. 2004 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Tom Melly
Subject: Re: How do you write Functions?
Date: 10 Mar 2004 04:35:44
Message: <404ee170$1@news.povray.org>
"Felbrigg" <som### [at] microsoftcom> wrote in message
news:404e01e0$1@news.povray.org...
> Can anyone give me a simple explanation of how to write a function for use
> in an isosurface or a pattern.  I've seen many examples and even some
> tutorials, yet none are clear on the basic input / output of a function POV.
>
> For instance.  Do all functions return a float, if so is it always between 0
> and 1?  Some functions seem to require parameters other dont, whats the rule
> here.  I'm a programer by trade so coding as a rule is not a mystery.  Just
> how to a start writing my own.

All functions *should* return a float for any particular values of x,y, and z,
but a flawed function may return an unusable value such as 1/0. The float may be
any value, positive or negative.

Pov will draw the surface of the object when the value returned by the function
equals the threshold. If the value returned is lower than the threshold, then
that point is inside the object. If the value returned is higher than the
threshold then that point is outside the object. By default, the threshold is 0,
but can be set to any value.

Now, consider the function for a sphere, x*x + y*y + z*z - the question here is
at what vectors (<x,y,z>) is  the result <= 0? Well, in this case, there is only
one vector, <0,0,0> since if either x,y or z is <> 0 then the result will be
greater than 0. So this function is no good, since there is no "inside" to the
sphere - just a single point-surface.

However, if we ask ourselves "at what point is the result <= 1?" then we get
something more interesting.... a sphere with a radius of 1. Probably teaching
grandmother to suck eggs here, but, for example, the point <-1,0,0> equates to
(-1*-1) + 0 + 0 = 1 and so on.

So, in order to get the function x*x + y*y + z*z to actually produce something,
we will either need to change the threshold to 1 or modify the function.
Personally, I prefer modifying the function. Now, we want to draw a surface
where the result of the function is 1, but by default it's drawing the surface
where the result is 0, so all we have to do is subtract 1 from the result, x*x +
y*y + z*z -1, and we will now get our sphere since all points that return > 1
will be outside the 0-threshold, even after subtracting 1, all points that
return 1 will be the surface, since 1-1 = 0, and all points that return < 1 will
be the inside, for example 0.9 - 1 = -0.1

Finally, we need to put a container around the hopeful area of our function,
since pov has no way of knowing where the natural boundary of the object is,
assuming that the object even has a natural boundary.


Post a reply to this message

From: Dave Matthews
Subject: Re: How do you write Functions?
Date: 12 Mar 2004 10:00:41
Message: <4051d099@news.povray.org>
Tom Melly wrote:
>  Probably teaching
> grandmother to suck eggs here, 

Well, that's a new one for me.  I haven't the faintest idea where it 
might come from, but I like it, and must find a way to use it.

Dave Matthews


Post a reply to this message

From: Tom Melly
Subject: Re: How do you write Functions?
Date: 12 Mar 2004 10:50:06
Message: <4051dc2e$1@news.povray.org>
"Dave Matthews" <dma### [at] nospamnet> wrote in message
news:4051d099@news.povray.org...
>
>
> Tom Melly wrote:
> >  Probably teaching
> > grandmother to suck eggs here,
>
> Well, that's a new one for me.  I haven't the faintest idea where it
> might come from, but I like it, and must find a way to use it.

There's a reference to it in the Hobbit (Gollum solves one of the riddles in the
dark when he remembers teaching his grandmother, his grandmother!, to suck
eggs). hmm... (googles)... 1707 is the first known reference.


Post a reply to this message

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