HN Debrief

Hilariously fast volume computation with the divergence theorem (2018)

  • Mathematics
  • Computer Graphics
  • Programming
  • Developer Tools

The post derives an efficient algorithm for computing the volume of a simple closed triangulated 3D mesh by applying the divergence theorem, so the answer becomes a sum of per-face terms instead of voxelizing, rendering, or doing heavier volumetric work. In plain terms, it turns volume into a surface accounting problem. Several people pointed out that the final formula is the same old signed-volume trick many graphics, CAD, and computational geometry people already use, usually framed as summing tetrahedra against the origin or as the 3D cousin of the shoelace formula for polygon area. What the post added for them was not novelty but a clean derivation that makes the cancellation obvious.

If you need mesh volume or related mass properties, this is a proven O(number of triangles) family of formulas, not a novelty. The practical work is less about math elegance and more about enforcing mesh preconditions, choosing the numerically convenient variant, and deciding whether exact-on-mesh beats a baked or approximate pipeline for your use case.

Discussion mood

Positive and mildly amused. People liked the derivation and the reminder that elegant math can collapse a 3D problem into a cheap surface sum, but many also stressed that the trick is old, widely rediscovered, and should be presented as a classic formula rather than a new algorithm.

Key insights

  1. 01

    This formula has deep historical roots

    The method was placed well before modern graphics practice. References pointed to ACM Algorithm 550 from 1980, a 1970 mass-properties paper, and even an 1899 note on polyhedron volume. That changes the framing from clever blog trick to a standard result that keeps getting rediscovered because it is simple, useful, and easy to derive from first principles.

    If you plan to ship or publish anything around mesh mass properties, do a quick literature pass first and use the established names. It will save you time, give you centroid and inertia extensions for free, and make the result easier for others to trust.

      Attribution:
    • physicsguy #1
    • jacobolus #1
    • lern_too_spel #1
  2. 02

    Tetrahedra, prisms, and divergence are the same computation

    The seemingly different explanations are not competing algorithms. Summing signed tetrahedron volumes against the origin, summing projected prism-like pieces, and the divergence-theorem derivation all collapse to the same determinant-based accounting. The only real difference is constant factors and which form makes the cancellations easiest to see or the code easiest to write.

    Pick the formulation that matches your implementation constraints. For most codebases, the tetrahedron determinant form is the easiest to recognize and test, while the projected-face form can shave arithmetic once expanded.

      Attribution:
    • eterevsky #1
    • Sharlin #1
    • phkahler #1
    • hingler36 #1
    • bmenrigh #1
  3. 03

    The same trick extends to mass properties

    Volume is just the entry-level case. If a quantity can be written as the divergence of a convenient field, the same surface-sum idea gives centroids, inertia matrices, and higher moments. One comment connected this to current transformers as a physical example of turning a hard integral into a boundary measurement, which is a useful mental model for why the method generalizes so broadly.

    Do not stop at volume if your pipeline needs center of mass or rigid-body parameters. Look for a unified mass-properties implementation instead of stacking separate numerical routines.

      Attribution:
    • amluto #1
    • ted_dunning #1
    • ahaferburg #1
  4. 04

    Input validation matters more than the formula

    The hard part in practice is not computing the sum. It is knowing when the mesh satisfies the assumptions behind it. Closedness and consistent orientation are the real requirements. One commenter also noted the method can degrade gracefully when triangles do not perfectly meet, which is helpful, but that is not a substitute for checking topology before you trust the output.

    Treat this as a geometry-kernel operation, not a one-liner. Add mesh validation, orientation checks, and test cases for self-intersections, open seams, and multi-component models before wiring the result into production logic.

      Attribution:
    • ahaferburg #1
    • MarkusQ #1
    • OscarCunningham #1

Against the grain

  1. 01

    Raster methods can still win on throughput

    The article’s swipe at rendering-based volume estimation drew pushback from people who actually use raster hardware. For approximate volume on very dense meshes, 2D rendering plus per-pixel depth-span accumulation can be cheaper than touching every triangle on the CPU. That does not beat the exact mesh formula on elegance, but it can beat it on total system cost when the GPU is already in the loop.

    Do not assume the mathematically exact triangle-sum method is the fastest end-to-end choice. Benchmark against the hardware and error tolerance you already have, especially if your pipeline is GPU-heavy.

      Attribution:
    • chrisjj #1 #2
  2. 02

    Rediscovery is often a feature, not a flaw

    The sniping about prior art met a blunt response. For a small result like this, deriving it yourself can be faster and more reliable than digging through decades of literature, especially when the goal is understanding rather than novelty. In that framing, the post succeeds because it shows the path, not because it claims ownership.

    Encourage engineers to re-derive simple tools when it builds intuition, then connect them to prior art once the idea is clear. That sequence is often the fastest way to get both understanding and correct implementation.

      Attribution:
    • 12_throw_away #1
    • nyeah #1
    • arjie #1

In plain english

CAD
Computer-aided design, software used to create and manipulate engineering or geometric models.
determinant
A number computed from a matrix that, in geometry, can represent signed area or signed volume scaling.
divergence theorem
A result from vector calculus that converts a volume integral over a region into an integral over the surface that encloses it.
exterior algebra
A branch of algebra used to work with oriented areas, volumes, and higher-dimensional analogues in a coordinate-friendly way.
GPU
Graphics Processing Unit, a processor specialized for rendering graphics and often used for AI and other compute-heavy workloads.
polyhedron
A 3D solid bounded by flat polygon faces.
shoelace formula
A standard formula for computing the area of a polygon from its vertex coordinates using signed sums.
triangulated
Broken into triangles so the surface can be represented and computed with piece by piece.
voxelizing
Converting a 3D shape into a grid of small volume cells, like 3D pixels.

Reference links

Historical papers and algorithms

Math references and explanations

Videos and visual intuition

Robustness and related concepts