RC RANDOM CHAOS

The divergence theorem turns mesh volume into a single O(n) triangle loop

· via Hacker News

Original source

Hilariously fast volume computation with the divergence theorem (2018)

Hacker News →

Alyssa Rosenzweig derives a fast method for computing the volume of a closed, triangulated 3D mesh by applying the divergence theorem. Volume is normally a triple integral of the constant 1 over a region; by choosing a vector field whose divergence equals 1, that volume integral collapses into a surface integral over the mesh’s boundary. Because the surface is just a collection of triangles, the whole computation reduces to a sum over each triangle, and the relevant cross product is constant across a triangle and cheap to evaluate directly from vertex coordinates.

The payoff is a closed-form formula with no numerical integration or differentiation and a single loop over triangles, making it linear in triangle count. Each triangle costs only seven additions and three multiplications, with one extra multiply outside the loop, versus naive approaches that effectively render the mesh and sample it. The author estimates a $35 Raspberry Pi could process on the order of 30 million triangles per frame at 60 fps on the CPU alone.

The piece is a compact math walkthrough rather than a security or product story. Rosenzweig notes it was written while studying for a vector calculus exam and adds that the algorithm is almost certainly not novel — a paper by Cha Zheng and Tsuhan Chen on feature extraction for mesh objects reaches the same result through a different derivation.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.