Simple Collision Detection

Box-Box Collision

Compute the overlap of two boxes - the region of points which are contained in both boxes. If an overlap exists, they collide.

def BoxCollidesWithBox(box1, box2):
    minx = max(box1.minX, box2.minX)
    maxx = min(box1.maxX, box2.maxX)
    miny = max(box1.minY, box2.minY)
    maxy = min(box1.maxY, box2.maxY)
    minz = max(box1.minZ, box2.minZ)
    maxz = min(box1.maxZ, box2.maxZ)
    return (minx <= maxx) and (miny <= maxy) and (minz <= maxz)