算法拆分自相交Path2D中成若干不能自相交的路径?算法、路径、Path2D

2023-09-11 03:34:22 作者:恋你年华

我需要的形状,以摆脱自相交。形状从一个点的数组构成,以使形状的所有段都行。 (仅的线,没有曲线和弧线)

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,我试图从该点,构建一个区域,距离,然后用它的PathIterator我创建了几个Path2Ds,其中的创建Path2D中莫名其妙地的是previous路径的子路径,所以自intersetions都不见了。但是,这是不工作的一些路径 - 自交叉仍然存在。

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?

编辑:我还没有发现任何有用的任何地方,所以我写了我自己的算法。查看答案。

I haven't found anything useful anywhere, so I written my own algorithm. See the answers.

推荐答案

如果工作不适合你,你可以尝试使用 GLUtessellator 分解你的图形成一组三角形,或(使用的 GL_LINE_LOOP 选项)刚刚边界边。

If Area is not working for you, you could try using a GLUtessellator to decompose your Shape into a set of triangles, or (using the GL_LINE_LOOP option) just the boundary edges.