如果我想剪辑均匀间隔的折线和闭合矩形多边形之间的交点,最外面的折线与矩形的边缘重合。
多段线与矩形多边形相交(绿色:剪辑,黑色:主题,红色:解决方案)
当折线有规律地与矩形相交时,解决方案提供了假设的两个相交点。但是,如果折线与多边形的边缘重合,则解为空。有没有办法在边缘检索解决方案?
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)