POV-Ray : Newsgroups : povray.general : function question Server Time
6 Aug 2024 12:26:53 EDT (-0400)
  function question (Message 1 to 10 of 16)  
Goto Latest 10 Messages Next 6 Messages >>>
From: Shay
Subject: function question
Date: 3 Apr 2002 16:20:36
Message: <3cab7224$1@news.povray.org>
Can I define a function that takes a float and returns a vector?
Something like this:

function Get_Vec {<x^2,x^3,x^4>}
Get_Vec (2) ------> <4,8,16>

Do I have to use a macro to accomplish this?

 -Shay


Post a reply to this message

From:
Subject: Re: function question
Date: 3 Apr 2002 16:24:26
Message: <dismau0b4okcpjbttn20s9pc7lhftp9smo@4ax.com>
On Wed, 3 Apr 2002 15:21:39 -0600, "Shay" <sah### [at] simcopartscom> wrote:
> Can I define a function that takes a float and returns a vector?

Not directly but there is possible workaround.

> Something like this:
> function Get_Vec {<x^2,x^3,x^4>}
> Get_Vec (2) ------> <4,8,16>
> Do I have to use a macro to accomplish this?

If it is called only at parse time then macro version could be simpler to code.

ABX


Post a reply to this message

From: JRG
Subject: Re: function question
Date: 3 Apr 2002 16:33:59
Message: <3cab7547@news.povray.org>
"Shay" wrote:
> Can I define a function that takes a float and returns a vector?

No.

> Something like this:
>
> function Get_Vec {<x^2,x^3,x^4>}
> Get_Vec (2) ------> <4,8,16>
>
> Do I have to use a macro to accomplish this?

Either that or something like:
#declare vec = <Get_VecX(2),Get_VecY(2),Get_VecZ(2)>;


--
Jonathan.

Home: http://digilander.iol.it/jrgpov


Post a reply to this message

From: Shay
Subject: Re: function question
Date: 3 Apr 2002 16:37:06
Message: <3cab7602@news.povray.org>
Thanks, guys. I'm going to have to time the workaround against a macro. I am
thinking of building combination fractal / 3D knots so speed is a very
important consideration.

 -Shay


Shay <sah### [at] simcopartscom> wrote in message
news:3cab7224$1@news.povray.org...


Post a reply to this message

From: JRG
Subject: Re: function question
Date: 3 Apr 2002 16:37:22
Message: <3cab7612@news.povray.org>

> On Wed, 3 Apr 2002 15:21:39 -0600, "Shay" <sah### [at] simcopartscom> wrote:
> > Can I define a function that takes a float and returns a vector?
>
> Not directly but there is possible workaround.

You mean some cyiptic code?

--
Jonathan.

Home: http://digilander.iol.it/jrgpov


Post a reply to this message

From:
Subject: Re: function question
Date: 3 Apr 2002 16:40:39
Message: <ljtmauofa469e877m395m9e19pl5fl8djj@4ax.com>
On Wed, 3 Apr 2002 23:36:43 +0200, "JRG" <jrg### [at] hotmailcom> wrote:
> > > Can I define a function that takes a float and returns a vector?
> >
> > Not directly but there is possible workaround.
>
> You mean some cyiptic code?

It depends what you mean as cyiptic.

ABX


Post a reply to this message

From: JRG
Subject: Re: function question
Date: 3 Apr 2002 16:43:15
Message: <3cab7773@news.povray.org>

> It depends what you mean as cyiptic.
>
> ABX

Oops, I meant "cryptic".

--
Jonathan.

Home: http://digilander.iol.it/jrgpov


Post a reply to this message

From:
Subject: Re: function question
Date: 3 Apr 2002 17:12:44
Message: <jltmaukpci64s7497l1qdr79asqpl6tpln@4ax.com>
On Wed, 3 Apr 2002 15:38:09 -0600, "Shay" <sah### [at] simcopartscom> wrote:
> Thanks, guys. I'm going to have to time the workaround against a macro. I am
> thinking of building combination fractal / 3D knots so speed is a very
> important consideration.

// at first you have to code functions for each component of your vector
// sample operations attached

#local f_X = function ( float ) { float };
#local f_Y = function ( float ) { float/2 };
#local f_Z = function ( float ) { float/3 };

// then you have to bound possible results
// bounding can be pretty large but remember about accuracy problem

#local X_Min = -10000;
#local X_Max = 2560;
#local Y_Min = 1000;
#local Y_Max = 1280;
#local Z_Min = 1000;
#local Z_Max = 3300;

// then you have to calculate ranges of coordinates

#local X_Range = X_Max - X_Min;
#local Y_Range = Y_Max - Y_Min;
#local Z_Range = Z_Max - Z_Min;

// now create pigment inside ranges
// our float is supposed to be at x coordinate position

#local P = pigment{
  average
  pigment_map{
    [
      1
      function { ( f_X(x) - X_Min ) / X_Range }
      color_map { [0 red 3*X_Min] [ 1 red 3*(X_Range+X_Min) ] }
    ]
    [
      1
      function { ( f_Y(x) - Y_Min ) / Y_Range }
      color_map { [0 green 3*Y_Min] [ 1 green 3*(Y_Range+Y_Min) ] }
    ]
    [
      1
      function { ( f_Z(x) - Z_Min ) / Z_Range }
      color_map { [0 blue 3*Z_Min] [ 1 blue 3*(Z_Range+Z_Min) ] }
    ]
  }
};

// now convert pigment to function

#local F=function{pigment{P}};

// finally call function putting float at x position and putting anything
// (for example 0) at x and y position

#local V = F(300,0,0);

// remember result is 5D vector (color) so before use as 3D recconvert it

#include "strings.inc"
#warning VStr( <V.x,V.y,V.z> )

// ABX
// I hope I will be considered as the father of this method ;-)


Post a reply to this message

From:
Subject: Re: function question
Date: 3 Apr 2002 17:16:19
Message: <0ovmauor2afad073nh0s42uhjjv5qqq2gg@4ax.com>
On Wed, 3 Apr 2002 23:42:36 +0200, "JRG" <jrg### [at] hotmailcom> wrote:
> Oops, I meant "cryptic".

It depends what you mean as cryptic.
Anyway code after moment in this thread so You'll see it is cryptic or not.

ABX


Post a reply to this message

From:
Subject: Re: function question
Date: 3 Apr 2002 17:21:02
Message: <vvvmaus0bvr1jq81bl52sdf4nsqvlvb6cm@4ax.com>

wrote:
> #local X_Min = -10000;
> #local X_Max = 2560;
> #local Y_Min = 1000;
> #local Y_Max = 1280;
> #local Z_Min = 1000;
> #local Z_Max = 3300;

should be rather

#local X_Min = -10000;
#local X_Max = 2560;
#local Y_Min = -1000;
#local Y_Max = 1280;
#local Z_Min = -100;
#local Z_Max = 3300;

ABX


Post a reply to this message

Goto Latest 10 Messages Next 6 Messages >>>

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