4
$\begingroup$

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:

enter image description here

And then it gets rotated like this:

enter image description here

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?

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$ Apr 19 at 9:22
  • $\begingroup$ 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. $\endgroup$
    – Julian
    Apr 19 at 9:25
  • $\begingroup$ I made some clarifications @TheoBendit $\endgroup$
    – Julian
    Apr 19 at 9:31
  • $\begingroup$ 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 ? $\endgroup$
    – YNK
    Apr 19 at 10:44
  • $\begingroup$ 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. $\endgroup$
    – Julian
    Apr 19 at 11:52

1 Answer 1

6
$\begingroup$

enter image description here

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

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

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.