Given a rotated rectangle, how can I find the largest axis-aligned rectangle of a given aspect ratio that can fit within the original rectangle? For example, I'd want to find the largest rectangle of aspect ratio 4:3 that can fit in another arbitrary rectangle.
I know the position, width, height and rotation of the enclosing rectangle. I know the width and height aspect ratio of the inscribed rectangle. I need to figure out the position, width and height of the inscribed rectangle.
Here's an example of what I'm looking for:
If it helps, I'm using the GLM C++ library.
Edit: not sure I understand why this should be closed. There's plenty of questions on geometry on stackoverflow. For example:
Let θ be the acute angle shown.
Project the axis-aligned rectangle (with sides w and aw, where a is the aspect ratio) onto the directions of the sides of the rotated rectangle. Then, to fit, you need, simultaneously,
Hence, your desired width is limited to