wo80 / Triangle.NET

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

concave polygon? #37

Closed jardeltecchio closed 1 year ago

jardeltecchio commented 1 year ago

Hello. Sorry, it's a newbie question. Is there a way to triangulate a concave polygon? I tried to do so, but i gues i missed something... here is my code:

        var pol = new Polygon();
        pol.Points.Add(new Vertex(0, 0));
        pol.Points.Add(new Vertex(0.2f, 0));
        pol.Points.Add(new Vertex(0.2f, -0.2f));
        pol.Points.Add(new Vertex(-0.2f, -0.2f));
        pol.Points.Add(new Vertex(-0.2f, -0.15f));
        pol.Points.Add(new Vertex(0, -0.15f));
        pol.Points.Add(new Vertex(0, 0));

        var options = new ConstraintOptions() { ConformingDelaunay = true};
        var qual = new QualityOptions() { MaximumArea = 0.005};
        mesh = (Mesh)pol.Triangulate(options, qual);
         var smoother = new SimpleSmoother();
         smoother.Smooth(mesh);

thanks in advance

this is my atempt to triangulate the blue polygon concave polygon

adriaanpfeiffer commented 1 year ago

You could take a look at the polygon example https://github.com/wo80/Triangle.NET/wiki/Polygon

jardeltecchio commented 1 year ago

It worked. I should have created the contour or segments. Thank you.