Sign in to follow this  

Rotation within an Array?

This topic is 4019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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

This topic is 4019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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