POV-Ray : Newsgroups : povray.general : Array with double #while Server Time
5 Nov 2024 13:23:15 EST (-0500)
  Array with double #while (Message 1 to 5 of 5)  
From: Grassblade
Subject: Array with double #while
Date: 6 Feb 2007 15:15:01
Message: <web.45c8e15a12d9160e802da7170@news.povray.org>
I'm working on matrix transformations using arrays, but nothing goes quite
as planned. The simplest example is transposing a 2d array:

////////////////////////////////////////////////////////////
#macro transp(array1)
     #local a1=dimension_size(array1,1);
     #local a2=dimension_size(array1,2);
     #local i=0;
     #local j=0;
     #declare temp1= array[a2][a1];
     #while (i<=a2-1)
           #while (j<=a1-1)
                  #declare temp1[i][j]=array1[j][i];
                  #local j=j+1;
           #end
           #local i=i+1;
     #end
#end

camera {location -8*z look_at 0}

light_source{<0,10,-10> rgb 1}

#declare ar1=array[3][2] {{1,0},{1,-1},{0,5}};
transp(ar1)
/////////////////////////////////////////////////////////////////

All good till now, I think, but when I try to visualise the result with the
following routine, I only get the first row. If I change the #while's in
the macro, so that i and j start from their highest values and go to 0,
only the last row is rendered. If I add a third dimension in the array,
only the values on a single spine are rendered. Any ideas on what I'm doing
wrong? I have
searched the newsgroup but I haven't seen many examples of nested #while
with arrays, so I'm inclined to think it's something to do with that. Pov
version is 3.61c for Windows.

///////////////////////////////////////////////////////////
#declare i1=0;
#declare j1=0;
union{
#while (i1<=dimension_size(temp1,1)-1)
      #while (j1<=dimension_size(temp1,2)-1)
             text{ttf "timrom.ttf"
                      str(temp1[i1][j1],1,0) 0.1,0 pigment {rgb 1}
              translate <(j1-1)*2,1-(i1-1),0>
              }
        #declare j1=j1+1;
        #end
    #declare i1=i1+1;
#end
}
//////////////////////////////////////////////////////////


Post a reply to this message

From: Tim Attwood
Subject: Re: Array with double #while
Date: 6 Feb 2007 16:09:34
Message: <45c8ee8e$1@news.povray.org>
You are making the same mistake twice...
The initial value in your inner nested while loops
need to be set every time the inner loop executes.
Like this:

#local A = from#;
#while (A <= to#)
   #local B = from#;
   #while (B <= to#)
      ... process
      #local B = B + step#;
   #end
   #local A = A + step#;
#end


Post a reply to this message

From: Warp
Subject: Re: Array with double #while
Date: 6 Feb 2007 17:08:30
Message: <45c8fc5e@news.povray.org>
Grassblade <nomail@nomail> wrote:
>      #local i=0;
>      #local j=0;
>      #declare temp1= array[a2][a1];
>      #while (i<=a2-1)
>            #while (j<=a1-1)

  When the execution gets to this point the second time, what do you
think the value of 'j' is?

-- 
                                                          - Warp


Post a reply to this message

From: Grassblade
Subject: Re: Array with double #while
Date: 8 Feb 2007 16:15:00
Message: <web.45cb9217806e8910cabcaa820@news.povray.org>
"Tim Attwood" <tim### [at] comcastnet> wrote:
> You are making the same mistake twice...
> The initial value in your inner nested while loops
> need to be set every time the inner loop executes.
> Like this:
>
> #local A = from#;
> #while (A <= to#)
>    #local B = from#;
>    #while (B <= to#)
>       ... process
>       #local B = B + step#;
>    #end
>    #local A = A + step#;
> #end
Pfft, what a silly mistake! Would you believe I twiddled my code looking for
whatever was messing my code up for over an hour?
Anyway, thanks. It's working as it should now.


Post a reply to this message

From: Grassblade
Subject: Re: Array with double #while
Date: 8 Feb 2007 16:15:00
Message: <web.45cb928d806e8910cabcaa820@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> Grassblade <nomail@nomail> wrote:
> >      #local i=0;
> >      #local j=0;
> >      #declare temp1= array[a2][a1];
> >      #while (i<=a2-1)
> >            #while (j<=a1-1)
>
>   When the execution gets to this point the second time, what do you
> think the value of 'j' is?
>
> --
>                                                           - Warp
Ehm, good point. <_<


Post a reply to this message

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