In a few days I'm facing the task of trying to move a piece of furniture into my apartment and the situation inspired me mathematically. Above is a sketch of the situation. We are trying to slide a small box of dimensions $h'$ and $w'$ through a corridor of dimensions $h$ and $w$ with entrance and an exit of widths of $a$ and $b$. No assumptions about any variables can be made except that $a$ > $h'$ and $b$ > $h'$, even if the picture suggests some relative dimensions. The box or any other dimension cannot obviously be stretched. The box can be turned freely.
I'm looking for the simplest way to calculate if it is possible to fit the box through the corridor, and how. I have come up with some tedious ways of trigonometry but somehow a simple and elegant solution eludes me. Help will be greatly appreciated!
EDIT: As pointed out in a comment, the box can be turned freely unlike my original question implied.
EDIT2: If it simplifies things, the length $h$ can be for my specific problem be assumed be bigger than $w'$ and $h'$, although it would be interesting to know a fully general case.


(The following is a partial answer at best, but too long for a comment.)
Suppose $\,a \le b\,$, otherwise flip the corridor around. If the box gets fully in through door $\,a\,$, then it will be able to get out through $\,b\,$ by symmetry, so it's enough to consider the move through $\,a\,$.
First step is to slide the box in at the maximum possible angle $\alpha$. If it can not get in the position depicted below without hitting the opposite walls first, then the move is impossible.
The angle $\alpha$ is determined by:
Then the conditions for the inside corners of the box to fit are:
$w' \cos \alpha \le w$
$w' \sin \alpha + h' \cos \alpha \le h$
(As a side comment, the first condition is equivalent to $\,h' \cdot w' \le a \cdot w\,$ i.e. the area of the box no larger than the area from the door to the opposite wall.)
These are necessary conditions, and no solution is possible if they don't hold. They are not sufficient conditions in general, though.
The next step would be to rotate the box towards vertical position by sliding the bottom corner to the right while keeping the top side in contact with the door edge. Such rotation, however, requires additional room at the top, and possibly to the right as well. Exactly how much room reduces in the end to finding the extrema of some trig functions, to which I did not find "nice" closed solutions.
Still, there are a couple of cases where the above conditions are sufficient as well (both of which assume that the length of the corridor is larger than the diagonal of the box $\,h \ge \sqrt{w'^2+h'^2}\,$).
If there is no perpendicular wall right next to $\,a\,$ i.e. if the bottom horizontal line in the drawing is missing, then the rotation can always be completed by sliding the bottom corner down and to the right, such that the box stays in contact with both edges of the door. In this case, the rightmost corner of the box never moves any closer to the right wall than it was before, so the previous condition is sufficient.
If the horizontal'ish diagonal of the red box has an upwards slope in that position (unlike the slightly downwards one in the picture), then again the rotation can be completed without requiring additional room on the right. This is the case when $\,\varphi \ge \frac{\pi}{2} - \alpha\,$ where $\,\varphi\,$ is the angle between the diagonal of the box and its wide side, which translates to $\,a \ge \frac{h'}{\sin \varphi}=\frac{h' \sqrt{h'^2+w'^2}}{w'}\,$.
(The above leaves out some trivial cases such as $w'\le w$ when the box can be simply translated all the way, or $w' \le a, h' \le w$ when the box can be first turned sideways then translated, but in my practice of having moved large boxes around corners those cases never happen ;-))