POV-Ray : Newsgroups : povray.newusers : Using conditional expression in functions. How to write step functions? : Using conditional expression in functions. How to write step functions? Server Time
8 Jul 2024 00:23:45 EDT (-0400)
  Using conditional expression in functions. How to write step functions?  
From: Evgenij Gagauz
Date: 18 Dec 2009 11:25:01
Message: <web.4b2babbe34012ef28bf23f70@news.povray.org>
Is there a way to use an conditional expression in function?

For example, how can I write something like that (the code isn't compilable):
#local  =
function(a) {
  #if (a < .1)
    1
  #else
    0
  #end
}

The compiler says that it doesn't know anything about "a".

Ok, the "#if" condition is calculated only once, but function will be calculated
many times. I try to rewrite the function:

#local  =
function(a) {
  (a < .1) ? 1 : 0
}

But the compiler says that "Expected 'operator', ? found instead". But as I know
the question sign is a float operator.

Where I'm wrong? And how to write for example step functions? Shall I use the
"select" function?
Unfortunatly I can't see a good way for modelling function like this:
___----_-__- with the "select" function.


Post a reply to this message

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