def split_face_with_scales( face: Part.Face, scales: list = [.75, .5], ) -> list: from BOPTools.GeneralFuseResult import GeneralFuseResult s1 = face.copy().scale(scales[0]) s2 = face.copy().scale(scales[1]) center_of_mass = face.CenterOfMass tr1 = center_of_mass.sub(s1.CenterOfMass) s1.Placement.Base = tr1 tr2 = center_of_mass.sub(s2.CenterOfMass) s2.Placement.Base = tr2 area1 = face.cut(s1) area2 = s1.cut(s2) e1, e2 = sorted(face.Edges, key=lambda x: x.Length, reverse=True)[0:2] v1 = e1.CenterOfMass v2 = e2.CenterOfMass poly = Part.makePolygon([v1, center_of_mass, v2]) faces = [] for area in (area1, area2): pieces, map_ = area.generalFuse([poly]) gr = GeneralFuseResult([area, poly], (pieces, map_)) gr.splitAggregates() comp = Part.Compound(gr.pieces) faces.extend(comp.Faces) faces.append(Part.Face(s2)) return faces
def execute(self,fp): b = fp.pin_circle_radius d = fp.roller_diameter e = fp.eccentricity n = fp.teeth_number p = b/n s = fp.segment_count ang = fp.pressure_angle_lim c = fp.pressure_angle_offset q = 2*math.pi/float(s) # Find the pressure angle limit circles minAngle = -1.0 maxAngle = -1.0 for i in range(0, 180): x = self.calc_pressure_angle(p, d, n, i * math.pi / 180.) if ( x < ang) and (minAngle < 0): minAngle = float(i) if (x < -ang) and (maxAngle < 0): maxAngle = float(i-1) minRadius = self.calc_pressure_limit(p, d, e, n, minAngle * math.pi / 180.) maxRadius = self.calc_pressure_limit(p, d, e, n, maxAngle * math.pi / 180.) # unused # Wire(Part.makeCircle(minRadius,App.Vector(-e, 0, 0))) # Wire(Part.makeCircle(maxRadius,App.Vector(-e, 0, 0))) App.Console.PrintMessage("Generating cam disk\r\n") #generate the cam profile - note: shifted in -x by eccentricicy amount i=0 x = self.calc_x(p, d, e, n, q*i / float(n)) y = self.calc_y(p, d, e, n, q*i / n) x, y = self.check_limit(x,y,maxRadius,minRadius,c) points = [App.Vector(x-e, y, 0)] for i in range(0,s): x = self.calc_x(p, d, e, n, q*(i+1) / n) y = self.calc_y(p, d, e, n, q*(i+1) / n) x, y = self.check_limit(x, y, maxRadius, minRadius, c) points.append([x-e, y, 0]) wi = make_bspline_wire([points]) wires = [] mat= App.Matrix() mat.move(App.Vector(e, 0., 0.)) mat.rotateZ(2 * np.pi / n) mat.move(App.Vector(-e, 0., 0.)) for _ in range(n): wi = wi.transformGeometry(mat) wires.append(wi) cam = Face(Wire(wires)) #add a circle in the center of the cam if fp.hole_radius.Value: centerCircle = Face(Wire(Part.makeCircle(fp.hole_radius.Value, App.Vector(-e, 0, 0)))) cam = cam.cut(centerCircle) to_be_fused = [] if fp.show_disk0==True: if fp.disk_height.Value==0: to_be_fused.append(cam) else: to_be_fused.append(cam.extrude(App.Vector(0, 0, fp.disk_height.Value))) #secondary cam disk if fp.show_disk1==True: App.Console.PrintMessage("Generating secondary cam disk\r\n") second_cam = cam.copy() mat= App.Matrix() mat.rotateZ(np.pi) mat.move(App.Vector(-e, 0, 0)) if n%2 == 0: mat.rotateZ(np.pi/n) mat.move(App.Vector(e, 0, 0)) second_cam = second_cam.transformGeometry(mat) if fp.disk_height.Value==0: to_be_fused.append(second_cam) else: to_be_fused.append(second_cam.extrude(App.Vector(0, 0, -fp.disk_height.Value))) #pins if fp.show_pins==True: App.Console.PrintMessage("Generating pins\r\n") pins = [] for i in range(0, n + 1): x = p * n * math.cos(2 * math.pi / (n + 1) * i) y = p * n * math.sin(2 * math.pi / (n + 1) * i) pins.append(Wire(Part.makeCircle(d / 2, App.Vector(x, y, 0)))) pins = Face(pins) z_offset = -fp.pin_height.Value / 2; if fp.center_pins==True: if fp.show_disk0==True and fp.show_disk1==False: z_offset += fp.disk_height.Value / 2; elif fp.show_disk0==False and fp.show_disk1==True: z_offset += -fp.disk_height.Value / 2; #extrude if z_offset!=0: pins.translate(App.Vector(0, 0, z_offset)) if fp.pin_height!=0: pins = pins.extrude(App.Vector(0, 0, fp.pin_height.Value)) to_be_fused.append(pins); if to_be_fused: fp.Shape = Part.makeCompound(to_be_fused)