Rotation within an Array?

Started by
1 comment, last by Zahlman 17 years, 4 months ago
I'm trying to rotate the contents on an array. Here is what I got for a formula so far. x = xcntr + ((i-xcntr) * cos(a * pi# / 180) - (j-ycntr) * sin(a * pi# / 180)) y = ycntr + ((i-xcntr) * sin(a * pi# / 180) + (j-ycntr) * cos(a * pi# / 180)) i and j are the lookup indices within the array this works great for 90 degree incremeents but sloppy at otheers Does anyone know a better way to to this? So code would be nice. Thanks
Advertisement
IT is difficult to rotate an array at other than 90 degree intervals. Try it by hand. Rotation like that always loses some information.
I assume the array represents an image of some sort. Don't do it yourself if you don't have to. For example, SDL provides a "rotozoom" module that handles this stuff.

Otherwise, you can improve accuracy by:

- iterating over the *destination* array, translating destination-array coordinates into source array coordinates, and copying them over. If you iterate over the source and copy into the destination, then you may get some pixels mapping to the same spot, and some spotted unmapped.
- Choosing adjacent pixels in the source and taking a weighted average to decide on the destination value. You can use the fractions from the floating-point calculations to determine how to weight the averages. (However, this is completely wrong for most palettized images.)

This topic is closed to new replies.

Advertisement