BrunoLevy / geogram

a programming library with geometric algorithms
Other
1.8k stars 122 forks source link

In mesh_surface_intersection, point outside boundary assertion failure in constrained Delaunay triangulation #110

Closed BrunoLevy closed 10 months ago

BrunoLevy commented 10 months ago

With Spiral_sphere_ornament_2013-11-23.stl (from Thingy10K), in debug mode:

  $ bin/intersect Spiral_sphere_ornament_2013-11-23.stl

assertion fail with inserted point outside boundary (!!!)

BrunoLevy commented 10 months ago

May come from a super skinny triangle nearly identical to a segment oriented towards (1,1,1) (worst case for chosing a projection direction) ?

OK, so I understand nothing, let's go "little spoon debugging mode", we only got five points and two triangles, so let us double check the result of orient_3d() and the 2D cases. Another possibility is a bug in orient3d() (a bit unlikely but who knows). So we could re-implement it with exact_nt and see what happens...

The two faulty triangles are like that: one of them has two nearly colocated vertices, and is sharing a vertex with the other one (that has a rather normal shape). Even by zooming a lot on the two nearly colocated vertices, one cannot see that they are not the same, but in CDT2d, projected_orient2d() never returned ZERO, so the triangle is probably valid (but very very degenerate).

When displaying the combinatorial information in the triangle-triangle intersection, it seems that there are incoherencies.

Next step: do a little drawing, with the points and edges labeled, to figure out what the combinatorial information says.

Activated debug message in triangle_triangle_intersection()

Problem may be in triangle_intersection(), intersect_edge_edge_1d() that checks for vertex-in-edge in 1d. nope (was not that).

Gotcha! The function uses an inexact Geom::triangle_axis() function that may choose not the best projection axis. And the orient_2d() != ZERO checks I have done were not there ! Tested: with exact triangle axis computation it works.