Ask HN: How to calculate if a box will fit through a hallway with a 90 degree turn

22 points by tocomment ↗ HN
It seems like it should be simple geometry but I'm stumped.

Will my box:

     --
    I  I
    I  I
     --
Fit through my hallway:

    I   I
    I   I
    I   ------
    I      
    ----------

31 comments

[ 1.5 ms ] story [ 72.6 ms ] thread
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.
I think if it can fit at a 45 degree angle in the corner then you're good.
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.
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?
he might be implying somehow that one or more people are carrying it, which might require rotation.
(comment deleted)
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.
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).

Yes, I understand that. That's why I asked if his drawing was supposed to be to scale.
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.
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 :)
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
Here's a paper on finding the maximum size of the box: http://www.springerlink.com/content/95mh987542674584/
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!

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.

It's not quite that simple. Don't forget the third dimension.

Sometimes you can get around it by leaning the box at a vertical angle, thus reducing the length that actually needs to get around the corner.

Edge cases! I actually learned the trick from an immigrant worker with an 8th grade education during a summer job moving furniture into a hotel thing. He had a couple of other neat string tricks to find fits as well. Books, covers etc.
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.

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>

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.

Remember, you are working in 3 dimensions. It may be possible to squeeze something a bit wider than the 2D solution would suggest.
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.

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.

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?
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.

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.

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.

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".

Yeah, this is one of those edge cases where it doesn't satisfy the string test from above, but there is still a chance it could fit.

sqrt[ (57/2)^2 + 22^2 ] = 36", which is greater than 31"

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.