Mark C
Mark C

Reputation: 43

Why is Triangle.Net not triangulating these polygons as expected?

I've been having issues with triangulating certain polygons with holes using Triangle.Net.

The issue seems to be certain circumstances where I define a hole using a contour and setting hole to 'true' (after first adding the outer contour, hole set to false). Polygon.Add(contour, true);

Triangle.Net then finds a point inside that hole through Point.FindInteriorPoint and for reasons I don't know sometimes it finds a point that is on the very edge of that hole and the result is the only thing that gets triangulated is the hole, the rest of the polygon is ignored.

So for example. Two polygons with identical outer contours :

(3.5, 3.5), (-2.5, 3.5), (-2.5 -0.5), (-4.5, -0.5), (-4.5, -2.5), (3.5, -2.5) Image1

But one has a hole defined as this contour:

(2.5, 2.5), (2.5, 0.5), (0.5, 2.5)

and hole set to true. The interior point for this hole is found to be (1.5, 2.5) which is right on the border. The result is the outer polygon is not triangulated but the hole is. Result

The other has a hole is defined as this contour:

(0.5, 2.5), (2.5, 2.5), (2.5, 0.5)

and hole set to true. The interior point for this hole is found to be (2, 2) which is nicely in the middle. The result is the outer polygon is correctly triangulated with the hole properly cut out. Result

They both seem to have the same contour direction so I don't know why one works ok but the other doesn't. If I provide the first polygon with a point inside the polygon as (2, 2) instead of just setting hole to 'true' then the polygon is all triangulated correctly. So I was fairly certain the issue seemed to be down to this finding its own point within the hole contour.

But to make matters even more confusing if I used a simpler outer polygon such as this:

(3.5, 3.5), (-2.5, 3.5), (-2.5, -2.5), (3.5, -2.5) Image2

Then I can define a hole exactly like in the first version and it all works fine even though the interior point is found to be (1.5, 2.5). So now I'm thinking the point on the edge is not a problem.

I'm a bit lost now. I don't really know what I'm doing wrong or where to look. Any suggestions would be appreciated. Thanks.

Upvotes: 4

Views: 1254

Answers (1)

Alex
Alex

Reputation: 1132

There are two different things going on here and, together, this makes the behavior confusing.

The first issue is the behavior of FindInteriorPoint. This method has some robustness problems and can find points that are on the contour boundary. I suspect you aren't using this fork of Triangle.NET that contains some robustness improvements that should yield good results especially on these simple cases.

Now, if you do specify a hole using a point that is on the boundary of the hole, what do we expect will happen? The answer is the results are random/unpredictable. Triangle locates the triangle in the final mesh containing the point identified as a hole and delete all the triangles it is connected to without crossing any constrained segments. Which side (using exact arithmetic) depends on the exact coordinates of the endpoints of the subsegment in the mesh which for a refined mesh will depend on rounding that occurs computing the extra vertices inserted. Your case doesn't have any refinement so the location really is exactly on the the segment. Triangle walks from a starting point towards the hole location until it finds a triangle containing the hole point: the arbitrary location of the starting point determines which side it will reach first and end up choosing. So if you have a different surrounding domain, you get a different (arbitrary) starting point and you can get a different result.

Upvotes: 3

Related Questions