Determine Volumes of n cubes in 3D space

806 Views Asked by At

How to find the shared volume of n overlapping cubes.Where each cube is described by two points in 3D space.(x1, y1, z1) being one corner of the cube and (x2, y2, z2) being the opposite corner.And the sides of each of the cubes are parallel to the axis.

2

There are 2 best solutions below

0
On

Each cube is bound by six planes. The intersection area has to satisfy all of these constraints, which will reduce to 6 active constaints. To reduce the constraints, for each dimension find the greatest lower bound and the smallest upper bound. Once you determine the active constraints then it should be straight forward to find the volume.

0
On

For an axis-aligned cuboid defined by two vertices, $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$, diagonally opposite each other, you can use $$\begin{array}{} x_{min} = \min(x_1, x_2) \\ y_{min} = \min(y_1, y_2) \\ z_{min} = \min(z_1, z_2) \\ x_{max} = \max(x_1, x_2) \\ y_{max} = \max(y_1, y_2) \\ z_{max} = \max(z_1, z_2) \end{array}$$ to find the extents of the cuboid along each coordinate axis. The eight vertices of the cuboid are then $$\begin{array}{} \left ( x_{min}, y_{min}, z_{min} \right ) \\ \left ( x_{max}, y_{min}, z_{min} \right ) \\ \left ( x_{min}, y_{max}, z_{min} \right ) \\ \left ( x_{max}, y_{max}, z_{min} \right ) \\ \left ( x_{min}, y_{min}, z_{max} \right ) \\ \left ( x_{max}, y_{min}, z_{max} \right ) \\ \left ( x_{min}, y_{max}, z_{max} \right ) \\ \left ( x_{max}, y_{max}, z_{max} \right ) \end{array}$$ Similarly, you only need $\min$ and $\max$ to find the extents of the intersection, if two axis-aligned cuboids intersect. It is the exact same operation as in two dimensions or one dimension, just done for all three coordinate axes.