Overlaying two non-rotating cubes is still a box. If the two corner points of the box A (x, y, z) and (x ', y', z ') (x'> x, y '> y, z'> z) and the two corner points of the box B are (a, b, c) and (a ', b', c ') (a'> a, b '> b, c'> c), then the overlap volume is
max(min(a',x')-max(a,x),0) * max(min(b',y')-max(b,y),0) * max(min(c',z')-max(c,z),0)
How to read the formula:
The overlay occurs on the X axis at the maximum of the two coordinates x and a and ends at least on a and x. If the value is <x (i.e., a <a '<x <x'), then there is no overlap, and what happens is that max (a, x) = x> min (a ', x') = a ', therefore, the difference becomes negative, and the volume is equal to zero (therefore, the external max (..., 0)). The same applies to the other two axes.
source share