|
![](/i/fill.gif) |
Yadgar wrote:
> High!
>
> I'm not really sure whether I'm on-topic here or not... but as this
> group also deals with programming techniques, I just assumed...
>
> My question: does PoV-Ray allow programming of "discontinuous" functions
> (I only dabble in math, so please don't stone me if this is not the
> correct terminus!)?
>
> Is it possible to write a function which changes apruptly at certain
> values, such as
>
> from x=0 to x=1.5: pow(x, 2)
> from x=1.5 to x=7: sqrt(14-x)+3
> etc. etc. ?
Try this:
#declare MinB = 0.0;
#declare MaxB = 1.5;
#declare FnB = function(x) { pow(x, 2) }
#declare MinC = 1.5;
#declare MaxC = 7.0;
#declare FnC = function(x) { sqrt(14 - x) + 3 }
#declare IntervalFn =
function(x) {
select(x - MinB, 0, select(x - MaxB, FnB(x), 0)) +
select(x - MinC, 0, select(x - MaxC, FnC(x), 0))
}
This function will return 0 when x is below 0 or above
(or equal to) 7.
To have it return (e.g.) -x when x is below 0 and (e.g.)
-1 when it is above or equal to 7, you can use this code:
#declare MaxA = 0.0;
#declare FnA = function(x) { -x }
#declare MinB = 0.0;
#declare MaxB = 1.5;
#declare FnB = function(x) { pow(x, 2) }
#declare MinC = 1.5;
#declare MaxC = 7.0;
#declare FnC = function(x) { sqrt(14 - x) + 3 }
#declare MinD = 7.0;
#declare FnD = function(x) { -1 }
#declare IntervalFn =
function(x) {
select(x - MaxA, FnA(x), 0) +
select(x - MinB, 0, select(x - MaxB, FnB(x), 0)) +
select(x - MinC, 0, select(x - MaxC, FnC(x), 0)) +
select(x - MinD, 0, FnD(x))
}
- And (despite what others have said in this thread,)
such functions can sometimes be useful in isosurfaces.
--
Tor Olav
http://subcube.net
http://subcube.com
Post a reply to this message
|
![](/i/fill.gif) |