wo80 / Triangle.NET

C# / .NET version of Jonathan Shewchuk's Triangle mesh generator.
442 stars 81 forks source link

Concave Polygon #15

Closed Paulchen29 closed 2 years ago

Paulchen29 commented 2 years ago

Hello,

I have a concave polygon and when I triangulate it with your Libary I get back only the convex hull no matter what constraint options I am using.

        ConstraintOptions constraintOpt = new ConstraintOptions();
        constraintOpt.ConformingDelaunay = false;
        constraintOpt.Convex = false; 

Any suggestions on that or is a concave not possible?

wo80 commented 2 years ago

Concave is possible. How do you set up your polygon?

Paulchen29 commented 2 years ago

Hey,

Thanks I figured it out yesterday! I was missing to add the segments to the polygon - I was just using points

        TriangleNet.Geometry.Polygon polygon = new TriangleNet.Geometry.Polygon();
        polygon.Points.AddRange(polygonPoints);

        for (int ix = 0; ix < polygonPoints.Count; ix++)
        {
            if (ix == polygonPoints.Count - 1)
            {
                polygon.Add(new Segment(new Vertex(polygonPoints[ix].X, polygonPoints[ix].Y),
                    new Vertex(polygonPoints[0].X, polygonPoints[0].Y)));
            }

            else polygon.Add(new Segment(new Vertex(polygonPoints[ix].X, polygonPoints[ix].Y),
                new Vertex(polygonPoints[ix + 1].X, polygonPoints[ix + 1].Y)));
        }