def intersection(L1,L2):
#make sure all lines are on the same z plane
#assert (math.isclose(L1.p0.z, L1.p1.z, abs_tol=0.0001))
#assert (L2.p0.z == L2.p1.z)
#assert (L1.p0.z == L2.p0.z)
x1 = L1.p0.x
y1 = L1.p0.y
x2 = L1.p1.x
y2 = L1.p1.y
x3 = L2.p0.x
y3 = L2.p0.y
x4 = L2.p1.x
y4 = L2.p1.y
xnum = (x1*y2-y1*x2)*(x3-x4) - (x1-x2)*(x3*y4-y3*x4)
xden = (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4)
ynum = (x1*y2-y1*x2)*(y3-y4) - (y1-y2)*(x3*y4-y3*x4)
yden = (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4)
try:
intersect = Point(xnum/xden,ynum/yden,L1.p0.z)
if ((intersect.x >= min(x1,x2)-delta) and (intersect.x <= max(x1,x2)+delta) and
(intersect.y >= min(y1,y2)-delta) and (intersect.y <= max(y1,y2)+delta) and
(intersect.x >= min(x3,x4)-delta) and (intersect.x <= max(x3,x4)+delta) and
(intersect.y >= min(y3,y4)-delta) and (intersect.y <= max(y3,y4)+delta)):
return intersect
else:
return None
# return intersect
except:
return None
#given a list of lines that make a manifold perimeter on a slice,
#and a percentage of space that should be infill,
#returns a list of infill lines (grid pattern) for that slice
#assumes print bed area is a square
评论列表
文章目录