Skip to content
Projects

TriangleMesh

The equations of simgeometry.objects.triangle_mesh, declared on the code that implements them and checked by the tests.

TriangleMesh

classsource

A surface made of triangles: closed (a solid) or open (panels).

volume
V=16∑fv0⋅(v1×v2)V = \frac16 \sum_f v_0 \cdot (v_1 \times v_2)
normal
nf=(v1−v0)×(v2−v0)∣(v1−v0)×(v2−v0)∣n_f = \frac{(v_1 - v_0) \times (v_2 - v_0)}{|(v_1 - v_0) \times (v_2 - v_0)|}
inside
p∈S  ⟺  s(q)⊕(#{f:[p,q]∩f≠∅} mod 2),q the node of p’s cell nearest to pp \in S \iff s(q) \oplus \bigl(\#\{f : [p, q] \cap f \ne \emptyset\} \bmod 2\bigr), \qquad q \text{ the node of } p\text{'s cell nearest to } p
nodes
s(q)=maj⁡k=x,y,z(#{f:the grid line along k meets f before q} mod 2)s(q) = \operatorname{maj}_{k = x, y, z}\Bigl(\#\{f : \text{the grid line along } k \text{ meets } f \text{ before } q\} \bmod 2\Bigr)
Order
2
Assumes
  • closed: every edge in exactly two faces, each directed edge once (consistent orientation); faces are reoriented so that V>0V > 0 and nfn_f points out
  • open meshes have no inside (contains is False everywhere) and their normals face the incoming segment
  • a uniform grid of about four cells per face over the mesh's box, shifted by irrational fractions of a cell; every cell lists the faces whose box (widened by 10−910^{-9} cells) overlaps it
  • first hits walk the segment's cells in order (Amanatides and Woo) and test their faces exactly (Möller–Trumbore), stopping once the nearest hit lies before the cell's exit; hits at t≤10−12t \le 10^{-12} are ignored
  • exact for the triangles, except for a segment through an edge or vertex exactly, where a crossing may count twice
  • the order is that of the volume of a sphere's mesh in the angular spacing
References
Built from