2015-10-14 88 views
0

我在xy平面中有两条相交路径,请参阅图像。 enter image description here从两条相交路径中获取三条合成路径

路径由一系列点定义,以便每两个连续的点形成路径边。路径总是关闭。点标记以指示它们是否来自边缘或曲线。 我想写一个函数来获得如下三个路径。 enter image description here

我尝试了以下方法。

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 

在我运行它之前,我的一位朋友指出,并不能保证path_C按照正确的顺序得到了点。现在我无法弄清楚如何解决这个问题。 如果你可以建议一些更好的优化。

附注:我其实想实现在Adobe Illustrator中的探路者面板鸿沟功能。

+0

你知道结果可能超过3个地区 –

+0

哦!我怎么错过了。顺便说一句,谢谢你指出。 –

回答

0

你要找的术语是一个“图形循环”,看看这个堆栈溢出线程:finding all cycles in graph。基本上你想从两条路径构建一个图形。这是通过加入两条路径(带入所有的边和垂直)并在每个交点上引入新的顶点来完成的。交点是图形合并的地方。在实现过程中,考虑所有的边缘情况,即交叉点可以发生在穿过顶点的边缘,共线边缘/垂直等之间。还要注意,对于某些形状,比如说U形和矩形,可以产生几个周期。

相关问题