POV-Ray : Newsgroups : povray.advanced-users : Array irritation. Server Time
2 Nov 2024 03:14:43 EDT (-0400)
  Array irritation. (Message 1 to 10 of 27)  
Goto Latest 10 Messages Next 10 Messages >>>
From: ian mcdonald
Subject: Array irritation.
Date: 17 Oct 2000 12:35:46
Message: <39ec7fe2@news.povray.org>
Hello,

I am attempting to learn the use of Arrrays for positioning of objects.
It works, a little.

I have a [3][10] array. I wish to use all data therein by counting down with
while loops. I wish for the loop to first use all 10 values from 3, then all
ten from 2 and lastly all 10 from 1.

I can't make code to do this. I am now very irritated.

The data in the array is controlled by two while loops that surround all of
this; this part works.

It seems that no computer/programming language of any sort works as I think
it should, I can't do as I wish with arrays, loops or etc.. Everything is
too dependant.

My main problem is creation of data in a loop, storage of this data, and
retrieval for usage outside the loops the data was generated with.

I'm not sure my sourcecode will help any, but I'll post it if needed.

Suggestions?

ian


Post a reply to this message

From: Michael Andrews
Subject: Re: Array irritation.
Date: 17 Oct 2000 14:25:20
Message: <39EC99EF.283EA738@reading.ac.uk>
ian mcdonald wrote:
> 
> Hello,
> 
> I am attempting to learn the use of Arrrays for positioning of objects.
> It works, a little.
> 
> I have a [3][10] array. I wish to use all data therein by counting down with
> while loops. I wish for the loop to first use all 10 values from 3, then all
> ten from 2 and lastly all 10 from 1.
> 
> I can't make code to do this. I am now very irritated.
> 
> The data in the array is controlled by two while loops that surround all of
> this; this part works.
> 
> It seems that no computer/programming language of any sort works as I think
> it should, I can't do as I wish with arrays, loops or etc.. Everything is
> too dependant.
> 
> My main problem is creation of data in a loop, storage of this data, and
> retrieval for usage outside the loops the data was generated with.
> 
> I'm not sure my sourcecode will help any, but I'll post it if needed.
> 
> Suggestions?
> 
> ian

// to declare the array
#declare MyArray = array[3][10] // remember :- indices [0..2][0..9]

// to initialise the array
#declare Index1 = 0; #while (Index1 < 3)
  #declare Index2 = 0; #while (index2 < 10)
    #declare MyAray[Index1][Index2] = Whatever_You_Want_To_Put;
  #declare Index2 = Index2 + 1; #end
#declare Index1 = Index1 + 1; #end

// to read the array as specified
#declare Index1 = 2; #while (Index1 >= 0)
  #declare Index2 = 9; #while (Index2 >= 0)
    #declare My_Retrieved_Value = My_Array[Index1][Index2];
  #declare Index2 = Index2 - 1; #end
#declare Index1 = Index1 - 1; #end

Hope this helps,
	Mike Andrews.


Post a reply to this message

From: Rune
Subject: Re: Array irritation.
Date: 17 Oct 2000 15:02:30
Message: <39eca246@news.povray.org>
Source code might help (try to simplify it before posting if possible).

It would probably also help with a more precise description of what you want
to do, and what the problem is.

Greetings,

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated October 9)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: David Wilkinson
Subject: Re: Array irritation.
Date: 17 Oct 2000 15:36:33
Message: <giapusk6m2qkq24ifm65osleibsse19b70@4ax.com>
On Tue, 17 Oct 2000 12:36:23 -0700, "ian mcdonald" <ian### [at] hotmailcom>
wrote:

>Hello,
>
>I am attempting to learn the use of Arrrays for positioning of objects.
>It works, a little.
>
>I have a [3][10] array. I wish to use all data therein by counting down with
>while loops. I wish for the loop to first use all 10 values from 3, then all
>ten from 2 and lastly all 10 from 1.
>
>I can't make code to do this. I am now very irritated.
>
>The data in the array is controlled by two while loops that surround all of
>this; this part works.
>
>It seems that no computer/programming language of any sort works as I think
>it should, I can't do as I wish with arrays, loops or etc.. Everything is
>too dependant.
>
>My main problem is creation of data in a loop, storage of this data, and
>retrieval for usage outside the loops the data was generated with.
>
>I'm not sure my sourcecode will help any, but I'll post it if needed.
>
>Suggestions?
>
>ian
>

#declare A1=array[3][10]
   {
      {"1","s","t"," "," ","A","r","r","a","y"}
      {"2","n","d"," "," ","A","r","r","a","y"}
      {"3","r","d"," "," ","A","r","r","a","y"}
    }                  

#declare Rowcount = 2;
#declare Colcount = 0;

