11
$\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$.

  • 0
    Nice question. The rectangle $R_1$ rotated by $\theta$ radians fits in an axis-aligned box of length $l_1\lvert\cos\theta\rvert+b_1\lvert\sin\theta\rvert$ and width $l_1\lvert\sin\theta\rvert+b_1\lvert\cos\theta\rvert$. So you want to determine whether there is any $\theta$ such that these are less than $l_2$ and $b_2$ respectively. Of course, one can restrict $\theta$ to $[0,\pi/2]$ and drop the absolute value signs. This leaves you with inequality constraints on a couple of trigonometric functions, and I don't feel like working it out after that...2012-09-03
  • 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.

  • 2
    `p≥q`? What happened with formula if `p=q`?2017-03-10
  • 0
    @PiotrWasilewicz I agree the condition is incorrect: if you cannot fit a *square* rug in a room, you won't fit it by rotation. But I love the answer.2017-03-13
  • 0
    @WeatherVane But answer is totally incorect! Check for `a = 8`, `b = 1`, `p = 10` and `q = 9`. This theorem sais that rectangle `10 x 9` fits in rectangle `8 x 1`.2017-03-14
  • 1
    @PiotrWasilewicz yes I see that now, was just starting to implement it - it seems to work for some values. Perhaps there must be a condition too that `a*b > p*q`.2017-03-14
  • 0
    @WeatherVane "work for some values" = doesn't work. I think `a*b > p*q` is not only condition that you need (but I'm not sure yet). Futhermore if you really only need `a*b > p*q` (and we have also `p>a` and also `a ≥ b`) we have theorem which is working not for "some values" it will be not enough for most examples.2017-03-14
  • 0
    @PiotrWasilewicz "works for some values" means "works for all the values I tested" ==> "works". I am saying it is *obvious* that your example cannot work when the area of the inner rectangle is larger than the outer one. The reason for conditions in any expression, is that they do not work for all values.2017-03-14
  • 0
    @WeatherVane. No. In general theorem is not working because theorem is broken. You can say "works enough for me" and thats ok.2017-03-14
  • 0
    No, your rectangles are the wrong way round. And I did not say "the only condition" but an obviously necessary one. There is no theorem which can fit a larger rectangle inside a smaller one. Please show why it is "broken", so far you mention only two obvious conditions, the first being `p==q` will not work (because of divide-by-zero) but logically, as I said, a square rug rotated won't fit a rectangle it can't fit when unrotated.2017-03-14
  • 0
    I think we are talking about two different situations. What I mean is: if theorem doesn't work for one case (even if case is obvious but it is in domain) it mathematically means that theorem doesn't work. You mean that theorem works for most not obvious cases so it is useful. I agree. Other cases when theorem not work (`a = 7`, `b = 81`, `p = 26`, `q = 16`) - due to perimeter2017-06-27
  • 0
    @WeatherVane I found not-obvious example: `a = 80`, `b = 79`, `p = 105`, `q = 7`. It satisfies your argument with area. Theorem says that I can fit pxq into axb. But it is not possible (you can visualize this case).2017-06-27
  • 0
    @PiotrWasilewicz FWIW I was brought here originally when trying to solve SPOJ problem [EQBOX](http://www.spoj.com/problems/EQBOX/). I did solve it by *using the link in the accepted answer*, although I had to add some conditions. My first attempt using this answer, failed.2017-06-27
  • 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