16 comments

  • physicsguy6 hours ago
    This is one of those when you go &quot;Huh, this is amazing!&quot; or &quot;Huh, I thought this trick was really well known!&quot; depending on your background ;)<p>Here&#x27;s a similar impl from 1980 written in Fortran that also computes other properties like centroid: <a href="https:&#x2F;&#x2F;calgo.acm.org&#x2F;550.zip" rel="nofollow">https:&#x2F;&#x2F;calgo.acm.org&#x2F;550.zip</a> Algorithm 550: Solid Polyhedron Measures A. M. Messner and G. Q. Taylor ACM Trans. Math. Softw., 6(1), Mar 1980, pp.121--130 Keywords: polyhedron, graphics, numerical integration Language: Fortran 66&#x2F;77; Shar Index: Z; Gams: P File size: 19.1 KB;<p>But Messner published it first in: A. M. Messner, &quot;A surface Integral method for computer calculation of mass properties&quot;, Paper No. 852, 29TH ANNUAL CONF. OF THE SOCIETY OF AERONAUTICAL WEIGHT ENGINEERS, Washington, D.C., May 1970.<p>I think
    • jacobolus3 hours ago
      This is one variant of the 3-d analog of the &quot;shoelace formula&quot; for area:<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shoelace_formula#Generalization" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shoelace_formula#Generalizatio...</a><p>The 2-d version is from the 18th century. I&#x27;d expect the 3-d version was probably known in the 19th century, but I haven&#x27;t searched for a reference.
    • amluto3 hours ago
      This technique should be straightforwardly adaptable to compute arbitrary moments, not just the centroid.<p>If you have a scalar-valued function that you can conveniently express as the divergence of any closed-form function, you can integrate it like this. And you can generalize beyond scalar-valued functions and beyond Euclidean space using the generalized Stokes’ theorem.<p>You can even do this in real life: if you want to integrate the electric current density through a surface (that is, measure the total current crossing the surface), you can integrate its anti-curl (is that a word?) around the boundary of that surface, which is what a current transformer or a clamp-on current meter does.<p>I bet there’s a hydraulic or pneumatic analog as well, but a nontrivial example isn’t immediately coming to mind.
  • eterevsky8 hours ago
    Isn&#x27;t the same as just taking every triangle from the mesh, calculating the volume of a prism-like polytope between it and its projection on one the planes, and then taking it with a + sign if its projection is oriented in one direction, and with a - sign if it&#x27;s oriented in another? This kind of formula works based on the basic geometry.
    • Sharlin7 hours ago
      Yes, this is essentially what the author derived (by means of calculus rather than geometric argument but the result is unsurprisingly the same). The 2D analog is easy to grok: to compute the area of a polygon, find the sum of the signed areas of each of the trapezoids formed by an edge and its projection on the x-axis. Turns out the negative areas of the right-to-left trapezoids cancel precisely out any excess area of the left-to-right trapezoids (or in the case of edges below the x-axis, add precisely the &quot;missing&quot; area).
    • cgadski7 hours ago
      Yep. Using the same kind of calculus ideas, I can also think about a vector field that has a Dirac mass of divergence at some point and zero divergence everywhere else. Then you get an expression that you can sum over faces to determine if a polyhedron contains some point. Again, for the right vector field there is a simple geometric interpretation, namely the solid angle that a face makes with respect to the point.
    • joelthelion6 hours ago
      &gt; calculating the volume of a prism-like polytope between it and its projection<p>There is the key insight that you don&#x27;t need to explicitly compute this projection.
    • gloveone3 hours ago
      Yes, the algorithm and its derivations are elementary and rather obvious for anyone decent at undergraduate level mathematics. But still, I am glad to see more people enjoying math!
    • xigoi7 hours ago
      I wonder if this could be reversed to give an intuitive “proof” of the divergence theorem.
      • meindnoch6 hours ago
        The divergence theorem can be intuitively summarized in one sentence: &quot;what comes out is whatever went in, plus whatever was produced inside&quot;
        • MarkusQ3 hours ago
          Minus whatever went away inside, unless you&#x27;re implicitly allowing negative production.
          • meindnoch2 hours ago
            Yes, both &quot;production&quot; and &quot;comes out&quot; are signed quantities.
      • seanhunter3 hours ago
        A very intuitive presentation of the divergence theorem is here <a href="https:&#x2F;&#x2F;youtu.be&#x2F;TORt20_HjMY?is=uoJ8-2ToCSwW9rVF" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;TORt20_HjMY?is=uoJ8-2ToCSwW9rVF</a>
    • aaa_aaa8 hours ago
      Yes I remember doing something like that in 90s for a survey&#x2F;map engineering cad application. After delaunay triangulation, calculating approximate voulume is easy. But this probably is a more general solution
      • srean5 hours ago
        Yes it goes by a couple of names. Surveyor&#x27;s formula, shoelace formula.<p>The Surveyor’s Area Formula Bart Braden The College Mathematics Journal, September 1986, Volume 17, Number 4.<p><a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20150406152731if_&#x2F;http:&#x2F;&#x2F;www.maa.org&#x2F;sites&#x2F;default&#x2F;files&#x2F;pdf&#x2F;pubs&#x2F;Calc_Articles&#x2F;ma063.pdf" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20150406152731if_&#x2F;http:&#x2F;&#x2F;www.maa...</a>
        • sigbottle3 hours ago
          Oh, it is the shoelace formula, but for 3D?<p>OP&#x27;s description vaguely triggered memories of the shoelace formula from a decade ago, but geometry was never my strong suit. All I remembered was positive&#x2F;negative triangles (or was it trapezoids)? make magic happen for area calculation.
    • diabllicseagull6 hours ago
      reminds me of that 1994 paper that reinvented the trapezoidal rule
      • MarkusQ3 hours ago
        Except this one 1) didn&#x27;t try to name it after themselves, 2) explicitly told us it wasn&#x27;t new, and linked to an example of prior work, and 3) isn&#x27;t generally taught in high school.
        • diabllicseagull1 hour ago
          see, when I say something reminds me of something else I don&#x27;t mean a one-to-one equivalence at every aspect one can think of.<p>anyhoo, it&#x27;s always a great skill to review the state-of-the-art BEFORE investing in a work&#x2F;write-up&#x2F;article - one of the very first things that a post-graduate program would teach you.
          • 12_throw_away1 hour ago
            Nah. Being able to derive and prove easy results like this for yourself is both way faster and more reliable than trying to wade through the literature to find the equation you want.
  • srean6 hours ago
    On the other hand, if you want to compute the <i>area</i> of a polygon that have vertices at lattice points, you can count the number of interior points <i>I</i>, the number of boundary points <i>B</i>. Then the area <i>A</i> is<p><pre><code> A = I + B&#x2F;2 - 1 </code></pre> This is Pick&#x27;s theorem<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pick&#x27;s_theorem" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pick&#x27;s_theorem</a><p>one of my favorite results. It does not generalize as nicely to higher dimensions unfortunately.<p>If like the post you want the volume of a polyhedron you can use the three dimensional analogue of the shoelace formula (essentially equivalent).<p>Let <i>Va, Vb</i> and <i>Vc</i> be the vertices of a triangle ∆ of a triangulation of the surface. You need to name the vertices in a consistent order&#x2F;orientation wrt the origin.<p>Then the volume <i>V</i> is the sum over all such triangles of the signed volumes<p><pre><code> V_∆ = 1&#x2F;6 Va ^ Vb ^ Vc. </code></pre> That&#x27;s the beauty of signed areas and volumes, determinants and exterior algebra.<p>To understand why this is so there&#x27;s this beautiful short video<p><a href="https:&#x2F;&#x2F;youtu.be&#x2F;Sv7VseMsOQc" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;Sv7VseMsOQc</a>
    • sebastianmestre5 hours ago
      From a computational standpoint, Pick&#x27;s theorem seems more useful to find the number of interior points via<p><pre><code> I = 2 (A - B + 1) </code></pre> Where area would be calculated using the sum of signed areas of triangles.
      • srean5 hours ago
        Indeed.<p>One of my <i>off by one</i> errors is a stupid hacky Monte Carlo intution for Picks theorem.<p>I count the number of points inside. Now about the boundary points I must assign some fractional weight because they are not fully inside. What&#x27;s a stupid fraction I can use? Well, half seems about right. Voila,<p><pre><code> A = I + B&#x2F;2.</code></pre>
  • elikoga8 hours ago
    My belly says the naive formula is summing the triangle pyramid volumes to the origin with sign in orientation. It looks like that&#x27;s what they derived. Which is a generalization of 2d polygon area calculated by summing triangle areas for each edge, I was taught this in a math camp where we calculated map polygon areas on gis data. I remember math knowledge being hard to get pre AI era but I didn&#x27;t remember it being this hard.<p>No idea what the author means by &quot;which are equivalent to rendering the mesh and then sampling the render&quot;.
    • less_less6 hours ago
      &gt; My belly says the naive formula is summing the triangle pyramid volumes to the origin with sign in orientation.<p>Yeah, that would also work but it&#x27;s a slightly slower formula, sum(det(v1,v2,v3))&#x2F;6. This one is summing sort of prism+pyramid shapes made by projecting each triangle to the yz plane.
    • chrisjj3 hours ago
      I&#x27;d say what author means is the standard solution - which is equivalent to his on triangles but is on pixels ... except there&#x27;s nothing naive about it and by using GPU parallelism and depth hardware it is lower cost on dense meshes.
      • uecker2 hours ago
        I really hope nobody computes the volume by rendering in 3D and counting pixels.
  • ahaferburg5 hours ago
    The emphasis here is on the mesh being simple and closed. Make sure to validate these preconditions before relying on the output.<p>Similar formulas exist for moments, to compute the inertia matrix for a rigid body.
    • MarkusQ3 hours ago
      Closed is clearly important. Why does it have to be simple? It looks like it should handle disjoint components, interior holes, etc. just fine?
  • arn3n8 hours ago
    I love these kinds of posts. Simple, fast, AI-free, and I learn something new.
    • alex_suzuki6 hours ago
      (2018)
      • IAmBroom4 hours ago
        OMG, that absolute dummy didn&#x27;t know something that a human did in 2018!<p>Are they not reading the entire internet every morning, when they wake up???
        • alex_suzuki4 hours ago
          I was merely pointing out that the post was published in 2018 so AI-free is kind of implied.
  • OscarCunningham1 hour ago
    It&#x27;s also robust to errors in the mesh. Like if the triangles don&#x27;t quite join up it still gives a reasonable answer. <a href="https:&#x2F;&#x2F;mathstodon.xyz&#x2F;@keenancrane&#x2F;109388206643166726" rel="nofollow">https:&#x2F;&#x2F;mathstodon.xyz&#x2F;@keenancrane&#x2F;109388206643166726</a>
  • meindnoch7 hours ago
    Don&#x27;t really need vector calculus for this. Geometric intuition is sufficient. It is simply the summation of signed volumes of triangular columns&#x2F;prisms parallel to the X axis.<p>Visualization: <a href="https:&#x2F;&#x2F;jsfiddle.net&#x2F;L7r1hwca&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsfiddle.net&#x2F;L7r1hwca&#x2F;</a><p>I don&#x27;t know what they could possibly mean by the naïve algorithms with rendering and sampling (???).
    • nyeah6 hours ago
      Yeah, agreed. But words are cheap. It&#x27;s one thing to say we don&#x27;t need vector calculus, and another to develop that claim through the actual vector calculus, step by step.
  • gurkwart7 hours ago
    There&#x27;s a really elegant solution using Geometric Algebra, that to this day is one of the most satisfying things I&#x27;ve ever learnt. Steven de Keninck outlines it in his 2019 Siggraph talk [1].<p>[1] <a href="https:&#x2F;&#x2F;youtu.be&#x2F;tX4H_ctggYo?t=4795" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;tX4H_ctggYo?t=4795</a>
  • bob10296 hours ago
    &gt; For a ballpark number, if volume needs to be calculated every frame in a high-performance 60 frames per second application, without the aid of a GPU, only using the CPU capabilities of a $35 Raspberry Pi, around 30 million triangles could be measured every frame.<p>If knowing the volume of a mesh is important, we could pre-calculate it (even using this exact technique) and store it as an attribute on the object. Lots of things in game dev that are modeled as an integral over three+ dimensions tend to work better as a baked setup rather than real time. We kickstarted an entire AI industry trying to chase real time lighting.
  • Isofarro5 hours ago
    I&#x27;m sorry, English is my first language. What does &quot;Hilariously&quot; mean in this context? Or is there a maths specific meaning&#x2F;interpretation?
    • Joker_vD2 hours ago
      <p><pre><code> Adverb hilariously (comparative more hilariously, superlative most hilariously) 1. In a hilarious manner; so as to amuse greatly. </code></pre> The author was greatly amused how quick the resulting algorithm works.
    • hallgrim5 hours ago
      The author is just expressing amusement at the surprising simplicity of the resulting algorithm
    • MarkusQ3 hours ago
      It&#x27;s an intensifier. As a native English speaker you should probably be aware that we eventually sand-blast the semantics off of words until they all becomes synonyms for &quot;good&quot;, &quot;bad&quot;, &quot;very&quot;, or &quot;um&quot;. (This is similar to what French does to phonemes, but unrelated.)
  • N_Lens8 hours ago
    I&#x27;ll accept any kind of jocularity in the current climate!
  • FartyMcFarter6 hours ago
    &gt; (No, there won’t be jokes.)<p>I must be missing something here, inside joke or something in the title?
    • Agentlien6 hours ago
      I assume it&#x27;s because the title contains &quot;hilariously&quot; and the author felt it necessary to state the content wasn&#x27;t meant as humorous.
  • gigatexal8 hours ago
    Did they also work on the graphics stack for the Asahi project?
    • StilesCrisis7 hours ago
      Yup!
    • gigatexal3 hours ago
      I used to watch their vtuber videos on YouTube!
    • unkeen7 hours ago
      Sadly, there is no way to find out, f.ex. by a quick Google search.
  • lern_too_spel4 hours ago
    You might be interested in the shoelace formula and its generalization to n dimensions. <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shoelace_formula" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shoelace_formula</a>
    • lern_too_spel1 hour ago
      For this particular case of 3 dimensions, I found<p>Newson, H. B. “On the Volume of a Polyhedron.” Annals of Mathematics, vol. 1, no. 1&#x2F;4, 1899, pp. 108–10. JSTOR, <a href="https:&#x2F;&#x2F;doi.org&#x2F;10.2307&#x2F;1967277" rel="nofollow">https:&#x2F;&#x2F;doi.org&#x2F;10.2307&#x2F;1967277</a>
  • flerovium1146 hours ago
    [dead]