6

I need to calculate triangles of a polygon. Polygon can contain holes. And Req an efficient way. So I think I need Constrained Delaunay Triangulation.

I must do that in c#, only need calculation not drawing or something.

poly2tri seems good but idk its not working for me :S

Anyway I need help. How can I calculate that triangles? (If your best offer is poly2tri, i can explain my problem on it)

user1708062
  • 75
  • 1
  • 4
  • What is the problem you're receiving with poly2tri? – Reed Copsey Oct 08 '12 at 16:27
  • When i adapt it into my codes i am getting a null argument problem but i am expecting same result. look on js because its more clear (all in one file) sweep.Triangulate our start point in CreateAdvancingFront() its assign front variable. front variable have two nodes. head, tail. as you see head havent prev value. Lets continue sweep.SweepPoints calling sweep.PointEvent. At start you will see "var node = tcx.LocateNode(point);" and SweepContext will call front.LocateNode and as you see search_node is head. and head have biggest X value. so "if (x < node.value) {" will occur but – user1708062 Oct 08 '12 at 17:16
  • head dont have prev so null will return. so we will get error. – user1708062 Oct 08 '12 at 17:17
  • Can you give some details how you fixed poly2tri, and possibly contribute it to the googlecode project? ("I changed some code lines seems working for now") Thanks! – Erwin Coumans Nov 08 '12 at 21:04

2 Answers2

3

Delaunay was not designed for this, use Ear Clipping instead.

abenci
  • 8,422
  • 19
  • 69
  • 134
  • Delaunay not designed for that. But Constrained Delaunay designed for that. Btw Ear Clipping seems a little slow and on some polygons its getting no result. – user1708062 Oct 09 '12 at 09:35
  • you can also use the Delauney Triangulation using QuickHull algorithm by projecting the 2D vertices onto a 3D paraboloid. Once you have the triangulation, drop faces whose center points lying outside of the polygon trail or inside your hole polygon trail. Which might be faster than ear clipping. – kneo Aug 20 '13 at 11:54
2

I suppose my simple solution on github:gist (but it's rather old and probably not optimal).

Ivan Kochurkin
  • 4,413
  • 8
  • 45
  • 80
  • Thanks i will check it if cant repair poly2tri. Btw i think i found something on algorithm (poly2tri). I changed some code lines seems working for now. I will continue my tests. Poly2tri algorithm have an mistake on InitTriangulation() on js, c, c++, c# and java version and maybe other ones too. I will continue tests for my repair. – user1708062 Oct 09 '12 at 09:47