Sign in to follow this  
Scott Brosious

Rotation within an Array?

Recommended Posts

Scott Brosious    122
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

Share this post


Link to post
Share on other sites
NIm    210
IT is difficult to rotate an array at other than 90 degree intervals. Try it by hand. Rotation like that always loses some information.

Share this post


Link to post
Share on other sites
Zahlman    1682
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.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this