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.