POV-Ray : Newsgroups : povray.advanced-users : Using vectors in functions Server Time
22 Feb 2025 16:05:20 EST (-0500)
  Using vectors in functions (Message 1 to 2 of 2)  
From: Bald Eagle
Subject: Using vectors in functions
Date: 17 Feb 2025 14:35:00
Message: <web.67b38f32de1c85dd1f9dae3025979125@news.povray.org>
So, I was going to spend some time converting some cool Shadertoy code into SDL,
and I was annoyed (as usual) that I couldn't do certain things.
I specifically wanted to create a function that performed a rotational matrix
transform on a vector given a variable angle.

Well, the function VM doesn't allow transform functions to take user-defined
arguments ("parameter names").
And we all "know" that you can't use vectors in functions.
Hell you can't even use vector dot-notation in functions.

2.2.1.6.4 Declaring User-Defined Vector Functions
Right now you may only declare vector functions using one of the special
function types. Supported types are transform and spline functions. For example:

 #declare foo = function {
   transform {
     rotate <90, 0, 0>
     scale 4
   }
 }

 #declare myvector = foo(4, 3, 7);

 #declare foo2 = function {
   spline {
     linear_spline
     0.0, <0,0,0>
     0.5, <1,0,0>
     1.0, <0,0,0>
   }
 }

 #declare myvector2 = foo2(0.7);

Function splines take the vector size into account. That is, a function
containing a spline with five components will also return a five component
vector (aka a color), a function containing a spline with two components will
only return a two component vector and so on.

Note: the number of parameters of special function types is determined
automatically, so you do not need to specify parameter names.


But, me being ME, that got a few things wiggling up in the ole' brain, and I
started to follow a few tenuous ides.
Round and round I went in circles, trying to make vector functions work, and
trying to bridge the gap between the SDL parser and the function VM.

And I have mostly done that as you'll see in the attached file.

The only thing that would make this FULLY functional would be to find a way to
shoehorn the actual vector into an argument allowable by some sort of special
function syntax.

But I hope that this inspires people to start playing around with the functions,
macros, reading the docs, exploring the various include files in the
distribution, and doing some experiments that reveal things that we can do (but
were told we couldn't).

- Bill "Bald Eagle" Walker


Post a reply to this message


Attachments:
Download 'functionselectvectorcomponent.pov.txt' (4 KB)

From: Tor Olav Kristensen
Subject: Re: Using vectors in functions
Date: 17 Feb 2025 18:20:00
Message: <web.67b3c3ee6aeda660737cc36e89db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I was going to spend some time converting some cool Shadertoy code into SDL,
> and I was annoyed (as usual) that I couldn't do certain things.
> I specifically wanted to create a function that performed a rotational matrix
> transform on a vector given a variable angle.
>
> Well, the function VM doesn't allow transform functions to take user-defined
> arguments ("parameter names").
> And we all "know" that you can't use vectors in functions.
> Hell you can't even use vector dot-notation in functions.
>
> 2.2.1.6.4 Declaring User-Defined Vector Functions
> Right now you may only declare vector functions using one of the special
> function types. Supported types are transform and spline functions. For example:
>
>  #declare foo = function {
>    transform {
>      rotate <90, 0, 0>
>      scale 4
>    }
>  }
>
>  #declare myvector = foo(4, 3, 7);
>
>  #declare foo2 = function {
>    spline {
>      linear_spline
>      0.0, <0,0,0>
>      0.5, <1,0,0>
>      1.0, <0,0,0>
>    }
>  }
>
>  #declare myvector2 = foo2(0.7);
>
> Function splines take the vector size into account. That is, a function
> containing a spline with five components will also return a five component
> vector (aka a color), a function containing a spline with two components will
> only return a two component vector and so on.
>
> Note: the number of parameters of special function types is determined
> automatically, so you do not need to specify parameter names.
>
>
> But, me being ME, that got a few things wiggling up in the ole' brain, and I
> started to follow a few tenuous ides.
> Round and round I went in circles, trying to make vector functions work, and
> trying to bridge the gap between the SDL parser and the function VM.
>
> And I have mostly done that as you'll see in the attached file.
>
> The only thing that would make this FULLY functional would be to find a way to
> shoehorn the actual vector into an argument allowable by some sort of special
> function syntax.
>
> But I hope that this inspires people to start playing around with the functions,
> macros, reading the docs, exploring the various include files in the
> distribution, and doing some experiments that reveal things that we can do (but
> were told we couldn't).

Hi Bill

I once did some work on something similar. See this thread:

From: Tor Olav Kristensen
Subject: Visualizing vector fields with a single isosurface
Date: 2010-01-30 08:35:01
http://news.povray.org/povray.binaries.images/thread/%3Cweb.4b6434d658c2698ed6291f840%40news.povray.org%3E/

Here's my (not so good) try at an explanation of what is going on:

In this isosurface, a grid of rounded boxes are created with a function.
And each of the x, y and z arguments to this function are processed by
other functions that does inverse transformations to them. I.e.: For each
points (x, y, z) in space these "preprosessing functions" calculates a
transform to apply to the x, y, z values that are fed to the function
that creates the the grid of rounded boxes.

Also have a look at how the function created by the RotateXYZ_Function()
macro is used in these SDL files:

https://dataduppedings.no/subcube/POV-Ray/Isosurface-Rotated_Noise.txt
https://dataduppedings.no/subcube/POV-Ray/Isosurface-Cubic_Space_Division.txt

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

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