Jacob Harding
Software Engineer | C++ Specialist | Graphics Enthusiast
I’m currently on the lookout for my next software engineering role — if you know of something cool, feel free to reach out! 😊
Tetrahedron Volume Gradient
2025-04-12The (signed) volume of a tetrahedron can be calculated as:
\[ V_{tet} = \frac{1}{6} (\mathbf{x}_1 - \mathbf{x}_0) \cdot ((\mathbf{x}_2 - \mathbf{x}_0) \times (\mathbf{x}_3 - \mathbf{x}_0)) \]This formula is derived from the volume of a parallelepiped. Computing the derivative of this volume is essential in many deformable body simulations which are built ontop of tetrahedral finite elements.
I’m going to make use of the dot product and cross product matrix calculus identities as well as cross product matrices in the derivation that follows. The later two of which I covered in my previous post. I leave them here for reference:
\[ \bbox[5px,border:2px solid lightblue] { \nabla_{\mathbf{x}} (\mathbf{f}(\mathbf{x}) \cdot \mathbf{g}(\mathbf{x})) = (\frac{\partial \mathbf{f}}{\partial \mathbf{x}})^{\top} \mathbf{g} + (\frac{\partial \mathbf{g}}{\partial\mathbf{x}})^{\top} \mathbf{f} } \] \[ \bbox[5px,border:2px solid lightblue] { \frac{\partial}{\partial\mathbf{x}}(\mathbf{f}(\mathbf{x}) \times \mathbf{g}(\mathbf{x})) = (\frac{\partial \mathbf{f}}{\partial \mathbf{x}} \times \mathbf{g}) - (\frac{\partial \mathbf{g}}{\partial \mathbf{x}} \times \mathbf{f}) } \] \[ \bbox[5px,border:2px solid lightblue] { [\mathbf{v}]_{\times} \mathbf{u} = \mathbf{v} \times \mathbf{u} } \]Now lets differentiate with respect to each point.
Defining:
\[ \mathbf{a} = \mathbf{x}_1 - \mathbf{x}_0, \mathbf{b} = \mathbf{x}_2 - \mathbf{x}_0, \mathbf{c} = \mathbf{x}_3 - \mathbf{x}_0 \]This gives:
\[ \begin{aligned} \nabla_{\mathbf{x}_0} V &= \frac{1}{6} \nabla_{\mathbf{x}_0} \left( \mathbf{a} \cdot (\mathbf{b} \times \mathbf{c}) \right) \\ &= \frac{1}{6} [ (\frac{\partial \mathbf{a}}{\partial \mathbf{x}_0})^{\top}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial (\mathbf{b} \times \mathbf{c})}{\partial \mathbf{x}_0})^{\top} \mathbf{a}] \\ &= \frac{1}{6} [ -\mathbf{I}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial \mathbf{b}}{\partial \mathbf{x}_0} \times \mathbf{c} - \frac{\partial \mathbf{c}}{\partial \mathbf{x}_0} \times \mathbf{b} )^{\top} \mathbf{a} ] \\ &= \frac{1}{6} [ -(\mathbf{b} \times \mathbf{c}) + (- \mathbf{I} \times \mathbf{c} + \mathbf{I}\times \mathbf{b} )^{\top} \mathbf{a} ] \\ &= \frac{1}{6} [ -(\mathbf{b} \times \mathbf{c}) + ([\mathbf{c}]_{\times} - [\mathbf{b}]_{\times})^{\top} \mathbf{a} ] \\ &= \frac{1}{6} [ -(\mathbf{b} \times \mathbf{c}) + (-[\mathbf{b}]_{\times}^{\top} + [\mathbf{c}]_{\times}^{\top}) \mathbf{a} ] \\ &= \frac{1}{6} [ -(\mathbf{b} \times \mathbf{c}) + ([\mathbf{b}]_{\times} - [\mathbf{c}]_{\times}) \mathbf{a} ] \\ &= \frac{1}{6} [ -(\mathbf{b} \times \mathbf{c}) + (\mathbf{b} \times \mathbf{a}) - (\mathbf{c} \times \mathbf{a}) ] \\ &= \frac{1}{6} [ -(\mathbf{b} \times \mathbf{c}) - (\mathbf{a} \times \mathbf{b}) - (\mathbf{c} \times \mathbf{a}) ] \\ &= -\frac{1}{6} [(\mathbf{b} \times \mathbf{c}) + (\mathbf{a} \times \mathbf{b}) + (\mathbf{c} \times \mathbf{a}) ] \\ \\ \\ \nabla_{\mathbf{x}_1} V &= \frac{1}{6} \nabla_{\mathbf{x}_1} \left( \mathbf{a} \cdot (\mathbf{b} \times \mathbf{c}) \right) \\ &= \frac{1}{6} [ (\frac{\partial \mathbf{a}}{\partial \mathbf{x}_1})^{\top}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial (\mathbf{b} \times \mathbf{c})}{\partial \mathbf{x}_1})^{\top} \mathbf{a}] \\ &= \frac{1}{6} [\mathbf{I}(\mathbf{b} \times \mathbf{c}) + (\mathbf{0})^{\top} \mathbf{a} ] \\ &= \frac{1}{6} \mathbf{b} \times \mathbf{c} \\ \\ \\ \nabla_{\mathbf{x}_2} V &= \frac{1}{6} \nabla_{\mathbf{x}_2} \left( \mathbf{a} \cdot (\mathbf{b} \times \mathbf{c}) \right) \\ &= \frac{1}{6} [ (\frac{\partial \mathbf{a}}{\partial \mathbf{x}_2})^{\top}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial (\mathbf{b} \times \mathbf{c})}{\partial \mathbf{x}_2})^{\top} \mathbf{a}] \\ &= \frac{1}{6} [\mathbf{0}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial \mathbf{b}}{\partial \mathbf{x}_2} \times \mathbf{c} - \frac{\partial \mathbf{c}}{\partial \mathbf{x}_2} \times \mathbf{b} )^{\top} \mathbf{a} ] \\ &= \frac{1}{6} [(\frac{\partial \mathbf{b}}{\partial \mathbf{x}_2} \times \mathbf{c} - \frac{\partial \mathbf{c}}{\partial \mathbf{x}_2} \times \mathbf{b} )^{\top} \mathbf{a}] \\ &= \frac{1}{6} [(\mathbf{I} \times \mathbf{c} - \mathbf{0} \times \mathbf{b} )^{\top} \mathbf{a}] \\ &= \frac{1}{6} [(-[\mathbf{c}]_{\times})^{\top} \mathbf{a}] \\ &= \frac{1}{6} \mathbf{c} \times \mathbf{a} \\ \\ \\ \nabla_{\mathbf{x}_3} V &= \frac{1}{6} \nabla_{\mathbf{x}_3} \left( \mathbf{a} \cdot (\mathbf{b} \times \mathbf{c}) \right) \\ &= \frac{1}{6} [ (\frac{\partial \mathbf{a}}{\partial \mathbf{x}_3})^{\top}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial (\mathbf{b} \times \mathbf{c})}{\partial \mathbf{x}_3})^{\top} \mathbf{a}] \\ &= \frac{1}{6} [\mathbf{0}(\mathbf{b} \times \mathbf{c}) + (\frac{\partial \mathbf{b}}{\partial \mathbf{x}_3} \times \mathbf{c} - \frac{\partial \mathbf{c}}{\partial \mathbf{x}_3} \times \mathbf{b} )^{\top} \mathbf{a} ] \\ &= \frac{1}{6} [(\mathbf{0} \times \mathbf{c} - \mathbf{I} \times \mathbf{b} )^{\top} \mathbf{a}] \\ &= \frac{1}{6} [([\mathbf{b}]_{\times})^{\top} \mathbf{a}] \\ &= \frac{1}{6} \mathbf{a} \times \mathbf{b} \\ \end{aligned} \]As a summary:
\[ \bbox[5px,border:2px solid blue]{ \begin{aligned} \nabla_{\mathbf{x}_0} V &= -\frac{1}{6} [(\mathbf{b} \times \mathbf{c}) + (\mathbf{a} \times \mathbf{b}) + (\mathbf{c} \times \mathbf{a}) ] \\ \nabla_{\mathbf{x}_1} V &= \frac{1}{6} \mathbf{b} \times \mathbf{c} \\ \nabla_{\mathbf{x}_2} V &= \frac{1}{6} \mathbf{c} \times \mathbf{a} \\ \nabla_{\mathbf{x}_3} V &= \frac{1}{6} \mathbf{a} \times \mathbf{b} \end{aligned} } \]