# packing boxes inside boxes

given 2 boxes (in 3-space) determine if one of the boxes resides within the other, or if a third box must be constructed that holds them both?

given that a box is defined by its center($x,y,z$), and its dimensions($W, H, D$).

consider that

• the boxes are immovable,
• can not have their properties altered,
• and all tests must be done with fundamental logic.
-
What is the question? – Gerry Myerson Apr 12 '12 at 3:40
@GerryMyerson edited. – gardian06 Apr 12 '12 at 3:45

Presumably the boxes are aligned with the axes and you have a definition that $W$ is the width in $x, H$ in $Y$, and $L$ in $z$. Call the centers $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$. Then box $1$ is inside box $2$ if $x_1-W_1/2 \gt x_2-W_2/2, x_1+W_1/2 \lt x_2+W_2/2$ and so on.
@gardian06: There are two tests in each dimension for box 1 inside box 2. I gave the two in $x$. You need all six to pass for box 1 to be in 2. Then there are six more to see if 2 is in 1, which you should be able to figure out by symmetry. If you are going to build a single box, it needs to have the minimum $x$ coordinate equal to the minimum $x$ of either box and so on-again the same logic I used. – Ross Millikan Apr 12 '12 at 4:14