# New size of a rotated-then-cropped rectangle

Imagine a rectangle (x1 by y1) always has to be drawn with horizontal and vertical lines (so it can't have lines at 45 degrees). If the rectangle is rotated by angle θ, it needs to have a rectangle drawn inside it so that this new rectangle still follows the rules. In the diagram, the black rectangle is the original, the red one is the rotated rectangle, and the green ones are three possible options (the two extremes, and one which maintains the aspect ratio). How can I work out (in terms of x1, y1 and θ):

1. the dimensions (x2 and y2) of the rectangle which maintains the aspect ratio of the original?
2. the dimensions (x2 and y2) of the rectangle which has the largest possible area within the given boundaries?
3. x2 for a given y2 (and vice-versa) within a valid range?

Answers to only one part are quite welcome. I've tried to work this out myself by looking at what I know about the resulting triangles, and can't seem to get anywhere (it's been a while since I studied Maths), so an answer to one of these might point me in the right direction.

• Is it necessary that the center of the new rectangles always be the same as the center of the original rectangle? – Raskolnikov Feb 8 '11 at 17:46
• Yes, but I don't really see how it makes much difference mathematically, given that the middle green rectangle (or any rectangle that aren't the two extremes shown) can freely slide one way or the other without changing size. – Nathan MacInnes Feb 9 '11 at 9:31

## 2 Answers

Let's say that the origin of a coordinate system is at the center of the original black rectangle. This is the center of the rotation and also the center of each of the green rectangles. Consider only the first quadrant (from the origin up and to the right). Exactly 1/4 of the black rectangle and each green rectangle is in the first quadrant. Let's further assume that, as in your picture, the angle of rotation is relatively small (say, less than 45°) and in the clockwise direction, and that $y_1<x_1$.

Let the vertex of the black rectangle that is in the first quadrant be $(a,b)=(\frac{1}{2}x_1,\frac{1}{2}y_1)$. Call the magnitude of the angle of rotation $\alpha$ ($0°<\alpha<45°$). The coordinates of the vertex of the red rectangle in the first quadrant are $(a\cos\alpha+b\sin\alpha,-a\sin\alpha+b\cos\alpha)$. The slope of the upper side of the red rectangle is $-\tan\alpha$. An equation for the upper side of the red rectangle in the first quadrant is $y-(-a\sin\alpha+b\cos\alpha)=-\tan\alpha(x-(a\cos\alpha+b\sin\alpha))$ for $0\le x\le a\cos\alpha+b\sin\alpha$. An equivalent simplified equation is $y=\sec\alpha(b-x\sin\alpha)$. This red upper side intersects the original black upper side at $x=b\cot\alpha(\sec\alpha-1)$.

So:

• for $b\cot\alpha(\sec\alpha-1)\le x\le a$, the vertex of the green rectangle in the first quadrant will be on the red side, at $(x,\sec\alpha(b-x\sin\alpha))$, and it will have area $4x\sec\alpha(b-x\sin\alpha)$.
• for $0\le x<b\cot\alpha(\sec\alpha-1)$, the vertex of the green rectangle in the first quadrant will be on the black side (here, I'm assuming from your picture that the green rectangle must be contained entirely within the black rectangle), at $(x,b)$, and it will have area $4xb$.
• assuming that the green rectangle must be contained entirely within the black rectangle, $x$ cannot be greater than $a$.

Assuming the first case:

• the maximum area is $b^2\csc\alpha\sec\alpha$ when $x=\frac{1}{2}b\csc\alpha$.
• the green rectangle will have the same aspect ratio as the black rectangle when $x=\frac{ab}{b\cos\alpha+a\sin\alpha}$ (and the area is $\frac{4ab^3}{(b\cos\alpha+a\sin\alpha)^2}$).

edit: I originally forgot the factors of 4 on the area, moving from my picture of just one-fourth of things back to the whole rectangles. Similarly, note that my $x$- and $y$-values are half of your $x_2$ and $y_2$, respectively. The maximum possible area for the second case (where the vertex is at $(x,b)$) is $4b^2\cot\alpha(\sec\alpha-1)$, which Mathematica seems to be telling me cannot be greater than the maximum area for the first case under my assumptions about the problem.

• Wow, thanks. That's amazing. You're assumptions were correct... I intended to get those across in the question, but obviously I didn't make it very clear. – Nathan MacInnes Feb 9 '11 at 9:21
• @Nathan: Glad I could help. Most of the assumptions were easy to guess from your diagram, just not explicit in the text—most math contexts allow for few, if any, assumptions from diagrams. – Isaac Feb 9 '11 at 18:51

The answer by Isaac,

the maximum area is b^2*cscα*secα when x=0.5*b*cscα = 0.5*b/sinα

seems to work for angles near 45 degrees. However, its range of validity seems to be aspect ratio dependent. For w/h aspect ratio >> a/b, it works for a large range of angles, but for aspect ratio = 1 it only works at 45 degrees.

It appears that within the valid range of this solution, only 2 diagonal vertices of the inner rectangle touch the sides of the rotated rectangle. But in the invalid range, all four vertices of the inner rectangle touch an appropriate side of the rotated rectangle.

This is easily seen by using α nearly zero (very little rotation), then sinα becomes nearly zero and x becomes very large, certainly much larger than a. Whereas the correct solution will be nearly the same size as the slightly rotated rectangle

I have tried solving this with lagrange multiplers and get the same answer. But I don't know how to put in an inequality constraint that x<=a.

I am wondering if this can be solved closed form with a more general solution that gives a solution for any angle and any aspect ratio. Or at least another solution that works where this solution fails. So far I have been unsuccessful.

I would appreciate hearing from the Mathematics experts on this.

• When copying math, you can right-click on it and use "Show Source" to copy the $\TeX$ source; if you just copy the text it doesn't get typeset. – joriki Jun 21 '11 at 9:57