Mail Archives: djgpp/1998/07/05/03:16:28
Andrew Deren wrote:
>
> Can someone help me figure an algo for rotating by 90 degrees a 2
> dimensional array.
>
> Let's say I have an array 20x20 and I want to rotate it by 90 degrees
> either to the left or right, but only some part of it let's say from (3,3)
> to (9,9).
> Can anyone help me figure it out?
> Thanks in advance.
There are two basic ways to do it depending on whether you are
optimizing for speed or memory use. The fast way is to copy from a
source array to a destination array using something like this:
for y...
for x...
dest(-y,x) = src(x,y)
end for
end for
That rotates 90 degrees clockwise. If you don't want to allocate a whole
other array, you can rotate the array components 4 at a time i.e.
simultaneously rotate all 4 quadrants to their next position.
--
.....
:edediah
:.:
- Raw text -