# Finding scale of rectangle inside larger rotated rectangle

• Sep 17th 2009, 05:42 AM
kissmyawesome
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.
• Sep 17th 2009, 09:50 AM
Wilmer
Good problem! My answer: I don't know (Doh)

BUT I'm pretty sure B needs to end up as a square (a square is a rectangle).
• Sep 17th 2009, 12:56 PM
Opalg
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 $x=\pm a$ and $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 $\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).
• Sep 17th 2009, 02:18 PM
kissmyawesome
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!
• Sep 18th 2009, 12:04 AM
kissmyawesome
I really should be able to figure this out by myself, but...

What is the formula when a < b?
• Sep 18th 2009, 12:09 AM
kissmyawesome
Sorted, when a < b:

$\Bigl(\pm\frac{a^2}{b\sin\theta+a\cos\theta}, \pm\frac{ab}{b\sin\theta+a\cos\theta}\Bigr)$
• Jun 2nd 2011, 04:56 PM
antofthy
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