I need to get rid of self-intersections in a shape. Shape is constructed from an array of points, so all segments of that shape are lines. (only lines, no curves and arcs)
Previously, I tried to create Path2D from that points, construct an Area from it, and then using its PathIterator I created several Path2Ds, which somehow were subpaths of previous path, and so self-intersetions were gone. But this isn't working for some paths - self-intersections still remain there.
So could you point me to some place where I can find good algorithm to do similar thing?
Edit: I haven't found anything useful anywhere, so I written my own algorithm. See the answers.
If
Area
is not working for you, you could try using a GLUtessellator to decompose yourShape
into a set of triangles, or (using theGL_LINE_LOOP
option) just the boundary edges.