Concave Polygon Tessellation / Triangulation

ewjordan, it cannot do that. There are some triangulators like the 'triangle' which allows you to specify minimum angle of the triangles, but AFAIK there is not triangulator which actually is going to change the input polygon. Delaney triangulation will give you the least slivers.

On the other hand you can request the GLU tesselator to return you just the outline of the polygon which allows you to fatten the input polygon using some naive algorithm (like the one I posted on that other thread) which might create self intersections or other nasty data and the extract the new outline and then triangulate that.

Monotone triangulators (including GLU tess) tend to create a lot of thin triangles. One way to improve the situation is to randomly flip edges between two triangles--which together create convex polygon--if the new edge is shorter than the original. That will not solve all cases but will improve the overall triangulation quality and especially improve merging triangles into convex polygons. I got on average 25% less polygons with my test data.

As an added bonus, the GLU tess handles holes too.
Quote:
ewjordan, it cannot do that. There are some triangulators like the 'triangle' which allows you to specify minimum angle of the triangles, but AFAIK there is not triangulator which actually is going to change the input polygon. Delaney triangulation will give you the least slivers.

That's about what I figured - I might try your edge flipping, though, that sounds like it could help.

Delaunay triangulation looks very nice overall, and I'm probably going to take a stab at implementing it (mostly because CSG becomes extremely easy with a constrained Delaunay algorithm working), but it's not ideal because while it does avoid slivers, the triangles it uses to do so can get fairly small, and in Box2d the size restriction tends to force polys to be omitted more often than the angle one. That said, once you start merging the Delaunay pieces into convex pieces you may get overall better results than from a graphics triangulator, I'm not sure yet.
It occurs to me that the fact that shapes can overlap is possibly the solution to the small triangles problem. When you have a problem like this, you extend the triangle into the rest of them on the side that is not exposed. I should imagine that can fix a large amount of cases.

The edge flipping sounds promising too.
Good call, that's probably worth trying. Just requires each edge to be marked as interior/exterior, which is easy to do. The polygon can then be puffed out along an interior edge (if possible - sometimes the "bad" edges are both exterior) to move the centroid far enough that there's some room. What I'm thinking also is that in case this doesn't work (if the interior edge would have to push outside the polygon or the too-close-to-centroid edges are both exterior), we just puff them out anyways, because that's an indication that the raw input won't allow a usable decomposition.

As far as the angle requirements (that neighboring sides are not too close to parallel), these are fixable by simply bisecting the angle, so using these two fix-ups, that should cover most cases.

The only problem would be that the inertia/mass calculations will not be right with overlaps present, but these calculations can be made valid pretty easily once the input edge is traced into a simple polygon. So we'd just need to provide a manual mass/inertia calculation function, and people would have to know not to use SetMassFromShapes with decomposed polys. This is a very minor thing anyways because most geometry should be single-covered.

I've got a new version of the C++ tool pretty much ready, that fixes a couple bugs with the last version (now I can't find any cases of valid randomized input that actually fail triangulation, though there are still occasionally gaps in output and the edge tracing is still slow) and updates it for 2.0, so I'll throw that up today or tomorrow and when I get back to my home this weekend I'll start reworking everything to be cleaner and implement these ideas.

BTW, as some of you may know I don't do a whole lot of C++ programming - I need to sort vertices for some of the stuff I'm going to rewrite, is there a preferred portable way to do this, or should I just write it myself?
ewjordan wrote:
So we'd just need to provide a manual mass/inertia calculation function, and people would have to know not to use SetMassFromShapes with decomposed polys.
You could add in quadrilaterals of negative mass for each triangle you extend, and then patch Box2D to ignore negative mass shapes for everything but SetMassFromShapes. But that's just getting messy.
ewjordan wrote:
BTW, as some of you may know I don't do a whole lot of C++ programming - I need to sort vertices for some of the stuff I'm going to rewrite, is there a preferred portable way to do this, or should I just write it myself?


std::sort is my preferred sorter since the comparison function is inlined.
Quote:
std::sort is my preferred sorter since the comparison function is inlined.

Thanks, I'll go with that, then - as an added bonus I see that std::sort uses introsort, which is exactly what I wanted, so that's perfect.
Not sure if any progress is being made, but I just did some very rudimentary testing of this code:

http://local.wasp.uwa.edu.au/~pbourke/p ... iangulate/

I took the C++ source, did some timings, and on my 2.8Ghz Core 2 machine it does a Delaunay Triangulation of a 1000 point cloud in roughly 28 ms, and 100 points in roughly 1.0 ms. I'd say anything below 10ms is easily doable in real-time, and this thing cranks out a 500 point delaunay triangulation almost always in 10ms. It appears to be O(n^(3/2)).

I think 100 points is far more than anything I'll need, so it looks like we got a winner here.

Now to turn this into the awesomest demo ever...

Oh, also I am not actually sure if this is a legit Delaunay triangulation, but the resulting mesh definitely looks like one. So thats good enough for me.
Indeed, that does look like Delaunay code - of course I should have checked Paul Bourke's pages when this first came up, it seems he always has the algorithm you need at any given moment, already coded up and optimized! It's not constrained Delaunay, which adds another step to the decomposition, but that's comparatively easy to code and (more importantly) debug.

This code would definitely make for a solid starting point for this stuff. I'm going to send an e-mail and see if he'd be willing to let us use it under zlib; I'll post an update here either way.
This might help:

http://www.geom.uiuc.edu/~samuelp/del_project.html

This stuff is a little beyond me, so I'll just fool around with the delaunay and try to make a convex decomp method out of it.

Original thread: https://box2d.org/forum/viewtopic.php?t=719