[Math] Volume of the intersection of two rectangular parallelepipeds

geometry

Given two rectangular parallelepipeds in $3D$ space, how would you compute the volume of their intersection? The orientations of the two rectangular parallelepipeds are not constrained in any special way. Each parallelepiped is described by a point $P$ that is a corner of the $parallelepiped$ as well as vectors $F$, $G$, and $H$ which represent the three mutually orthogonal edges that meet at point $P$.

Best Answer

A workable way would be to clip all 6 boundary faces of each box against the boundary planes of the other, which leaves you with a bunch of convex faces that form the boundary of the intersection object. The actual volume of this object can be calculated by

$$ V = \frac{1}{3} \sum_{F_i \in Faces} \vec p_i \cdot \vec n_i A_i $$

in which $\vec p_i$ is a point on the face, $\vec n_i$ is the unit face normal and $A_i$ is the area of face $F_i$. Take care to keep the orientation of the faces consistent, however.