javascript contador Skip to content

The surprising math behind rotating an image

The surprising math behind rotating an image

The surprising math behind rotating an image

Explanation (in video) of the science behind when we rotate an image with some image editing program.

You may find it easy to rotate a simple image, but the truth is that there’s a lot of math behind (or at least for someone who doesn’t understand much about numbers). And so, children, it is important to study mathematics. Like this very simple action, which at least in my case, I do many times a day without taking into account everything behind it, there are many others that without mathematics would not be possible.

Mathematics, in this case, can explain how images are rotated. The calculations behind the action of rotating an image really are pretty basic. Even a high school student will know how to do it comfortably. And it is that, after all, it is about knowing the Pitgoras theorem and some linear algebra.

The Pitgoras theorem, the key

IronMortality has been the user who has been in charge of uploading a video to YouTube with the explanation (very poor, that is, because it has not emphasized the origin of those calculations) of how you could rotate an image in Paint with an angle less (or greater) than 90 degrees, which is the only rotation that allows the program to be carried out. The truth is that the method that this user has used is exactly the algorithm used by image editing programs for many years.

First, twist the horizontal 30


The first step is rotate the ordinate axis (horizontal). Be careful, it is not to rotate the image 30, because if we had not already discovered the mystery, but the axis. We illustrate with an example. For this, in Paint, we will have to do click right over the image. A context menu will open and we will have to press Resize.


Keep in mind that you should have the Select mode and not the Brush mode (as seen in the image above). Once the floating window has opened, enter the value 30 in the third field (the field is called Horizontal). You will see how the ordinate axis moves as in the drawing above.

We modify the height


But what height to choose? The new measure be calculated using this formula: 1 / cos (x), where x is, of course, the angle we have chosen (in this case, it’s 30). The result, if we do it using the calculator, is 1.3_. To enter it in Paint, we do click right again on the image and in the contextual menu we choose the option Resize. We enter the value (specifically 133, because we must place it in percentages) in the second field (it should correspond to Vertical).

We rotate the vertical 30 degrees


Finally, we do the same step as the first time, but this time not on the ordinate axis, but in the abscissa. I mean, we doclick Right over the image, we select Change size and type 30 in the fourth field, which is the one that puts Vertical.

We rescale the image


Finally, the image needs to be rescaled to its original state, although it was little, we have modified the measurements, both in height and width. What you need to do is enter the result of cos (x) as a percentage in the first two fields, which correspond to the height and width. Specifically, the cosine of 30 degrees is 0.866, so we must enter 87% in the two text entries.

By the way, you are not the only one who seems that when turned 30 degrees the face seems happier, I have also thought about it.