Triangulation has extra points/triangles. Not being removed in cleanup?

90 views
Skip to first unread message

Dylan Meville

unread,
Jul 13, 2014, 1:35:08 AM7/13/14
to poly...@googlegroups.com
Hello, I'm having some strange results with my triangulation of a simple shape.
I'm using the C# port found here: https://github.com/MaulingMonkey/poly2tri-cs

I have my polygon defined by these points:
-25 -73
70 -32
42 81
-84 133
-146 -6
-87 -62

(testing at http://r3mi.github.io/poly2tri.js/ shows proper results)

However, when I test my project I have two extra points being added to my triangulation.  After doing some searching it seems this can happen when the triangulation fails before the cleanup is complete, and it doesn't remove the extra points it needs to triangulate the polygon properly.  What could cause the triangulation to fail, and what can I do to fix it and remove those points sticking out at the top left and right?

The js demo linked above gave proper results, so maybe I'm using the triangulator incorrectly?

 Poly2Tri.PolygonPoint[] pp = new Poly2Tri.PolygonPoint[6];
 pp[0] = new Poly2Tri.PolygonPoint(-25, -73);
 pp[1] = new Poly2Tri.PolygonPoint(70, -32);
 pp[2] = new Poly2Tri.PolygonPoint(42, 81);
 pp[3] = new Poly2Tri.PolygonPoint(-84, 133);
 pp[4] = new Poly2Tri.PolygonPoint(-146, -6);
 pp[5] = new Poly2Tri.PolygonPoint(-87, -62);
 
Poly2Tri.Polygon poly = new Poly2Tri.Polygon(pp);
Poly2Tri.TriangulationContext tcx = new Poly2Tri.DTSweepContext();
tcx.PrepareTriangulation(poly);
Poly2Tri.DTSweep.Triangulate((Poly2Tri.DTSweepContext)tcx);
Debug.Log("Mesh triangulated with: " + tcx.Triangles.Count + " triangles")




obi

unread,
Jul 13, 2014, 4:29:35 AM7/13/14
to poly...@googlegroups.com
The simplest way to use Poly2Tri is

P2T.triangulate(polygon);
polygon.getTriangles();

Then you don't have to use the triangulation context at all. The triangulation in the context is the raw triangulation this is cleaned up and stored in the polygon.
The only reason I see for using the triangulation context yourself is reusing it for multiple triangulations and save some object creations.

Dylan Meville

unread,
Jul 13, 2014, 5:06:45 AM7/13/14
to poly...@googlegroups.com
I thought I copied the contents of the P2T.Triangulate function properly, but maybe the problem came from grabbing the triangles from the context or something.  I was just stupidly overcomplicating things I guess.  Anyhow, using the P2T class it's working properly now.  Thanks a million!
Reply all
Reply to author
Forward
0 new messages