|
|
"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
|
|