#while (Rowcount>-1)
  #debug "\n"
   #while (Colcount<10)
      #debug concat(A1[Rowcount][Colcount])
      #declare Colcount=Colcount+1;
   #end
   #debug "\n"
   #declare Colcount=0;    
  #declare Rowcount = Rowcount-1;
#end
----------------------
dav### [at] hamiltonitecom
http://hamiltonite.com/


Post a reply to this message

From: David Fontaine
Subject: Re: Array irritation.
Date: 17 Oct 2000 17:55:17
Message: <39ECC842.38398C3C@faricy.net>
David Wilkinson wrote:

>       #debug concat(A1[Rowcount][Colcount])

Why concatenate one string? :)

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Warp
Subject: Re: Array irritation.
Date: 18 Oct 2000 05:24:36
Message: <39ed6c54@news.povray.org>
David Fontaine <dav### [at] faricynet> wrote:
: Why concatenate one string? :)

  I have seen this written in C:

double x = (double)(1.0);

  I'm just wondering why this wasn't enough:

double x = 1;

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Pabs
Subject: Re: Array irritation.
Date: 18 Oct 2000 05:43:21
Message: <39ED7102.9C9BD2E4@hotmail.com>
Warp wrote:

>   I have seen this written in C:
> double x = (double)(1.0);

<chuckle> Who wrote that </chuckle> :)))
As far as I know most compilers convert constants at compile time.

>   I'm just wondering why this wasn't enough:
> double x = 1;

Maybe they thought that the compiler would insert instructions to convert an
int to a double at runtime, unlikely though it is?


--
Bye
Pabs


Post a reply to this message

From: David Wilkinson
Subject: Re: Array irritation.
Date: 18 Oct 2000 06:01:06
Message: <h7tqus8sek4qu6ahfcq371v008q9nmunsd@4ax.com>
On Tue, 17 Oct 2000 16:44:34 -0500, in povray.advanced-users you wrote:

>David Wilkinson wrote:
>
>>       #debug concat(A1[Rowcount][Colcount])
>
>Why concatenate one string? :)

You're right David, concatenation is  absolutely redundant, although it does no
harm in this instance.  It's a good example of how bugs arise when you are
re-using code and don't think it through carefully enough :-)
----------------------
dav### [at] hamiltonitecom
http://hamiltonite.com/


Post a reply to this message

From: Warp
Subject: Re: Array irritation.
Date: 18 Oct 2000 07:21:52
Message: <39ed87d0@news.povray.org>
Pabs <pab### [at] hotmailcom> wrote:
: Maybe they thought that the compiler would insert instructions to convert an
: int to a double at runtime, unlikely though it is?

  Current compilers can do lots of optimizations. Some of them are even
surprising.
  I was once debugging this kind of code (in C++):

int main()
{
    int i = 1;
    cout << i << endl;
}

  It was very strange since the debugger didn't execute the 'int i=1;' line
at all and it didn't even show the value of the variable 'i'.
  I thought that "what the **** is wrong with this?" until I realized that
I had all compile optimizations turned on. I turned them off and then the
debugging worked as expected.

  What happened was that the optimizations made by the compiler had converted
the above code to one equivalent to this:

int main()
{
    cout << 1 << endl;
}

  The compiler had completely wiped out the 'i' variable and that's why the
debugging looked so strange :)

  Btw, too many times I see code like this:

a = var>>2;  // equivalent to: a = var/4;

  The idea is that shifting is usually a lot faster than dividing so people
optimize by hand in this way.
  This, however, is nowadays made in vain and makes only the code harder to
read. I'd say that every current C(++) compiler can internally optimize this:

a = var/4;

to this:

a = var>>2;

so it's not necessary to do it by hand.

  Sometimes the optimizations made by a compiler are just marvelous. For
example most implementations of gcc convert this kind of code:

(var << 5)|(var >> 27);

(supposing that 'var' is an unsigned int of size 32 bits)
to this (in assembler):

rol [Variable], 5

(ie. "rotate the value [Variable] to the left 5 positions").

  In C there's no operation to rotate values like in most assemblers so you
have to do it with two shifts and one or.
  It's just incredible how the compiler can figure out that what you are
actually trying to do is a rotation and compiles the rather complex command
into one rotation assembler instruction (instead of two shifts and an or).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Lutz Kretzschmar
Subject: Re: Array irritation.
Date: 18 Oct 2000 10:27:59
Message: <jqcrus8b4ff8c7fg4st3a97f6lqpnsaagr@4ax.com>
Hi Warp, you recently wrote in povray.advanced-users:

>   I have seen this written in C:
> 
> double x = (double)(1.0);
> 
>   I'm just wondering why this wasn't enough:
> 
> double x = 1;

Maybe the programmer previous written that line as

DBL x = (DBL) 1.0;

and had DBL defined as float, but didn't want to add the 'f' onto the
1.0.

Then he did a global search and replace and replaced DBL with double?

- Lutz
  email : lut### [at] stmuccom
  Web   : http://www.stmuc.com/moray


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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