POV-Ray : Newsgroups : povray.text.tutorials : ARRAYS: More possibilities then the manual tells us Server Time
13 Oct 2024 06:54:26 EDT (-0400)
  ARRAYS: More possibilities then the manual tells us (Message 1 to 4 of 4)  
From: Jaap Frank
Subject: ARRAYS: More possibilities then the manual tells us
Date: 14 Jul 2003 20:02:35
Message: <3f13449b$1@news.povray.org>
Hi,

this is a small explanation of advanced use of arrays.
In the manual you will find several limitations in using
arrays, but you can circumvent this.

If you declare a multi-dimensional array the normal way,
    #declare A = array[2][2][2]
you can't take a single dimension from it:
    #declare B = A[2][2]    // this gives an error

Also you can't put different things in it. Once you have
initiated one entry with some kind of variable type, all the
other entries have to be of the same kind.
But, ... you can put everything what you like in it,
arrays too!

If you declare an array, you give it a name:
    #declare Times = array[2]
You then put some values in it:
    #declare Times[0] = 23.24;
    #declare Times[1] = 12.57;
Compare this with:
    #declare Times0 = 23.24;
    #declare Times1 = 12.57;
Look at it the following way:
It looks as if POVray uses Times[0] and Times[1]
as a name for a variable.
You can then imagine that you can put everything in it.
Only the way the names are stored in memory is different
for arrays.

Here are two examples:

If you want a very high dimensional array, this can be done.
Further you can extract a peace of an array.

// --------- Start of code ----------------------------------------
#declare A = array[2][2][2]
#declare B = array[2][2][2]
#declare C = array[2][2][2]
//    Connect the arrays
#declare B[0][0][0] = C
#declare A[0][0][0] = B
//    Initiate something
#declare A[0][0][0][0][0][0][0][0][0]=0.345;
//    Extract a piece
#declare D = A[0][0][0][0][0][0]

//#declare E = A[0][0][0][0][0] //<-- this gives an error of coarse

#debug str(A[0][0][0][0][0][0][0][0][0],5,3)
// -------   End of code -----------------------------------------

Amazingly POV does not get confused!!

This way it is also possible to put different things into one total array.
In one subarray you can put objects and in other subarrays some
different kind of variables.
So you can build your own multi variable type of array.

// --------- Start of code ----------------------------------------
#declare Obj = 0;
#declare Var = 1;
#declare Tex = 2;
#declare Total = array[3]

// Make the subarrays
#declare Objects = array[2]
#declare Vars = array[4]
  {0,1, -1, +1}
#declare Textur = array[2]
  {pigment{color rgb <0,1,0>},
   pigment{color rgbt <1,1,1,0.4>} }

// Connect everything
#declare Total[Obj] = Objects
#declare Total[Tex] = Textur
#declare Total[Var] = Vars

// Use it:
#declare  Total[Obj][0] =
  sphere{ Total[Var][0], Total[Var][1]
          texture { Total[Tex][0]}}
#declare  Total[Obj][1] =
  box{    Total[Var][2], Total[Var][3]
          texture { Total[Tex][1]}}

// Show it:
object {Total[Obj][0]}
object {Total[Obj][1]}

light_source {
  <-20, 40, -20>
  color rgb <1,1,1> }
camera {
  location <0,0,-3>
  look_at 0 }

// -------   End of code -----------------------------------------

Why is this useful?
You can give a macro in one name (Total) a couple
of objects and all his variables and let it do something
with it.
For instance: the macro can reach the textures and
can change them.

I hope someone can use this.

Jaap Frank


Post a reply to this message

From: Steve Shelby
Subject: Re: ARRAYS: More possibilities then the manual tells us
Date: 24 Sep 2003 10:45:01
Message: <web.3f71acc72793170fbea25d220@news.povray.org>
Jaap Frank wrote:
>Hi,
>
>this is a small explanation of advanced use of arrays.
>In the manual you will find several limitations in using
>arrays, but you can circumvent this.
>
Jaap,
Can this method be used to transform an array over time, that is add a clock
value ot an array? For example, I have a spline defined by an array:
#declare MySpline = create_spline (array [6] {<-2, .6, 0>,<-1.2, .6,
0>,<-.4,-.6,0>,<.4,-.6,0>,<1.2,.6,0>,<2,.6,0>}
Say I want to transform the spline in an animation to this:
#declare MySpline = create_spline (array [6] {<-2, .1, 0>,<-1.2, .1,
0>,<-.4,-.0,0>,<.4,-.0,0>,<-1.2,0,0>,<2,0,0>}
Can that be done?
Thank you,
Steve Shelby
she### [at] earthlinknet


Post a reply to this message

From: Kene
Subject: Re: ARRAYS: More possibilities then the manual tells us
Date: 21 Sep 2009 08:30:01
Message: <web.4ab771232793170f772dd76f0@news.povray.org>
> // --------- Start of code ----------------------------------------
> #declare Obj = 0;
> #declare Var = 1;
> #declare Tex = 2;
> #declare Total = array[3]
>
> // Make the subarrays
> #declare Objects = array[2]
> #declare Vars = array[4]
>   {0,1, -1, +1}
> #declare Textur = array[2]
>   {pigment{color rgb <0,1,0>},
>    pigment{color rgbt <1,1,1,0.4>} }
>
> // Connect everything
> #declare Total[Obj] = Objects
> #declare Total[Tex] = Textur
> #declare Total[Var] = Vars
>
> // Use it:
> #declare  Total[Obj][0] =
>   sphere{ Total[Var][0], Total[Var][1]
>           texture { Total[Tex][0]}}
> #declare  Total[Obj][1] =
>   box{    Total[Var][2], Total[Var][3]
>           texture { Total[Tex][1]}}
>
> // Show it:
> object {Total[Obj][0]}
> object {Total[Obj][1]}
>
> light_source {
>   <-20, 40, -20>
>   color rgb <1,1,1> }
> camera {
>   location <0,0,-3>
>   look_at 0 }
>
> // -------   End of code -----------------------------------------
>
> Why is this useful?
> You can give a macro in one name (Total) a couple
> of objects and all his variables and let it do something
> with it.
> For instance: the macro can reach the textures and
> can change them.
>
> I hope someone can use this.
>
> Jaap Frank

This is a very good explanation of arrays to me and I have been searching the
documentation and the net. It is making things very exciting for me. Thanks
Jaap!


Post a reply to this message

From: clipka
Subject: Re: ARRAYS: More possibilities then the manual tells us
Date: 21 Sep 2009 10:00:27
Message: <4ab786fb$1@news.povray.org>
My! I was always thoroughly convinced that you can't store arrays in 
arrays...

This is precious gold man!

Also note that this allows to store multiple elements of different type 
in one array, by wrapping each in another 1-element array.


Post a reply to this message

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