# How far does one have to zoom into an image that was rotated a certain amount of degrees in order to only see only the original pixels again?

This question was asked by a work colleague of mine, but my days as a mathematician are long gone unfortunately. It does sound like a pretty basic geometry problem to me, doesn't it?

I'm not expecting an extremly detailed answer here, but does anyone have any resources on this? I'm pretty sure this was already answered somewhere.

Please let me know if the question is formulated too vaguely. Thanks a lot in advance!

For clarification: I imagine that the original image looks something like this:

And then it gets rotated like this:

Only the red pixels are considered the "original pixels" while the white pixels are not. So the question would be how far do I have to zoom into the second picture in order to only see red pixels again?

• What do you mean by the "original pixels" here? This problem is unclear. For the record, you are not supposed to fit your entire question into the title, and you are supposed to elaborate in the body. Indeed, the body of the question should be readable without reading the title. Apr 19 at 9:22
• By "original pixels" I mean the pixels that only belong to the image that wasn't rotated yet but will be rotated during the process, to be more precise. I guess you could imagine that the image is embedded in some infinite two dimensional space. Apr 19 at 9:25
• I made some clarifications @TheoBendit Apr 19 at 9:31
• Please answer the following questions. Does your image always look like a rectangle (or square)? Around what point does the image get rotated? When you say "zoom into the second picture", do you mean scaling up the rotated image to completely cover the original image ?
– YNK
Apr 19 at 10:44
• The images are either rectangles or squares, yes. The image does get rotated around it's center. And yes, "zooming in" means to scale up the rotated image up to the point where you can't see any other pixels that appeared after rotating the original image, so in the example above, I'd like to scale up the second image until there is no white pixel left. Apr 19 at 11:52

The figure above shows the original image in the standard orientation with its edges parallel to the $$x$$ and $$y$$ axis, and then it shows the same image but rotated by its center by an angle $$\theta$$.

What you need to do is find the intersection points between the diagonals and the rotated edges of the image, and choose the one that is closest to the center of the image to construct your zoom rectangle (the blue rectangle) in the figure above.

If the image center is the origin, and the image extends over the rectangle $$[-a, a] \times [-b, b ]$$, then the equation of the right edge is $$x = a$$, and the equation of the top edge is $$y = b$$. When rotating the image by an angle $$\theta$$ counter clockwise, then the point $$(x, y)$$ is mapped to $$(x',y') = R (x,y)$$

where

$$R = \begin{bmatrix} \cos \theta && - \sin \theta \\ \sin \theta && \cos \theta \end{bmatrix}$$

It follows that $$(x, y) = R^T (x', y')$$. Therefore, the equation of the right edge is $$R^T (x', y') = a$$, which is

$$\cos(\theta) x' + \sin(\theta) y' = a$$

Similarly the equation of the rotated top edge is

$$-\sin(\theta) x' + \cos(\theta) y' = b$$

Now the equations of the red diagonals are $$y' = \pm \dfrac{b}{a} x'$$

Intersect these diagonals with the two rotated edges to obtain $$(x_1, y_1)$$ and $$(x_2, y_2)$$. Choose the point that closer to the origin, i.e. having the smaller $$\sqrt{ x_i^2 + y_i^2 }$$, and call this point $$(x_0, y_0)$$

Now the zoom rectangle (shown in blue) extands over $$[- |x_0|, |x_0| ] \times [-|y_0| , |y_0| ]$$

The zoom factor is the following ratio

$$\text{Zoom Factor} = \dfrac{a}{|x_0| } = \dfrac{b}{| y_0 | }$$

• The zoom factor can be also expressed as $\dfrac{a}{b}\sin\left(\theta\right)+\cos\left(\theta\right)$.
– YNK
Apr 20 at 9:41