POV-Ray : Newsgroups : povray.general : Array and vector functions? Server Time
7 Oct 2025 00:33:40 EDT (-0400)
  Array and vector functions? (Message 1 to 6 of 6)  
From: Ilya Razmanov
Subject: Array and vector functions?
Date: 3 Oct 2025 15:24:59
Message: <68e0230b$1@news.povray.org>
Greetings sentients,

do I understand it correctly that POV-Ray does not have array functions 
(meaning I can neither pass an array as argument nor receive it as a 
result), and vector functions are so limited that practically aren't 
worth mentioning?

I have a weird idea of turning my POV-Ray Mosaic

https://dnyarri.github.io/povzaika.html

into something even more unhuman. Currently primitive attributes are 
controlled by source pixel brightness; I'm thinking of making it 
controlled by arbitrary function of color and coordinates (yes, 
something like "Xaos Tools" "Paint Alchemy" Photoshop plugin, but for 
3D). Not sure it's a good idea but why not to try somedays. For that, I 
need some suitable form of passing arguments/results in a packed form, 
to avoid turning all this into something obscure and cabbalistic.

-- 
Ilyich the Toad
https://dnyarri.github.io/


Post a reply to this message

From: Bald Eagle
Subject: Re: Array and vector functions?
Date: 3 Oct 2025 15:50:00
Message: <web.68e02838c4b39641e2c47eda25979125@news.povray.org>
Ilya Razmanov <ily### [at] gmailcom> wrote:
> Greetings sentients,
>
> do I understand it correctly that POV-Ray does not have array functions
> (meaning I can neither pass an array as argument nor receive it as a
> result), and vector functions are so limited that practically aren't
> worth mentioning?

You are correct in that they do not exist as inbuilt functions

The best we have is

https://wiki.povray.org/content/Reference:Function

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 transforms return a three component vector, while 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.

Depending on what you want to specifically do, there might possibly be a
workaround.

- BE


Post a reply to this message

From: Ilya Razmanov
Subject: Re: Array and vector functions?
Date: 4 Oct 2025 06:13:14
Message: <68e0f33a@news.povray.org>
On 03.10.2025 22:47, Bald Eagle wrote:
> 
> You are correct in that they do not exist as inbuilt functions
> 

(sighing like an angry snake) Ok, surely I can try transmitting 
arguments in unpacked form like function(array[0], array[1], array[2], 
etc). Once upon a time I even wrote function with 13 named arguments 
(for my Scale3xSFX implementation), but at list I didn't have to unpack 
them every time since they were named already...

-- 
Ilyich the Toad
https://dnyarri.github.io/


Post a reply to this message

From: jr
Subject: Re: Array and vector functions?
Date: 4 Oct 2025 08:00:00
Message: <web.68e10b7ac4b396416ddd22546cde94f1@news.povray.org>
hi,

Ilya Razmanov <ily### [at] gmailcom> wrote:
> On 03.10.2025 22:47, Bald Eagle wrote:
> > You are correct in that they do not exist as inbuilt functions
> (sighing like an angry snake) Ok, surely I can try transmitting
> arguments in unpacked form like function(array[0], array[1], array[2],
> etc). ...

if you're not "averse", you could perhaps use simple list/queue macros; eg
<drive.google.com/file/d/1-lISncj8_qJQsjXR2TclUc67Whv-HmZL/view?usp=sharing>


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Array and vector functions?
Date: 4 Oct 2025 11:00:00
Message: <web.68e13664c4b396411f9dae3025979125@news.povray.org>
Ilya Razmanov <ily### [at] gmailcom> wrote:

> (sighing like an angry snake)

I will join you in the chorus.

> Ok, surely I can try transmitting
> arguments in unpacked form like function(array[0], array[1], array[2],
> etc).

You can, and can more easily do so using a loop.
So, write a macro to loop through all of your array indices, and that will work
just fine.
The only thing is, you only get to define that function with it's current array
values ONCE.   Because the function gets defined at parse time and cannot be
changed during render time.

> Once upon a time I even wrote function with 13 named arguments
> (for my Scale3xSFX implementation), but at list I didn't have to unpack
> them every time since they were named already...

Like I said, there are workarounds.
I needed something like this once or twice, and you can do a few interesting
things.
First, you can write a function that allows you to change which parts of the
array that use so that you're not constantly using them all.
Fn=function (N) { select (N, 0, 1, 0) * Array [1] + ....}
So if you write a function where the zeroes land on the array elements that you
want, then those are the only ones multiplied by 1.

You can also write spline functions.

WFP has experiments with using image_maps as a way to sort of store values in an
"array"



- BE


Post a reply to this message

From: Bald Eagle
Subject: Re: Array and vector functions?
Date: 4 Oct 2025 11:25:00
Message: <web.68e13bcfc4b396411f9dae3025979125@news.povray.org>
I wrote this back in 2022 to play with this sort of thing.

I think that kurtz le pirate also wrote something along these lines once.
http://news.povray.org/povray.general/thread/%3C6580562c%241%40news.povray.org%3E/?ttop=445919&toff=100

Hope these ideas help.

- BW


Post a reply to this message


Attachments:
Download 'lagrangepolynomialinterpolation.pov.txt' (7 KB)

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