1 Star 0 Fork 2

chenyp401/CAM

forked from zzthfut/CAM 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
IntersectStl_sweep.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
zzthfut 提交于 2023-07-31 22:51 . 5-8
from layer import Layer
from GeomAlgo import intersectTriangleZPlane
import numpy as np
class SweepPlane:
def __init__(self):
self.triangles = []
self.z = 0
class IntersectStl_sweep:
def __init__(self, stlModel, layerThk):
self.stlModel = stlModel
self.layerThk = layerThk
self.layers = []
self.intersect()
def intersect(self):
triangles = self.stlModel.triangles
triangles.sort(key=lambda t: t.zMinPnt(), reverse=False)
zs = self.genLayerHeights()
k = 0
sweep = SweepPlane()
for z in zs:
for i in range(len(sweep.triangles) - 1, -1, -1):
if z > sweep.triangles[i].zMaxPnt():
del sweep.triangles[i]
for i in range(k, len(triangles)):
tri = triangles[i]
if z >= tri.zMinPnt() and z <= tri.zMaxPnt():
sweep.triangles.append(tri)
elif tri.zMinPnt() > z:
k = i
break
layer = Layer(z)
for triangle in sweep.triangles:
seg = intersectTriangleZPlane(triangle, z)
if seg is not None:
layer.segments.append(seg)
self.layers.append(layer)
def genLayerHeights(self):
xMin, xMax, yMin, yMax, zMin, zMax = self.stlModel.getBounds()
z = zMin + self.layerThk
zs = [i for i in np.arange(z, zMax, step=self.layerThk, dtype="float")]
return zs
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chenyp401/cam.git
git@gitee.com:chenyp401/cam.git
chenyp401
cam
CAM
master

搜索帮助