You should be able to modify Determine if two rectangles overlap each other? to your purpose fairly easily.
Suppose that you have CubeA
and CubeB
. Any one of 6 conditions guarantees that no overlap can exist:
Cond1. If A's left face is to the right of the B's right face,
- then A is Totally to right Of B
CubeA.X2 < CubeB.X1
Cond2. If A's right face is to the left of the B's left face,
- then A is Totally to left Of B
CubeB.X2 < CubeA.X1
Cond3. If A's top face is below B's bottom face,
- then A is Totally below B
CubeA.Z2 < CubeB.Z1
Cond4. If A's bottom face is above B's top face,
- then A is Totally above B
CubeB.Z2 < CubeA.Z1
Cond5. If A's front face is behind B's back face,
- then A is Totally behind B
CubeA.Y2 < CubeB.Y1
Cond6. If A's left face is to the left of B's right face,
- then A is Totally to the right of B
CubeB.Y2 < CubeA.Y1
So the condition for no overlap is:
Cond1 or Cond2 or Cond3 or Cond4 or Cond5 or Cond6
Therefore, a sufficient condition for Overlap is the opposite (De Morgan)
Not Cond1 AND Not Cond2 And Not Cond3 And Not Cond4 And Not Cond5 And Not Cond6