POV-Ray : Newsgroups : povray.general : Function woes Server Time
16 Nov 2024 19:19:26 EST (-0500)
  Function woes (Message 1 to 5 of 5)  
From: Martin Magnusson
Subject: Function woes
Date: 16 Sep 2003 11:47:27
Message: <3f67308f$1@news.povray.org>
Can anybody please tell me what's wrong with the following code? POV 
stops at the "<" and says that it expected an operand instead. How else 
can I measure the distance between two points?

#declare Gauss =
   function( x, y, z, Centre, Spread ) {
     exp( vlength( <x, y, z> - Centre ) / 2*pow( Spread, 2 ) )
   }

/ martin


Post a reply to this message

From: ABX
Subject: Re: Function woes
Date: 16 Sep 2003 11:55:30
Message: <r8cemv4vmt4baukikc4r6c54p56hkj7e9q@4ax.com>
On Tue, 16 Sep 2003 17:47:26 +0200, Martin Magnusson
<lov### [at] frustratedhousewiveszzncom> wrote:
> Can anybody please tell me what's wrong with the following code?

You used not allowed syntax.

> POV stops at the "<" and says that it expected an operand instead.

And this is according to function syntax listed in documentation. If you could
look into syntax frame at http://www.povray.org/documentation/view/140/ there
is not vector mentioned in allowed _function_ syntax.

> How else can I measure the distance between two points?

Using f_r() function: f_r(X1-X2,Y1-Y2,Z1-Z2).

ABX


Post a reply to this message

From: Martin Magnusson
Subject: Re: Function woes
Date: 17 Sep 2003 04:14:21
Message: <3f6817dd$1@news.povray.org>
OK, thanks. Now I have other problems though...

First, I declare a function like this:

#declare Gauss =
function(X1, Z1, S) {
   exp( -1 * ( pow(x-X1, 2) + pow(z-Z1, 2) ) / (2*pow(S, 2)) )
}

Then I'd like to use it in an isosurface, but it gives unexpected 
results. Using the macro below does what I want. I would expect the two 
lines inside the function{} to be equal, but when using the one that is 
commented out here, I just get a flat surface. Can somebody tell me why?

#macro Node( Centre_x, Centre_z, Spread )
isosurface
{
   function {
     //y - Gauss( Centre_x, Centre_z, Spread )
     y - exp( -1 * ( pow(x-Centre_x, 2) + pow(z-Centre_z, 2) ) / 
(2*pow(Spread, 2)) )
   }
   contained_by {
     sphere{ <Centre_x, 0, Centre_z>, Spread*5 }
   }
   pigment{ rgbt < 1, 0, 0, 0.5> }
}
#end

camera
{
   location <3, 8, -10>
   look_at <0, 1, 0>
}

light_source
{
   <10000, 10000, -10000>
   rgb 1
}

Node( 0, 0, 1 )


Post a reply to this message

From: ABX
Subject: Re: Function woes
Date: 17 Sep 2003 04:41:07
Message: <987gmv88j224bu0ajmhqc3dr3s5pclbbuc@4ax.com>
On Wed, 17 Sep 2003 10:14:23 +0200, Martin Magnusson
<lov### [at] frustratedhousewiveszzncom> wrote:
> Then I'd like to use it in an isosurface, but it gives unexpected 
> results. Using the macro below does what I want. I would expect the two 
> lines inside the function{} to be equal, but when using the one that is 
> commented out here, I just get a flat surface. Can somebody tell me why?

You did wrong assumption that x flows magically from isosurface to Gauss
function. x used within function code is basically reference to first
parameter of _current_ function, y is second one, z is third one. So you have
to write your code as follow:

#declare Gauss =
function(x,y,z,X1, Z1, S) {
   exp( -1 * ( pow(x-X1, 2) + pow(z-Z1, 2) ) / (2*pow(S, 2)) )
}

#macro Node( Centre_x, Centre_z, Spread )
isosurface
{
   function {
     y - Gauss( x,y,z, Centre_x, Centre_z, Spread )
   }
   contained_by {
     sphere{ <Centre_x, 0, Centre_z>, Spread*5 }
   }
   pigment{ rgbt < 1, 0, 0, 0.5> }
}
#end

I did not checked this but should work now as expected.

ABX


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Function woes
Date: 17 Sep 2003 08:27:35
Message: <3f685337@news.povray.org>
In article <987gmv88j224bu0ajmhqc3dr3s5pclbbuc@4ax.com> , ABX 
<abx### [at] abxartpl>  wrote:

> You did wrong assumption that x flows magically from isosurface to Gauss
> function. x used within function code is basically reference to first
> parameter of _current_ function, y is second one, z is third one.

Actually, this isn't correct.  x, y and z can appear anywhere in the
parameter list.  However, they also exist when they are not defined in the
parameter list.  In that case, they will be 0.0 and thus constant.

    Thorsten

____________________________________________________
Thorsten Froehlich
e-mail: mac### [at] povrayorg

I am a member of the POV-Ray Team.
Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

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