Alex Rivera | Logout

Calculate largest inscribed rectangle in a rotated rectangle

Asked 2011-04-26T10:52:28.480
61

I'm trying to find the best way to calculate the biggest (in area) rectangle which can be contained inside a rotated rectangle.

Some pictures should help (I hope) in visualizing what I mean:

input rectangle with given width and height rotate erctangle by alpha degrees output inner rectangle

The width and height of the input rectangle is given and so is the angle to rotate it. The output rectangle is not rotated or skewed.

I'm going down the longwinded route which I'm not even sure if it will handle the corner cases (no pun intended). I'm certain there is an elegant solution to this. Any tips?

EDIT: The output rectangle points don't necessarily have to touch the input rectangles edges. (Thanks to Mr E)

Edit
Report

1 Answer

14

Trying not to break tradition putting the solution of the problem as a picture:)

enter image description here


Edit: Third equations is wrong. The correct one is:

3.w * cos(α) * X + w * sin(α) * Y - w * w * sin(α) * cos(α) - w * h = 0

To solve the system of linear equations you can use Cramer rule, or Gauss method.

answered 2011-04-26T13:35:04.073

Your Answer