POV-Ray : Newsgroups : povray.unofficial.patches : Step function Server Time
1 Nov 2024 15:25:03 EDT (-0400)
  Step function (Message 1 to 10 of 17)  
Goto Latest 10 Messages Next 7 Messages >>>
From: Libellule
Subject: Step function
Date: 21 Aug 2000 22:17:37
Message: <39A1E2F9.CB1B7B4B@insectes.net>
I was wondering if it was possible to add a Heaviside step function for
use in isosurfaces:

say two arguments, the first is the "switch" point, where the function
goes from 0 to 1 (or vice versa), and the second is the argument, which
would be a good place to put x, y, z or whatever for the expression.

I was thinking about this for say, limiting a sinusoid to a particular
range, by multiplying it by a step function (two actually, one to
truncate each end of it). It could have other uses, I guess.....


Post a reply to this message

From: Chris Huff
Subject: Re: Step function
Date: 21 Aug 2000 22:30:18
Message: <chrishuff-755F17.21314021082000@news.povray.org>
In article <39A1E2F9.CB1B7B4B@insectes.net>, Libellule 
<lib### [at] insectesnet> wrote:

> I was wondering if it was possible to add a Heaviside step function for
> use in isosurfaces:
> 
> say two arguments, the first is the "switch" point, where the function
> goes from 0 to 1 (or vice versa), and the second is the argument, which
> would be a good place to put x, y, z or whatever for the expression.
> 
> I was thinking about this for say, limiting a sinusoid to a particular
> range, by multiplying it by a step function (two actually, one to
> truncate each end of it). It could have other uses, I guess.....

I'm not quite sure what you mean...but wouldn't min() and max() do what 
you want? Do you want a function that is 0 below a certain input value, 
and 1 above it?

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Alberto
Subject: Re: Step function
Date: 22 Aug 2000 00:01:04
Message: <39A1FABF.3E55ED39@usb.ve>
Libellule wrote:
> 
> I was wondering if it was possible to add a Heaviside step function for
> use in isosurfaces:
> 

You can do it with the gradient pattern used as a pigment. In the
following example, the Heaviside function domain is restricted to the x
interval (-1, 1)

#version unofficial MegaPov 0.5;
#default{pigment{rgb 1}}

camera{location <3, 5, -5>  look_at 0 angle 60}
light_source{<2,5,-5>  rgb 1}

#macro Heaviside(jump)
  #local lx = (jump + 1)/2;
  #declare myheavi =
    function{
      pigment{gradient x translate -x/2 scale 2
      color_map{[lx rgb 0][lx rgb 1]}
    }
  }
#end

Heaviside(.5)

isosurface{function{y - myheavi(x, y, z)/10}
  contained_by{box -<1, 1, 1> <1, 1, 1>}
  accuracy .01
  max_gradient 21
}

Hope this will help you.

Regards,       Alberto


Post a reply to this message

From: Alberto
Subject: Re: Step function
Date: 22 Aug 2000 00:29:37
Message: <39A2016F.7B1ED0D2@usb.ve>
Sorry, there is a simpler solution. Replace the previous macro by

#macro Heaviside(jump)
  #declare myheavi = function{if((x - jump),1,0)}
#end

No restriction in the domain of definition

Regards, Alberto


Post a reply to this message

From: Libellule
Subject: Re: Step function
Date: 22 Aug 2000 00:41:00
Message: <39A2049B.223930F@insectes.net>
> Do you want a function that is 0 below a certain input value,
> and 1 above it?

Yes.
Graph of H(u)

 |
1|      ------
 |____________
        |
        u

The stuff Alberto mentioned looks right, does it need all that pigment
related stuff?


Post a reply to this message

From: Chris Huff
Subject: Re: Step function
Date: 22 Aug 2000 10:59:33
Message: <chrishuff-84E935.10005522082000@news.povray.org>
In article <39A2016F.7B1ED0D2@usb.ve>, jac### [at] usbve wrote:

> Sorry, there is a simpler solution. Replace the previous macro by
...snip...
> No restriction in the domain of definition

