1 Star 0 Fork 2

chenyp401/CAM

forked from zzthfut/CAM 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GenDpPath.py 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
zzthfut 提交于 2023-08-15 15:49 . 9-16
from GenHatch import genHatches
from GeomAlgo import rotatePolygons
import numpy as np
from Polyline import Polyline
from SpiltRegion import splitRegion
class GenDpPath:
def __init__(self, polygons, interval, angle):
self.polygons = polygons
self.interval = interval
self.angle = angle
self.splitPolys = []
def genScanYs(self, polygons):
yMin, yMax = float("inf"), float("-inf")
for poly in polygons:
for pt in poly.points:
yMin, yMax = min(pt.y, yMin), max(pt.y, yMax)
ys = [round(y, 7) for y in np.arange(yMin + self.interval, yMax, self.interval)]
# print(ys)
return ys
def linkLocalHatches(self, segs):
poly = Polyline()
for i, seg in enumerate(segs):
poly.addPoint(seg.A if (i % 2 == 0) else seg.B)
poly.addPoint(seg.B if (i % 2 == 0) else seg.A)
return poly
def generate(self):
rotPolys = rotatePolygons(self.polygons, -self.angle)
ys = self.genScanYs(rotPolys)
self.splitPolys = splitRegion(rotPolys)
paths = []
for poly in self.splitPolys:
segs = genHatches([poly], ys)
if len(segs) > 0:
path = self.linkLocalHatches(segs)
paths.append(path)
return rotatePolygons(paths, self.angle)
def genDpPath(polygons, interval, angle):
return GenDpPath(polygons, interval, angle).generate()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chenyp401/cam.git
git@gitee.com:chenyp401/cam.git
chenyp401
cam
CAM
master

搜索帮助