
Ask HN: How to calculate if a box will fit through a hallway with a 90 degree turn - tocomment
It seems like it should be simple geometry but I'm stumped.<p>Will my box:<p><pre><code>     --
    I  I
    I  I
     --
</code></pre>
Fit through my hallway:<p><pre><code>    I   I
    I   I
    I   ------
    I      
    ----------</code></pre>
======
noonespecial
You can find out with a piece of string. Make the string as long as the mid-
point of the box on one edge to one of its corners on the other side. Hold the
string at the inside corner of the hall. If you can sweep the arc without
touching any walls it will fit.

If you don't know the size of the box in advance, hold the string at the
corner and make the string the longest possible length that can sweep this
arc. Take the sting with you to the box.

What you are really doing is measuring the distance to the corner from the
closest wall and then making sure the line from the box's midpoint to one of
its corners is not longer. There are edge cases (ha!), but this generally
works.

~~~
NoBSWebDesign
I believe this is technically incorrect, but it errs on safe side. I.e. if the
string sweeps through the arc, the box will fit, if it doesn't swing through
the arc, there is still a chance that the box will fit. I'm assuming this is
what you are referring to by "edge cases".

Mathematically this "string theory" (sorry, couldn't help myself) is saying
the following:

sqrt[ (l/2)^2 + b^2 ] < min(x,y)

where l = length of box, b = base of box, and x and y are the respective
widths of the two hallways.

However, this ignores the fact that the pivot point on the box around the
corner can slide as you push the box around the corner. So the pivot point
could essentially slide from one end of the box to the other (at some point
sliding through the midpoint you are measuring for), which allows a lot more
leeway for the box's acceptable dimensions.

I worked on this problem a bit this morning, but I don't have my trusty TI-89
calculator to help out. This is actually a calculus problem that I have a
difficult time explaining without posting some sketches. Maybe I'll do that in
the near future.

~~~
noonespecial
_but I don't have my trusty TI-89 calculator to help out_

You speak with knowledge, worthy adversary, but with my HP-48g, I would defeat
you! </bad overdub due to RPN>

------
kduncklee
Here's a paper on finding the maximum size of the box:
<http://www.springerlink.com/content/95mh987542674584/>

~~~
NoBSWebDesign
I began working on this problem this morning, and my calc equations kept
getting bigger and bigger, then after I had about 2 pages filled with
equations, I saw your post.

I feel much better now knowing I wasn't missing something obvious, and I can
finally move onto my actual work for the morning after seeing the solutions.
Thanks!

------
quellhorst
If you gzip your ascii box, it will fit in your hallway. Or provide the
measurements and someone here will do the math for you :)

------
tocomment
Thanks for all the answers. It's starting to make sense. I'm relieved to see
it's not an easy problem.

If it helps, it's an elliptical machine I was thinking of buying (I was using
a rectangular box shape as an abstraction.)

I'm not sure how easily it can be disassembled.

The dimensions are 22" x 57" x 66" and the hallway is 31" in the first
corridor and 32" in the next, with a height of 82".

~~~
niyazpk
According to the condition I previously provided, (sqrt(x^2+y^2) - l/2) should
be greater than or equal to b for the box to fit through.

Here let us take h=66 since it will fit only that way in the corridor.

x = 31, y = 32

b = 22, l = 57, h =66

So (sqrt(x^2+y^2) - l/2) = 44.55 - 28.5 = 16.05

Now 16.05 is less than b(=22), so the box will not fit through.

------
niyazpk
Consider a box l x b x h

let x = width of one corridor.

let y = width of the perpendicular corridor.

We will disregard the height of the box here since I assume that you can find
out the correct way to orient the box.

The box will fit throught the hallway if:

(sqrt(x^2+y^2) - l/2) >= b

I will post the reasoning after I get out of my office.

BTW, thanks for posting this intersting problem.

~~~
NoBSWebDesign
I really am curious as to how you arrived at this equation. It is a vast over-
simplification of the problem.

The equation I came up with is as follows:

