One of the hardest problems in working with raster graphics is rotation. How do you rotate an array of pixels by an arbitrary angle in such a way that the picture still looks good?
Let's start with nine pixels.
![]()
Now we rotate them 45°.
![]()
Simple enough, right?
The problem is, monitors don't adapt so easily to diamond-shaped pixels. We need to convert these diamond-shaped pixels back to square pixels.
![]()
This is equivalent to showing the original square arrangement with diamond pixels:
![]()
But there's a problem: Those gaps between the pixels. They make for a low resolution and will ruin our pretty colors. (Think of viewing the image through one of those roll-up car window shades.)
So we need to take the gaps out. This leaves us with one of two hopscotch-like representations:
![]()
![]()
Hmmm. OK, so we got back to square pixels, but we have a new problem: the aspect ratio of the image has changed. Remember that we had a bisymmetrical diamond: the X diameter was the same as the Y diameter. Now we have a diamond that is squished on one axis or the other. And we still have the previous problem, that this won't fit on a monitor with a plain (non-staggered) grid of pixels.
No problem. Working from the second image, we'll interpolate the even columns from two pixels each into three pixels each.
![]()
Ack. Not so good. And what do we do about that middle column? Suppose we stretch it out to five pixels: rows (1,2)→1, (1,2,3)→2, (2,3,4)→3, (3,4,5)→4, (4,5)→5.
![]()
Interpolation has faded the colors of each pixel in the middle column, and the center pixel is now a faint brown, rather than pure 50% gray. Blurgh. There must be a better way.
| 2006-03-27 http://boredzo.org./koans/rotation |
|