I'm looking to find the width and height of a rectangle without rotation within a rotated bounding rectangle. I have rotation in degrees and the width and height of the bounding rectangle. Basically I'm looking to find the largest ( largest area ) un-rotated rectangle that will fit inside a rotated rectangle of any given size.
Asked
Active
Viewed 1,605 times
2
-
1Isn't the smallest rectangle inside a bigger one an empty rectangle? – Tunococ Jan 29 '13 at 01:51
-
Yeah I think that's what it's called. – Jordan Jan 29 '13 at 02:04
-
I think the question is meant to be to find the largest rectangle with sides parallel to the axes. If so, this is an incompletely specified question. Many rectangles with sides parallel to the axes will fit into a shape like ◇ but there is no obvious choice of "largest", since we could fit a tall, narrow rectangle, a short, wide rectangle, a squarish rectangle, and so on. – David Moews Jan 29 '13 at 02:05
-
1@DavidMoews - It seems like there has to be an equation for finding the largest possible rect that would fit. Just found this, although its too complicated for me to understand quickly. http://stackoverflow.com/questions/5789239/calculate-largest-rectangle-in-a-rotated-rectangle – Jordan Jan 29 '13 at 02:13
-
Please make two corrections: 1) Ask for the "largest" rectangle 2) Specify one: with largest area or with largest perimeter or ... – Maesumi Jan 29 '13 at 04:04
-
A problem with looking at https://stackoverflow.com/q/5789239/3466415 is that the two top-voted answers are wrong (that is, wrong at the time I am writing this, more than ten years later). I provided an algorithm in an answer here that I think is about as simple as it can be, but at the end of that answer I also link to several stackoverflow answers that I believe are correct. – David K Oct 10 '22 at 03:21
1 Answers
1
If you don't have the coordinates of the rotated corners, just rotate each point.
Once you have that, find the smallest and largest $x,y$ coordinates of the 4 points.
The smallest and largest $x,y$ pairs correspond to the bottom-left and top-right corners of your rectangle.
Jacob
- 2,540
-
-
-
-
This is not a correct answer as there is no guarantee that the rectangle will end up on the same x,y coordinates if one is rotated and not the other one
Also "rotate each point" according to what reference?
– Tofandel Aug 19 '22 at 16:22