From: Jedediah Smith 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: NNTP-Posting-Host: 209-20-0-182.dialin.interlog.com NNTP-Posting-Time: 5 Jul 1998 06:48:22 GMT Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 :.: