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:
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.
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
- 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.