If one box can fit inside the other than it can fit also if boxes have same center. So only rotation is enough to check, translation is not needed to check.
2D case: For boxes X=(2A,2B)
and x=(2a,2b)
positioned around (0,0)
. That means corners of X
are (+-A, +-B)
.
---------(A,B)
|
-----------(a,b)
(0,0) |
-----------(a,-b)
|
---------(A,-B)
Be rotating x
around (0,0)
, corners are always on circle C
with radius sqrt(a^2+b^2)
. If part of circle lie inside box X
, and if part inside X
has enough arc length to place 2 points on distance 2a
or 2b
, than x
can fit inside X
. For that we need to calculate intersection of C
with lines x=A
and y=B
, and calculate distance between these intersection. If distance is equal or grater than 2a
or 2b
, than x
can fit inside X
.
3D case: Similar. For boxes X=(2A,2B,2C)
and x=(2a,2b,2c)
positioned around (0,0,0)
. Rotating x
around (0,0,0)
, all corners move on sphere with radius sqrt(a^2+b^2+c^2)
. To see is there enough space on sphere-box intersection part, find intersection of sphere with planes x=A
, y=B
and z=C
, and check is there enough space to fit any of quads (2a,2b)
, (2a,2c)
or (2b,2c)
on that sphere part. It is enough to check are points on part border on sufficient distance. For this part I'm not sure about efficient approach, maybe finding 'center' of intersection part and checking it's distance to border can help.