Skip to content

Fix false intersections for coplanar triangles with collinear edges - #113

Open
clintmorris229 wants to merge 1 commit into
SarahWeiii:mainfrom
clintmorris229:fix/collinear-edge-false-intersections
Open

clintmorris229 wants to merge 1 commit into
SarahWeiii:mainfrom
clintmorris229:fix/collinear-edge-false-intersections

Conversation

@clintmorris229

Copy link
Copy Markdown
Contributor

Fixes #89.

edge_edge_test, used by coplanar_tri_tri, computed its cross products in float. For two collinear edges, f, d and e should be 0, but rounding left small, equal values (e.g. all ≈ −2.3e-10). Those passed the general-case check as a crossing at the edges' endpoints. The collinear branch, which would correctly find no overlap, only runs afterwards, with an absolute tolerance smaller than the noise. As a result, TriangleIntersects::triangle reported intersections between coplanar triangles that don't touch, and IsManifold flagged valid meshes as self-intersecting, triggering unnecessary preprocessing. Which inputs trigger it depends on FMA contraction: the example in #89 fails only with FMA; the one below fails only without.

This change computes the edge-edge test in at least double. For float inputs, that makes rounding errors in f, d and e negligible, so collinear and nearly collinear edges are classified correctly. Double inputs are unchanged.

Repro (returns 1 1 before, 0 0 after):

using V = coacd::IntersectVector3;
using M = threeyd::moeller::TriangleIntersects<V>;
// Plane z = 0. Each triangle has one edge on the line y = x + 0.1; the edges
// are collinear but don't overlap, and the triangles don't touch.
V a0{0.5f, 0.6f, 0.f}, a1{0.4f, 0.5f, 0.f}, a2{0.5f, 0.5f, 0.f};
V b0{0.1f, 0.2f, 0.f}, b1{0.3f, 0.4f, 0.f}, b2{0.3f, 0.2f, 0.f};
std::printf("%d %d\n", M::triangle(a0, a1, a2, b0, b1, b2),
            M::triangle(b0, b1, b2, a0, a1, a2));

Testing, against an exact 2D reference, with and without -mfma -ffp-contract=fast:

Before (no FMA / FMA) After
#89 example and two others 2 / 1 wrong 0
200k coplanar pairs with collinear, disjoint edges 8,531 / 1,370 wrong 0
200k random coplanar pairs 0 / 0 wrong 0

edge_edge_test computed its cross products in float. For collinear edges,
rounding left small equal values in f, d and e that passed the general-case
check as a crossing, so coplanar triangles that don't touch were reported as
intersecting and IsManifold flagged valid meshes (SarahWeiii#89). Compute the test in at
least double so these rounding errors are negligible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatic preprocess mode sometimes activates unnecessarily due to false triangle intersections

1 participant