Math behind rotation in MS Paint

For those who don’t know, MS Paint only has the options to rotate an image by right angles. To carry out an arbitrary rotation (θ), the following hack is suggested:

  1. Horizontal skew by θ

  2. Vertical Stretch by 1cos2θ

  3. Vertical Skew by θ

  4. Horizontal and Vertical Stretch by cosθ

I would like to know how this works.

(I guess one way would be to show that multiplying the above operations represented as matrices should return the 2D rotation matrix, but I do not know what are the matrix representations for the intermediate steps.)


I think the following matrix product gives an explanation.

The first step is given by the matrix

The second step corresponds to

The second shearing operation corresponds to

At this point we have done S2D1S1 that after a little bit of matrix manipulation and using the identity sin2θ+cos2θ=1 becomes

The last step amounts to a scalar multiplication by cosθ and gives us the familiar rotation matrix

Edit: I got to use this as an exercise in a freshman course that just ended. I was actually a bit unhappy with that youtube video, because it doesn’t show the transitions from one step to the other. To fix this problem I made an animation, where the four steps are done gradually: in steps one and three I continuously move the shear (skew) parameter from zero to the desired value. Similarly in steps two and four the scaling parameter changes continuously from one to the proper value. All the steps are done sequentially.

enter image description here

Source : Link , Question Author : kuch nahi , Answer Author : Jyrki Lahtonen

Leave a Comment