12
$\begingroup$

Given two rectangles $R_1(l_1, b_1)$ and $R_2(l_2, b_2)$ where $l$ and $b$ are their length and breadth respectively, how to check if $R_1$ can fit inside $R_2$ or vice versa.

If $R_1$ and $R_2$ lie in the same plane and there exists an orientation of $R_1$ such that it lies completely inside $R_2$, then $R_1$ fits inside $R_2$.

  • 2
    This reminds me of a story where a train allowed only items of a max length/breadth/depth, so to get his over-long umbrella onto the train the passenger put it into a box.2012-09-03

2 Answers 2

5

Look at: http://www.jstor.org/stable/2691523

  • 2
    This theorem is wrong. Check for rectangles `(a x b) = (8 x 8)` and `(p x q) = (10 x 10)`. Both conditions (`p > a` and `b >= fraction`) are satisfy (it is necessary and sufficient condition) but square `(10x10)` doesn't fit into square `(8x8)`.2017-03-10
6

Joseph Malkevitch's answer is perfect.

For all who can't read the complete article, here's the most elegant solution (necessary and sufficient condition for a rectangle pxq to fit in a rectangle axb, provided p≥q, a≥b and p>a):

Rectangle pxq fit in rectangle axb

=((a+b)/(p+q))^2+((a-b)/(p-q))^2

Two obvious day-to-day applications: rug on a floor, tray in an oven.

  • 0
    @WeatherVane Maybe person who added this problem to SPOJ read article and this is why most cases works. Or maybe theorem fits to almost every example (it is really hard to find example for which theorem doesn't work). What other conditions did you add?2017-06-27