Hilariously fast volume computation with the divergence theorem (2018)(alyssarosenzweig.ca)
261 points by luu 13 days ago | 67 comments
tl;dr: Using the divergence theorem with F = ⟨x,0,0⟩, the volume of a closed triangulated mesh reduces to a simple sum over triangles, requiring only ~11 floating-point operations per triangle (no numerical integration needed). The resulting formula is V = (1/6) Σ (Δ₁×Δ₂)ₓ · (T₀ₓ + T₁ₓ + T₂ₓ), which is O(n) and fast enough to process ~30 million triangles per frame at 60fps on a Raspberry Pi. The author notes the algorithm likely isn't novel—a similar approach appears in prior work by Zheng and Chen.
HN Discussion:
  • ~This technique is well-known and can be derived from basic geometric intuition without vector calculus
  • Provides historical or alternative references showing prior art for the same approach
  • Enthusiastic appreciation for learning this elegant, simple technique
  • Adds practical caveats about mesh preconditions and extensions to other properties like inertia
  • Questions the practical need for per-frame computation since volume can be precomputed