# Thread: Finding scale of rectangle inside larger rotated rectangle

1. ## Finding scale of rectangle inside larger rotated rectangle

Apologies if I'm poor at describing this problem.

I have a rectangle, A, of known size, that starts aligned to the x/y axes, and can rotate around its centre point.

For any given angle of rotation, I need to determine the maximum dimensions of a second rectangle, B, that:

- is inscribed inside A
- maintains the same proportions as A
- maintains alignment to the x/y axes So, here A (the black rectangle) has been rotated through 30 degrees (the red rectangle). How do I determine the maximum size of B (the blue rectangle)?

Many thanks for any help.

2. Good problem! My answer: I don't know BUT I'm pretty sure B needs to end up as a square (a square is a rectangle).

3. The vertices of the blue rectangle will lie on the diagonals of the black rectangle (green lines on the attachment). So all you have to do is to see where the green lines intersect the red lines, choose the two such intersections that are closer to the centre of the rectangle, and take those to be opposite vertices of the blue rectangle.

If the black rectangle has sides on the lines $\displaystyle x=\pm a$ and $\displaystyle y=\pm b$, where a>b, and the red rectangle is obtained by rotating it through an angle θ (between 0 and π/2), then I think that the vertices of the blue rectangle will be at $\displaystyle \Bigl(\pm\frac{ab}{a\sin\theta+b\cos\theta}, \pm\frac{b^2}{a\sin\theta+b\cos\theta}\Bigr)$ (but I haven't checked that calculation carefully).

4. Opalg,

Plotted on a graph, that looks correct, I'll do the programming tomorrow to make sure. Thanks for the help - its depressing how little math I can do after 10 years out of school!

5. I really should be able to figure this out by myself, but...

What is the formula when a < b?

6. Sorted, when a < b:

$\displaystyle \Bigl(\pm\frac{a^2}{b\sin\theta+a\cos\theta}, \pm\frac{ab}{b\sin\theta+a\cos\theta}\Bigr)$

7. ## Practical example

the above formula was used in an ImageMagick discussion forum to develop a video rotation sequence.
the coordinates was used to define a 'scaling factor' enlarging an rotated image so that it completely defines the images original bounds.

ImageMagick &bull; View topic - optimizing 'convert' speed

finding, inside, larger, rectangle, rotated, scale 