2
\$\begingroup\$

I wish to triangulate a polygon I only have the outline of (p0, p1, p2 ... pn) like described in this question: How do you triangulate an arbitrary polygon? and this webpage: http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/algorithm2.html

I do not wish to learn the subject and have a deep understanding of it at the moment. I only want to see an effective algorithm that can be used out of the box. The one described in the site seems to be of somewhat high complexity O(n) for finding one ear. I heard this could be done in O(n log n) time. Is there any well known easy to use algorithm that I can translate port to use in my engine that runs with somewhat reasonable complexity?

The reason I need to triangulate is that I wish to feel out a 2d-outline and render it 3d. Much like we fill out a 2d-outline in paint. I could use sprites. This would not serve cause I am planning to play with the resulting model on the z-axis, giving it different heights in the different areas.

I would love to try the books that were mentioned, although I suspect that is not the answer most readers are hoping for when they read this Q & A format. Mostly I like to see a code snippet I can cut and paste with some modifications and start running.

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

Not sure if this is the answer you seek, since you mention 3D. But I used Poly2Tri (alternate link) once to convert parametric curved shapes to triangles and it worked fine. I'm saying this because you need an easy implementation, and using this library I did it in an afternoon.

\$\endgroup\$
2
\$\begingroup\$

I have actually implemented it myself with a simple scanline algorithm. It doesnt grant the best results, but its good enough for me. From what I remember:

  1. You just have to sort your vertices along the X.

  2. Create column spans with the ordered vertices (thus, making it monotone polygons).

  3. And finally, find the diagonals lines connecting the vertices along the spans.

Is it clear?

EDIT: Please dont mind the mess: http://code.google.com/p/bzk3/source/browse/#svn%2Ftrunk%2Fsource%2Fcommon%2Fsrc%2Fbr%2Fodb%2Flibsvg (look for it at svn/trunk/source/common/src/br/odb/libsvg/)

In fact, I used to provide a standalone runnable jar just for that. More details at: https://sites.google.com/site/montysprojects/current-projects/svgtriangulator

\$\endgroup\$
2
  • \$\begingroup\$ Yes you can and should :P \$\endgroup\$ Commented Oct 15, 2012 at 23:36
  • \$\begingroup\$ Edit the answer and put the links in there, it will be easier to spot them :D \$\endgroup\$ Commented Oct 16, 2012 at 4:52
2
\$\begingroup\$

Velcro Physics (formerly Farseerer physics) has six different triangulators. You can check them here.

They're under the folder: /src/VelcroPhysics/Tools/Triangulation/

\$\endgroup\$
1
  • \$\begingroup\$ I will look there and update you when I get more work done. \$\endgroup\$
    – AturSams
    Commented Oct 14, 2012 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .