Problem with Triangulation using NetTopologySuite

124 Views Asked by At

I don't have much experience with NetTopologySuite, so any help will be appreciated!

I have a polygon:

POLYGON((10 12,10 8,9 8,9 13,10 13,10 15,11 15,11 13,12 13,12 15,14 15,14 13,15 13,15 8,13 8,13 12,12 12,12 9,11 9,11 12,10 12))

enter image description here

and I need to triangulate it, so what I'm doing is basically:

var reader = new WKTReader();
var polygon = (Polygon)reader.Read("POLYGON((10 12,10 8,9 8,9 13,10 13,10 15,11 15,11 13,12 13,12 15,14 15,14 13,15 13,15 8,13 8,13 12,12 12,12 9,11 9,11 12,10 12))");
    
var builder = new DelaunayTriangulationBuilder();
    
builder.SetSites(polygon);
var triangles = builder.GetTriangles(GeometryFactory.Default);

and if I plot triangles, it seems to be not triangulating it properly... I'm not sure if this result is expected or not, but what I need is that the triangulation returns me a list of triangles that will fit exactly inside the input polygon, but instead it's returning:

MULTIPOLYGON (((9 13, 9 8, 10 12, 9 13)), ((9 13, 10 12, 10 13, 9 13)), ((9 13, 10 13, 10 15, 9 13)), ((10 15, 10 13, 11 13, 10 15)), ((10 15, 11 13, 11 15, 10 15)), ((11 15, 11 13, 12 13, 11 15)), ((11 15, 12 13, 12 15, 11 15)), ((12 15, 12 13, 14 13, 12 15)), ((12 15, 14 13, 14 15, 12 15)), ((14 15, 14 13, 15 13, 14 15)), ((15 13, 14 13, 13 12, 15 13)), ((15 13, 13 12, 15 8, 15 13)), ((13 8, 15 8, 13 12, 13 8)), ((13 8, 13 12, 12 9, 13 8)), ((13 8, 12 9, 10 8, 13 8)), ((10 8, 12 9, 11 9, 10 8)), ((10 8, 11 9, 9 8, 10 8)), ((9 8, 11 9, 10 12, 9 8)), ((10 12, 11 9, 11 12, 10 12)), ((10 12, 11 12, 10 13, 10 12)), ((10 13, 11 12, 11 13, 10 13)), ((11 13, 11 12, 12 12, 11 13)), ((11 13, 12 12, 12 13, 11 13)), ((12 13, 12 12, 13 12, 12 13)), ((12 13, 13 12, 14 13, 12 13)), ((13 12, 12 12, 12 9, 13 12)), ((12 9, 12 12, 11 12, 12 9)), ((12 9, 11 12, 11 9, 12 9)))

enter image description here

So as the second images shows in the marked area, I need the triangles to match that area exactly, like all the others, but it returns me a multipolygon that is missing that part...

What am I doing wrong?

1

There are 1 best solutions below

0
FObermaier On

NTS' DelaunayTriangulation only takes the Coordinates of the Geometrys to build the triangulation. You need to use ConformingDelauneyTriangulation to respect boundary lines. Additionally you will need to check for all result triangles if they are contained by the original Geometry. A check for the controid will do.