7

I recently asked this question about how to cut down a concave polygon to convex ones, and I was suggested to do Triangulation or Polygon Partitioning.

The library I'm using (SFML\Box2D) only takes convex shapes.

This is what I want to know:

  1. Is Polygon Partitioning, or Triangulation of Polygons faster?

  2. How does Polygon Partitioning work/ How do you do it?


Don't forget Triangulation doesn't require convex shapes to be made either...

Cœur
  • 37,241
  • 25
  • 195
  • 267
Griffin
  • 2,399
  • 7
  • 48
  • 83

2 Answers2

4

Polygon partitioning splits your polygon into convex polygons.
Triangulation splits it into triangles. As far as I understand, partitioning into triangles requires that you first perform polygon partitioning, since partitioning convex polygon into triangles is relatively trivial.
Splitting polyon into convex polygons is the hard part. I have written a program that does both for a class and if you want I can dig it up.

Here's my code: https://github.com/meshko/triangulator/tree/master/som

I haven't touched in 10 years so beware of.

MK.
  • 33,605
  • 18
  • 74
  • 111
  • that would be GREAT! please do =) – Griffin Jul 15 '11 at 02:47
  • 1
    @MK: You can triangulate concave polygons directly, although it may be easier to triangulate convex ones... – Darren Engwirda Jul 15 '11 at 02:49
  • @Griffin I've updated answer with the link to the code. Good luck. – MK. Jul 15 '11 at 03:19
  • @MK: So in the readme.txt you say "Algorithm consists of two phases: first polygon is split into monotone polygons, then each monotone polygon is triangulated in linear time." I know how to do this, so does any of the source actually partion a polygon to convex shapes? – Griffin Jul 15 '11 at 03:29
  • um... I guess it doesn't. Sorry, confused convex and montone :( – MK. Jul 15 '11 at 03:34
  • all good! just make sure to upvote the question cuz i've been looking for answer for a while... – Griffin Jul 15 '11 at 04:09
4

Not a full answer to your question, but if you have a general polygon (concave, convex, whatever) and you are looking to triangulate it (for subsequent openGL style rendering perhaps) you could look into "constrained Delaunay triangulation" packages. One such example is the Triangle package, which is reputed to be fast and robust.

As I understand it, the algorithms used in Triangle exhibit O(nlogn) runtime complexity.

Darren Engwirda
  • 6,915
  • 4
  • 26
  • 42
  • i just wanted to know if you knew if it was faster,i'll put it back if you don't. – Griffin Jul 15 '11 at 03:23
  • 1
    Triangle has a runtime complexity of `O(nlogn)`, which is generally pretty fast asymptotically. If you can find an `O(n)` algorithm then obviously that may be faster, but I'm not aware of any algorithms in this class. Maybe check this out http://code.google.com/p/polypartition/ and compare the reported complexities. To *actually* find the *fastest* method you would need to benchmark, and get some real timing results... – Darren Engwirda Jul 15 '11 at 03:27
  • Another consideration is triangulation quality, since many valid triangulations can be generated for a given polygon. A Delaunay based algorithm (such as Triangle) is in some sense optimal, because it constructs the triangulation which maximises the smallest angle. – Darren Engwirda Jul 15 '11 at 03:43
  • That link you gave to the PolyPartition Library looks really interesting/ Useful! There's no guide to it is there? I'm trying to figure it out from the source code right now. – Griffin Jul 15 '11 at 05:50