It is easy to rotate pixel array if the angle is a multiple of 90 degree.

For example, (quote from Computer Graphics with OpenGL)

We can rotate a two-dimensional object or pattern 90' counterwise by reversing the pixel values in each row of the array, then interchanging rows and columns.

But I could not understand how to rotate pixel array when the angle is not a multiple of 90 degree from the textbook.

Each desitination pixel area is mapped onto the rotated array and the amout of overlap with the rotated pixel areas is calculated.

Why does this means?

  1. Choose an origin for your coordinate system. A corner or the middle of the image is typical.
  2. For each pixel, compute its (x, y) coordinates relative to the origin.
  3. For each pixel, compute its new coordinates when keeping its distance from the origin the same and adjusting its angle by the desired rotation.
  4. In a temporary buffer, copy pixels from the original image using the new coordinates.
  5. Go over the temporary buffer, and for each pixel that wasn't assigned a color, interpolate the colors from surrounding pixels.

There are some details glossed over there, but the basic idea is sound. Coordinate transformations can be accomplished using basic trigonometry.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.