Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!csd4.milw.wisc.edu!leah!bingvaxu!sunybcs!boulder!tramp!foster From: foster@tramp.Colorado.EDU (J. Gabriel Foster) Newsgroups: comp.graphics Subject: Re: Wanted: Bitmap rotation algorithm Message-ID: <9406@boulder.Colorado.EDU> Date: 14 Jun 89 15:46:45 GMT References: <8.UUL1.2#261@persoft.UUCP> <230@helens.Stanford.EDU> Sender: news@boulder.Colorado.EDU Reply-To: foster@tramp.Colorado.EDU (J. Gabriel Foster) Organization: University of Colorado, Boulder Lines: 37 In article <230@helens.Stanford.EDU> mike@relgyro.STANFORD.EDU (Mike Macgirvin) writes: >In article <8.UUL1.2#261@persoft.UUCP> ericf@persoft.UUCP (Eric R. Feigenson) writes: >>I am look for any and all algorithms relating to rotating a bitmap an >>aribtrary amount. Efficiency and accuracy (minimal distortion) are, >>of course, important considerations. An English or pseudo-code > Some code is included at this point. > > There are some 'holes' in an image using this method at angles >which are not right angles.... > Two comments: 1) I think there is a bug in the included code. 2) There is a way that is less likely to produce holes. Here are the proposed fixes. > for(y = 0;y < HEIGHT; y ++) > for(x = 0;x < WIDTH; x ++) { > xx = (x * cos(radians(angle)) - (y * sin(radians(angle)); > yy = (x * sin(radians(angle)) + (y * cos(radians(angle)); > color = image[xx][yy]; > setpixel(x,y,color); > } Notice that you always fetch from the source picture at the rotated angle. (The angle may need to be -angle by the way. I have not tested it.) This means that you set every pixel in the destination image, so there are no rounding errors that leave holes. (There are other problems, mostly with some pixels getting spread out a bit.) Hope this helps. --> J. Gabriel Foster --> foster@eprince.colorado.edu --> foster%eprince@vaxf.colorado.edu.BITNET University of Colorado @ Boulder.