如果要剪切等距折线和一个封闭的矩形多边形之间的交点,则最外面的折线与矩形的边缘重合。
具有矩形多边形的折线相交(绿色:剪辑,黑色:主题,红色:求解)
当折线规则地与矩形相交时,解决方案按预期提供了两个相交点。但是,在折线与多边形的边缘重合的情况下,解决方案为空。有没有办法在边缘检索解决方案?
import numpy as np
import pyclipper
clip = np.asarray([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
pc = pyclipper.Pyclipper()
pc.AddPath(clip, pyclipper.PT_CLIP, True)
pathlist = []
for y in np.linspace(0, 10, 11):
path = ((-1, y), (11, y))
pathlist.append(path)
pc.AddPaths(pathlist, pyclipper.PT_SUBJECT, False)
solutions = pc.Execute2(pyclipper.CT_INTERSECTION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD)
for solution in solutions.Childs:
contour = np.asarray(solution.Contour)