EarClippingTriangulator produces "inside-out" triangulation result
See original GitHub issueIssue details
Using the test case below, it appears the the EarClippingTriangulator is returning a result that is “inside-out” where it tries to connect points using the area outside the polygon. This would be also be seen in situations where the CW/CCW winding is incorrectly detected however I don’t believe that to be the case here and if the input points are reversed then the problem is still present. The test case is a bunch of squares merged together into a larger polygon and therefore there are a lot of colinear points which I would speculate is the trigger for this issue.
Reproduction steps/code
private void test()
{
float[] points = new float[] {
41.92309f, -78.590225f,
41.92219f, -78.590225f,
41.92219f, -78.591415f,
41.9195f, -78.591415f,
41.9195f, -78.592606f,
41.9186f, -78.592606f,
41.9186f, -78.589035f,
41.920395f, -78.589035f,
41.920395f, -78.58785f,
41.9186f, -78.58785f,
41.9186f, -78.58547f,
41.9195f, -78.58547f,
41.9195f, -78.58666f,
41.92219f, -78.58666f,
41.92219f, -78.589035f,
41.92309f, -78.589035f,
41.92309f, -78.590225f
};
EarClippingTriangulator triangulator = new EarClippingTriangulator();
ShortArray shortArray = triangulator.computeTriangles(points);
// Produces a result of [0, 16, 15, 15, 14, 13, 13, 12, 11, 9, 8, 7, 9, 7, 6, 9, 6, 5, 10, 9, 5, 4, 3, 2, 2, 1, 0, 0, 15, 13, 0, 13, 11, 0, 11, 10, 0, 10, 5, 0, 5, 4, 4, 2, 0]
// POLYGON ((41.92309 -78.590225, 41.92219 -78.590225, 41.92219 -78.591415, 41.9195 -78.591415, 41.9195 -78.592606, 41.9186 -78.592606, 41.9186 -78.589035, 41.920395 -78.589035, 41.920395 -78.58785, 41.9186 -78.58785, 41.9186 -78.58547, 41.9195 -78.58547, 41.9195 -78.58666, 41.92219 -78.58666, 41.92219 -78.589035, 41.92309 -78.589035, 41.92309 -78.590225))
// MULTIPOLYGON (((41.92309 -78.590225, 41.92309 -78.590225, 41.92309 -78.589035, 41.92309 -78.590225)), ((41.92309 -78.589035, 41.92219 -78.589035, 41.92219 -78.58666, 41.92309 -78.589035)), ((41.92219 -78.58666, 41.9195 -78.58666, 41.9195 -78.58547, 41.92219 -78.58666)), ((41.9186 -78.58785, 41.920395 -78.58785, 41.920395 -78.589035, 41.9186 -78.58785)), ((41.9186 -78.58785, 41.920395 -78.589035, 41.9186 -78.589035, 41.9186 -78.58785)), ((41.9186 -78.58785, 41.9186 -78.589035, 41.9186 -78.592606, 41.9186 -78.58785)), ((41.9186 -78.58547, 41.9186 -78.58785, 41.9186 -78.592606, 41.9186 -78.58547)), ((41.9195 -78.592606, 41.9195 -78.591415, 41.92219 -78.591415, 41.9195 -78.592606)), ((41.92219 -78.591415, 41.92219 -78.590225, 41.92309 -78.590225, 41.92219 -78.591415)), ((41.92309 -78.590225, 41.92309 -78.589035, 41.92219 -78.58666, 41.92309 -78.590225)), ((41.92309 -78.590225, 41.92219 -78.58666, 41.9195 -78.58547, 41.92309 -78.590225)), ((41.92309 -78.590225, 41.9195 -78.58547, 41.9186 -78.58547, 41.92309 -78.590225)), ((41.92309 -78.590225, 41.9186 -78.58547, 41.9186 -78.592606, 41.92309 -78.590225)), ((41.92309 -78.590225, 41.9186 -78.592606, 41.9195 -78.592606, 41.92309 -78.590225)), ((41.9195 -78.592606, 41.92219 -78.591415, 41.92309 -78.590225, 41.9195 -78.592606)))
}
Version of LibGDX and/or relevant dependencies
Tested on 1.9.3 Test run on Android
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Triangulation by Ear Clipping - Geometric Tools
An outer polygon with two inner polygons. The figure makes it clear that none of the vertices of inner polygon I1 are visible...
Read more >Which triangulation algorithm creates these triangles
I think it is not delanuay or ear clipping but which polygon triangulation method create these triangles? Any help? picture of triangulation.
Read more >Delaunay triangulation algorithm in shapely producing erratic ...
It is not producing an 'erratic' result. it takes the vertices as inputs as stated in the manual:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Like #5631, working with such scales is not ideal. This works correctly:
Probably you could do a general use massaging, like:
areVerticesClockwise
is returning false. If we force it to return true, then the triangulation is correct.