def addOvercut(a): nonlocal pos, centerv, radius, extendedv, sign, negative_overcuts, positive_overcuts # move the overcut shape center position 1 radius in direction v pos -= centerv * radius if abs(a) < math.pi / 2: shape = utils.Circle(radius, 64) shape = shapely.affinity.translate(shape, pos.x, pos.y) else: # elongate overcut circle to make sure tool bit can fit into slot p1 = pos + (extendedv * radius) l = shapely.geometry.LineString((pos, p1)) shape = l.buffer(radius, resolution=64) if sign > 0: negative_overcuts.append(shape) else: positive_overcuts.append(shape)
def execute(self, context): #utils.silhoueteOffset(context,-self.diameter) o1 = bpy.context.active_object shapes = utils.curveToShapely(o1) negative_overcuts = [] positive_overcuts = [] diameter = self.diameter * 1.001 for s in shapes: s = shapely.geometry.polygon.orient(s, 1) if s.boundary.type == 'LineString': loops = [s.boundary] #s=shapely.geometry.asMultiLineString(s) else: loops = s.boundary for ci, c in enumerate(loops): if ci > 0 or self.do_outer: #c=s.boundary for i, co in enumerate(c.coords): i1 = i - 1 if i1 == -1: i1 = -2 i2 = i + 1 if i2 == len(c.coords): i2 = 0 v1 = Vector(co) - Vector(c.coords[i1]) v1 = v1.xy #Vector((v1.x,v1.y,0)) v2 = Vector(c.coords[i2]) - Vector(co) v2 = v2.xy #v2 = Vector((v2.x,v2.y,0)) if not v1.length == 0 and not v2.length == 0: a = v1.angle_signed(v2) sign = 1 #if ci==0: # sign=-1 #else: # sign=1 if self.invert: # and ci>0: sign *= -1 if (sign < 0 and a < -self.threshold) or ( sign > 0 and a > self.threshold): p = Vector((co[0], co[1])) v1.normalize() v2.normalize() v = v1 - v2 v.normalize() p = p - v * diameter / 2 if abs(a) < math.pi / 2: shape = utils.Circle(diameter / 2, 64) shape = shapely.affinity.translate( shape, p.x, p.y) else: l = math.tan(a / 2) * diameter / 2 p1 = p - sign * v * l l = shapely.geometry.LineString((p, p1)) shape = l.buffer(diameter / 2, resolution=64) if sign > 0: negative_overcuts.append(shape) else: positive_overcuts.append(shape) print(a) #for c in s.boundary: negative_overcuts = shapely.ops.unary_union(negative_overcuts) positive_overcuts = shapely.ops.unary_union(positive_overcuts) #shapes.extend(overcuts) fs = shapely.ops.unary_union(shapes) fs = fs.union(positive_overcuts) fs = fs.difference(negative_overcuts) o = utils.shapelyToCurve(o1.name + '_overcuts', fs, o1.location.z) #o=utils.shapelyToCurve('overcuts',overcuts,0) return {'FINISHED'}