POV-Ray : Newsgroups : povray.general : Array? Server Time
31 Oct 2024 14:09:01 EDT (-0400)
  Array? (Message 1 to 7 of 7)  
From: Bill DeWitt
Subject: Array?
Date: 10 Mar 2000 08:46:38
Message: <38c8fcbe@news.povray.org>
Is there any further information on arrays in POV (besides the docs)?
Specifically I would like to see ways of declaring array elements
mathematically rather than manually. Perhaps in loops or with a formula.


Post a reply to this message

From: Margus Ramst
Subject: Re: Array?
Date: 10 Mar 2000 08:57:44
Message: <38C8FFC7.E052DD8C@peak.edu.ee>
Bill DeWitt wrote:
> 
> Is there any further information on arrays in POV (besides the docs)?
> Specifically I would like to see ways of declaring array elements
> mathematically rather than manually. Perhaps in loops or with a formula.

Not sure what you mean, but here's an examlpe of what I'd call automatic
declaration:

#declare A=array[100]
#declare N=dimension_size(A,1); //Auto get the number of elements
#declare C=0;
#while(C<N)
  #declare A[C]=1;
  #declare C=C+1;
#end

This automatically initializes all array elements to 1.
You can of course replace 1 with an arbitrary formula etc etc.

Margus


Post a reply to this message

From: Bill DeWitt
Subject: Re: Array?
Date: 10 Mar 2000 13:10:25
Message: <38c93a91@news.povray.org>
"Margus Ramst" <mar### [at] peakeduee> wrote :
>
> #declare A=array[100]
> #declare N=dimension_size(A,1); file://Auto get the number of elements
> #declare C=0;
> #while(C<N)
>   #declare A[C]=1;
>   #declare C=C+1;
> #end
>

    This is more or less what I was doing, I just wondered if there was
anything else to know. I hadn't got the dimension_size thing though, Thanks!


Post a reply to this message

From: Ken
Subject: Re: Array?
Date: 10 Mar 2000 13:22:18
Message: <38C93DE2.2E56417B@pacbell.net>
Bill DeWitt wrote:
> 
> "Margus Ramst" <mar### [at] peakeduee> wrote :
> >
> > #declare A=array[100]
> > #declare N=dimension_size(A,1); file://Auto get the number of elements
> > #declare C=0;
> > #while(C<N)
> >   #declare A[C]=1;
> >   #declare C=C+1;
> > #end
> >
> 
>     This is more or less what I was doing, I just wondered if there was
> anything else to know. I hadn't got the dimension_size thing though, Thanks!

 I was messing with this a few months ago trying to sort irregular shaped
shingles on a roof. I resorted to storing and retrieving from an array. It
looks a bit like the example that Margus showed.

#declare Num = 20;
#declare MyArray = array[Num];
#declare i = 0;
  #while (i < num)
     #declare MyArray[i] = i;
     #declare i = i + 1;
  #end

this stores the current value of i into the array at each position (so
MyArray[5] = 5) to get them out, simply do something like the following

#declare i = 0;
#declare Sum = 0;
#while (i < num)
   #declare Sum = Sum + MyArray[i];
   #declare i = i + 1;   
#end



-- 
Ken Tyler -  1300+ Povray, Graphics, 3D Rendering, and Raytracing Links:
http://home.pacbell.net/tylereng/index.html http://www.povray.org/links/


Post a reply to this message

From: Bill DeWitt
Subject: Re: Array?
Date: 10 Mar 2000 13:25:43
Message: <38c93e27@news.povray.org>
"Bill DeWitt" <the### [at] earthlinknet> wrote :
>
>     This is more or less what I was doing, I just wondered if there was
> anything else to know. I hadn't got the dimension_size thing though,
Thanks!
>

    I should probably explain more. I was using this to preload an array for
Chris Colfax's spline include, and I got to the point of wondering why, if I
was going to use a formula for filling the spline macro, didn't I just use
the formula to position the object?

    The answer is, of course, at my level of knowledge, that there -is- no
reason not to... unless there was something I could learn that might give me
a reason.

    Otherwise I will just use the macro to make splines points that cannot
be gotten by simple formulas.


Post a reply to this message

From: Chris Colefax
Subject: Re: Array?
Date: 12 Mar 2000 17:29:46
Message: <38cc1a5a@news.povray.org>
Bill DeWitt <the### [at] earthlinknet> wrote:
>     I should probably explain more. I was using this to preload an array
for
> Chris Colfax's spline include, and I got to the point of wondering why, if
I
> was going to use a formula for filling the spline macro, didn't I just use
> the formula to position the object?
>
>     The answer is, of course, at my level of knowledge, that there -is- no
> reason not to... unless there was something I could learn that might give
me
> a reason.
>
>     Otherwise I will just use the macro to make splines points that cannot
> be gotten by simple formulas.

If your formula is time-dependent then you should probably use it
explicitly, e.g.:

   object {MyObject
      translate <sin(4*pi*clock), cos(16*pi*clock), pow(clock, 2)>*<3, 1,
10>
      }

However, what this doesn't give you is the automatic direction changes and
banking that the Spline Macros calculate.  I do have the workings of a
POV-Ray Motion System that will operate in a similar way to the spline
macros, but allow other mathematically defined paths (and path modifiers),
e.g. you could specify a spline, to which you could add a loop, and a wave,
or an orbit with a bounce, or a spiral with a twist, or a combination of the
whole lot!

For irregular paths, though, I still believe that cubic interpolating
splines are the most suitable option, and the methods Margus and Ken
provided should work fine (particularly, say, when you want a mathematical
path which you want to make irregular by adding random amounts to certain
points, without having the path jump about randomly).


Post a reply to this message

From: Johannes Hubert
Subject: Re: Array?
Date: 12 Mar 2000 19:01:07
Message: <38cc2fc3@news.povray.org>
"Ken" <tyl### [at] pacbellnet> wrote in message
news:38C93DE2.2E56417B@pacbell.net...
>
> this stores the current value of i into the array at each position (so
> MyArray[5] = 5) to get them out, simply do something like the
following
>
> #declare i = 0;
> #declare Sum = 0;
> #while (i < num)
>    #declare Sum = Sum + MyArray[i];
>    #declare i = i + 1;
> #end


Hmm, I don't get it:

If "MyArray[i]" always has the value "i", why then use the array in the
first place? Simply substituting "i" has the same effect, hasn't it?

after all: "MyArray[i]" equals "i" - they are equivalent, so you can
rewrite your code without the array:

#declare i = 0;
#declare Sum = 0;
#while (i < num)
   #declare Sum = Sum + i;
   #declare i = i + 1;
#end

(I am assuming that this is just a trivial example, because if you
really were after the sum, you wouldn't use a loop like that but would
use a mathematical formula instead, wouldn't you? Sum = num/2 * (num+1))

Johannes.


Post a reply to this message

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