简体   繁体   English

从两个相交的路径中获得三个结果路径

[英]getting three resultant paths from two intersecting paths

I have two intersecting paths in a xy plane see image. 我在xy平面中有两条相交的路径,请参见图片。 在此处输入图片说明

A path is defined by a set of points in order so that every two consecutive points form an edge of path. 路径由一组点按顺序定义,以便每两个连续的点形成路径的边缘。 Paths are always closed. 路径总是封闭的。 Points are flagged to indicated that whether they from edges or curve. 点被标记以指示它们是来自边缘还是曲线。 I am trying to write a function to get three paths as following. 我正在尝试编写一个函数来获取以下三个路径。 在此处输入图片说明

I tried the following. 我尝试了以下方法。

create temp path Object path_C
go through every edge in path_A
    go through every edge in path_B
        if current edge of path_A intersects edge of path_B
        find the intersection
        store the intersection point in path_C
    inner loop ends here
outer loop ends here
go through every point in path_A
   if a point lies within the path_B 
   add it to the path_C
   and remove it from path_A 
end of loop
go through every point in path_B
   if a point lies within the path_A 
   add it to the path_C
   and remove it from path_B
end the loop  

before I could run it one of my friend pointed out that there is no guarantee that path_C has got the points in correct order. 在我运行它之前,我的一位朋友指出,不能保证path_C的顺序正确。 Now I can't figure out how can I fix this problem. 现在我不知道如何解决此问题。 If you can suggest some optimizations that will be even better. 如果您可以提出一些优化建议,那就更好了。

Side note : I am actually trying to implement the divide feature in adobe illustrator's pathfinder panel. 旁注 :我实际上是在Adobe illustrator的探路者面板中尝试实现除法功能。

The terminology you looking for is a "graph cycle", look at this stack overflow thread: finding all cycles in graph . 您要查找的术语是“图形循环”,请查看此堆栈溢出线程: 在graph中查找所有循环 Basically you want to construct a graph from the two paths. 基本上,您想从两条路径构造图。 This is done by joining two paths (bring all their edges and verts), and introducing new vertices on each point of intersection. 这是通过连接两条路径(使它们的所有边和顶点都变为顶点)并在每个相交点引入新顶点来完成的。 The point of intersection is where the graphs will merge. 相交点是图形合并的地方。 During implementation, consider all the edge cases, ie intersection can happen between an edge going through a vertex, colinear edges/verts, etc. Also note, that for certain shapes, like say U shape and a rectangle, can produce several cycles. 在实现过程中,请考虑所有边缘情况,即,穿过顶点的边缘,共线边缘/顶点等之间可能发生相交。还要注意,对于某些形状(例如U形和矩形),可能会产生多个循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM