Skip to content
Projects

Triangle hit test

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

triangle_fractions

functionsource

Fractions t and barycentric u, v where segments meet triangles.

fraction
t=e2⋅qe1⋅p,u=s⋅pe1⋅p,v=d⋅qe1⋅p,p=d×e2,q=s×e1,s=a−v0t = \frac{e_2 \cdot q}{e_1 \cdot p}, \quad u = \frac{s \cdot p}{e_1 \cdot p}, \quad v = \frac{d \cdot q}{e_1 \cdot p}, \qquad p = d \times e_2, \quad q = s \times e_1, \quad s = a - v_0
hit
e1⋅p≠0,u≥0,v≥0,u+v≤1e_1 \cdot p \ne 0, \quad u \ge 0, \quad v \ge 0, \quad u + v \le 1
Assumes
  • triangle v0v1v2v_0 v_1 v_2 with e1=v1−v0e_1 = v_1 - v_0, e2=v2−v0e_2 = v_2 - v_0; segment a+tda + t d, tt the fraction of the step
  • edges and vertices belong to the triangle; a segment in the triangle's plane (e1⋅p=0e_1 \cdot p = 0) never meets it
  • the same arithmetic as the Pyccel kernels mesh_first_hits and mesh_inside
References