Concave Polygon Tessellation / Triangulation

I'm trying to think but I cannot come up with an efficient way to determine if some edge lies within a concave polygon...

edit: Wikipedia to the rescue! http://en.wikipedia.org/wiki/Point_in_polygon

edit - take 2: Also, I noticed I was running the Delaunay triangulation in Debug mode earlier, it can actually achieve a 1000-point triangulation in well under 10 milliseconds on my machine!

Also, I believe that finding a greedy triangulation is even faster (linear time) and may make things a bit easier to code. Don't know why I hadn't thought of that earlier.

Also, regarding the issue with regular Delaunay triangulations not handling concave polygons (and requiring some sort of constrained Delaunay triangulation), a simple way to fix it is to loop through all edges, and check for containment within the concave polygon using a raycasting method, and remove all triangles that are not contained within the original concave polygon. Also, if there are edges of the concave polygon which are not a subset of the edges in the Delaunay Triangulation, we can just simply superimpose it into the mesh and slice up some of the existing triangles. This will only yield convex quadrilaterals and more triangles, both of which are fine for use by box2d.

I do have a question though. As far as these limitations go:

Quote:
- Edges can't be too close to parallel
- Area must be greater than a minimum value
- Each edge must be more than b2_toiSlop away from the centroid


If I give box2d a polygon shape that does not satisfy these conditions, will it take care of the problem without crashing or doing anything bad (i.e. undefined behavior) ? Ideally it should just omit the offending polygon altogether.
Interestingly, VC++ completely ignores the b2Asserts and my code, which creates a delaunay triangulation and does not do anything about really tiny triangles, works pretty well in the simulation as far as i can tell. Only when I compiled with codeblocks did the program quit on me when the assertions failed.
Nope, Box2d normally would just crash if passed a bad polygon - if you have assertions disabled, it will continue running as if everything's okay, but the physics might work wrong since the geometry won't satisfy the assumptions the engine makes. It's probably best to figure out how to turn assertions on, because they are really there to alert you to any problems with what you've passed to the engine, and if any are being skipped, you're right, the behavior is pretty much undefined. Ideally the fix-up and discarding of shapes would happen as part of the triangulation utility, so that you never hit an assertion in the engine (the current convex decomposition utility pretty much achieves that, but it's slow and doesn't produce very high quality triangulations).

By the way, Paul Bourke e-mailed me back and said that as long as there's a proper attribution, he always grants permission to use code, so that's good news. I'm going to see if I can work his code into the start of a full utility for decomposition.
I looked at Paul Bourke's code. It looks like it takes a soup of vertices and make a triangle mesh. Not quite what I was hoping for. I really need the CSG aspect of triangulation.

The GLU tesselator does make slivers. Right now I have it configured to only produce triangles, (as opposed to tri strips or tri fans). With this configuration it will output zero area triangles. Those are relatively easy to catch and ignore. The triangles that are too small for the toi slop are a bit tougher. In the mean time, is there a way I can tell if a triangle will fail before I actually try to create it? Could we change the toi stuff to use percentages instead of a flat value? Another option would be to shrink it right up to the centroid in the case it would normally assert. That way it is not 0.04 less but it is as close as possible. Would there be any negative side affects for either of these solutions?

-nick

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