www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/05/03:16:28

From: Jedediah Smith <jedediah AT interlog DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Rotating 2d array
Date: Sun, 05 Jul 1998 05:51:30 -0700
Organization: Interlog Internet Services
Lines: 30
Message-ID: <359F76D2.7840@interlog.com>
References: <Pine DOT GSO DOT 3 DOT 96 DOT 980701233047 DOT 8788A-100000 AT oscar DOT eecs DOT uic DOT edu>
NNTP-Posting-Host: 209-20-0-182.dialin.interlog.com
NNTP-Posting-Time: 5 Jul 1998 06:48:22 GMT
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019