y1 = [l/(2b(1/tan(a)^2 - cos(a))] * [x - l/cos(a) + b/sin(a)] + l/cos(a) +
b/sin(a)

where you plugin b, l, and x based on your parameters, and find the maximum
value for y1 when a goes from 0 to 90 degrees. That maximum value should be
less than y for the box to be able to fit around the corner.

------
Tichy
Don't have time to properly look into it, but here is a quick guess: I suppose
the best you can do is rotate the box around the corner on one point on the
"upper" side of the box (upper in 2d). If you pick one point on the upper side
of the box (which will be the turning point), you can calculate the distance
of the lower corners of the box to that point. These distances have to be less
or equal to the distance of the inner corner of the hallway to the opposing
side of the hallway (which incidentally might be the width of the hallway).

This gives you two equations for determining the point on the box to rotate
around. If you can solve them, the box will fit through the hallway.

Btw., voted up for reminding me of that classic Douglas Adams story where the
hero ends up writing a program to calculate how his sofa could have gotten
stuck in the hallway.

------
pg
If it fits in both corridors without reorientiation, it follows that it fits
through the corner, which is part of both corridors. (Imagine sliding a square
on a chessboard.) Or are you asking something more complicated? Is that ascii
drawing supposed to be to scale?

~~~
kduncklee
While this is always true, it is possible to get a longer object in if you
turn as you go. It's an easy problem if the object has no thickness, but
trickier otherwise.

~~~
gambling8nt
To solve the problem for an object with thickness, imagine shifting the wall
on the inside of the turn in by a distance equal to the width of a box (with
the corner expanding out to a semicircle), and then consider moving a line
segment through the appropriately shrunken hallway.

Note that we're still being possibly inefficient, as we are not using our
third available dimension; however, this is only relevant if the box is much
longer in one direction than the other two (for example, if you were trying to
carry a 2x4 around this corner).

------
ander501
This may give you a place to start

[http://archives.math.utk.edu/visual.calculus/3/applications....](http://archives.math.utk.edu/visual.calculus/3/applications.2/)

------
thexa4
Why turn it at all? If you just start moving it the other way you won't have
the problem of turning.

If you really want to turn the box, make sure the hallway is wider then 3/4 *
sqrt(2) * lengthBox If you turn the box 45 degrees, that's when the box will
use the most space. The hallway will have to be 3/4 of the diagonal of the
box.

------
anigbrowl
Probably if you don't mind rotating it around. I spent a summer working as a
mover once it's surprisingly easy to get a sofa round corners. So unless you
have a very small hallway or a very large box, I'd guess yeah. It would help
if you told us what was in the box, but I understand if you're under NDA :-p

------
jsz0
I don't know the proper way to calculate it geometrically but the most
practical way might be to make a template with the same dimensions (WxL) out
of a single sheet of cardboard and give it a try.

------
stelund
sqrt(h^2 + h^2)*2 is the max length if your box is 0 is width. The max
possible length decreases with sqrt(w^2 + w^2) as width expands.

Assumed the hallways size is symetrical and your object cannot be tilted to
achive a smaller length. For example, an object of little height in a high to
ceiling room will be possible to tilt with the same measurements are presented
above (pythagoras). But if the box has any substancial height you wont get any
help from a tilt. A soffa would tilt, a dish washer does not.

------
stevejalim
What's in the box? Unless the contents are basically the size and shape of the
carton, why not just take them out and carry them in a few trips if the box
won't make it?

~~~
nailer
All of the evils, ills, diseases, and burdensome labor that mankind has not
known previously. However at the very bottom of her box, there lies hope.

Personally I reckon you should keep it closed.

------
tocomment
I hope this isn't too off topic, but it's like a life-hack, right? We all need
to know if something will fit in our houses before we buy it.

------
Raphael
Remember, you are working in 3 dimensions. It may be possible to squeeze
something a bit wider than the 2D solution would suggest.

------
patio11
You're going to need a tape measure either way, so tape-measure out the
longest edge of the box, then take the tape measure and see if you can put it
through 90 degrees of motion within the bend without hitting a wall. If not,
then I'm guessing you're in for some breakage.

------
Raphael
I think if it can fit at a 45 degree angle in the corner then you're good.

