import pyclipper
from numpy import arange
根据:http ://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/Clipper/Properties/PreserveCollinear.htm 有一个 Clipper 类的属性,但我不知道如果它是为 PyclipperOffset() 实现的
生成给定数量的轮廓偏移量的函数
def offset_paths(polypaths, offset, n_o_offsets):
paths_w_offsets = []
scaled_paths = pyclipper.scale_to_clipper(polypaths, scale=gV.PYCLIPPER_SCALE)
scaled_offset = offset * gV.PYCLIPPER_SCALE
while(len(scaled_paths)):
>needed if there is more then one path in list
path = scaled_paths.pop()
paths_w_offsets.append(path)
for off in arange(scaled_offset, n_o_offsets*scaled_offset, scaled_offset):
pco = pyclipper.PyclipperOffset()
>I want to preserve collinear points of the input Path
pco.AddPath(path, pyclipper.JT_MITER, pyclipper.ET_CLOSEDPOLYGON)
new_offset = pco.Execute(off)
if len(new_offset):
paths_w_offsets.append(new_offset.pop())
else:
print('No Offset generated')
return pyclipper.scale_from_clipper(paths_w_offsets, scale=gV.PYCLIPPER_SCALE)
subj = [[[31.50139808654785, -35.0], [30.625, -35.0], [30.185029983520508, -35.0], [26.25, -35.0], [22.901138305664062, -35.0], [21.875, -35.0], [20.736642837524414, -35.0], [17.5, -35.0], [13.373607635498047, -35.0], [16.25702476501465, -33.757022857666016], [17.5, -33.12771987915039], [19.10905647277832, -32.23405456542969], [21.586854934692383, -30.625], [21.76314353942871, -30.51314353942871], [21.875, -30.42853355407715], [24.223499298095703, -28.598499298095703], [26.25, -26.735370635986328], [26.502002716064453, -26.502002716064453], [26.735370635986328, -26.25], [28.598499298095703, -24.223499298095703], [30.42853355407715, -21.875], [30.51314353942871, -21.76314353942871], [30.625, -21.586854934692383], [32.23405456542969, -19.10905647277832], [33.12771987915039, -17.5], [33.757022857666016, -16.25702476501465], [35.0, -13.373607635498047], [35.0, -17.5], [35.0, -20.736642837524414], [35.0, -21.875], [35.0, -22.901138305664062], [35.0, -26.25], [35.0, -30.185029983520508], [35.0, -30.625], [35.0, -31.50139808654785], [35.0, -35.0]]]
offset_paths(subj, -0.4, 3)
偏移路径中的共线点已被删除,但仍应包含在内