Christoph Breuning
Christoph Breuning

Reputation: 33

Pyclipper/Clipper: Intersection of Polylines with Polygon Edge

If I want to clip the intersections between evenly spaced Polylines and a closed rectangle Polygon, the outermost Polylines coincide with the edges of the Rectangle.

Polylines Intersection with Rectangle Polygon(Green: Clip, Black: Subject, Red: Solution)

image

When the Polylines intersect the rectangle regularly, the solution provides, as supposed, the two intersecting points. However, in the case where the Polyline coincides with the edge of the Polygon, the solution is empty. Is there a way to retrieve the solution at the edges?

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)

Upvotes: 1

Views: 981

Answers (0)

Related Questions