You don't need a macro for this, a plain old function will do fine.

#declare Heaviside = function {if(x - y, 1, 0)}
// x=the value, y=the jump threshold, z=nothing

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Chris Huff
Subject: Re: Step function
Date: 22 Aug 2000 11:01:02
Message: <chrishuff-D10B4C.10022422082000@news.povray.org>
In article <39A### [at] insectesnet>, Libellule 
<lib### [at] insectesnet> wrote:

> The stuff Alberto mentioned looks right, does it need all that pigment
> related stuff?

It is for that method, which uses the color_map of the pigment to get 
the jump. For the second method, which uses an if() function, there is 
no pigment, and it should execute faster.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Alberto
Subject: Re: Step function
Date: 22 Aug 2000 13:34:23
Message: <39A2B900.9BC7401A@usb.ve>
Chris Huff wrote:

> ... 
> You don't need a macro for this, a plain old function will do fine.
> 
> #declare Heaviside = function {if(x - y, 1, 0)}
> // x=the value, y=the jump threshold, z=nothing
> ...

Agreed. But I think the best solution to Libellule problem should be
something like

#macro Heaviside(jump)
  if(x - jump, 1, 0)
#end

isosurface{function{y - Heaviside(actual_jump)}
  contained_by{box -<1, 1, 1> <1, 1, 1>}
  accuracy .01
  max_gradient 21
}

where actual_jump is a constant float.

In this way, if you need more than one step function with jumps at
distinct places in the same isosurface, this would be the optimal
implementation. I tried this code but got an error message

error: float factor expected but macro identifier found instead.

So macro substitution doesn't work inside function{...}. I thought that
at parse time, this macro substitution would take effect.

Is that a MegaPov misbehavior or is this intended for some reason?

Regards, Alberto.


Post a reply to this message

From: Chris Huff
Subject: Re: Step function
Date: 22 Aug 2000 14:08:04
Message: <chrishuff-33264E.13092622082000@news.povray.org>
In article <39A2B900.9BC7401A@usb.ve>, jac### [at] usbve wrote:

> So macro substitution doesn't work inside function{...}. I thought that
> at parse time, this macro substitution would take effect.
> 
> Is that a MegaPov misbehavior or is this intended for some reason?

This is the reason I wrote it as a function. :-)
No, macros don't work within functions, neither do #if, #switch, or 
#while. How should the internals of the macro work? Macros can have 
local variables and can do different things for each time they are 
called. The only way I can see to do it would be to have the macro be 
evaluated once, at parse time, but this would make it appear to the user 
that the macro is called from within the function, when it is really 
called to make part of the function.

I think the best way to do things would be to extend functions to have 
variable numbers of parameters(so you could just have 1 parameter, or 5, 
instead of always having 3), allow functions to be called like macros 
from within the scene file, and to extend the function language with 
loops, variables, and conditionals(there is already an if() function, 
but a slightly different syntax could be useful).

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Francois Dispot
Subject: Re: Step function
Date: 22 Aug 2000 19:25:11
Message: <39A30BD5.5E049847@club-internet.fr>
Chris Huff wrote:
> 

> I think the best way to do things would be to extend functions to have
> variable numbers of parameters(so you could just have 1 parameter, or 5,
> instead of always having 3), allow functions to be called like macros
> from within the scene file, and to extend the function language with
> loops, variables, and conditionals(there is already an if() function,
> but a slightly different syntax could be useful).

Being able to call finctions would be great, and would also suppress the
need for texture or pigment evaluation...
About the "if" function, it could also be possible to have something
like the well-known cryptic a?b:c syntax.
Adding local variables and loops would probably make things quite
different. Could you elaborate on a possible syntax? Did you think about
some lisp-like or RPN (a la PostScript) method?

-- 

      __  __ __  __  _
|  | /  \  /  / |_  /  |/
\/\/ \__/ /_ /_ |__ \_ |\


Post a reply to this message

Goto Latest 10 Messages Next 7 Messages >>>

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