def helicalextrusion(wire, height, angle): face_a = Face(wire) face_b = face_a.copy() face_transform = App.Matrix() face_transform.rotateZ(angle) face_transform.move(App.Vector(0, 0, height)) face_b.transformShape(face_transform) spine = Wire(Line(fcvec([0., 0, 0]), fcvec([0, 0, height])).toShape()) auxspine = makeHelix(height * 2 * pi / abs(angle), height, 10., 0, bool(angle < 0)) faces = [face_a, face_b] pipeshell = BRepOffsetAPI.MakePipeShell(spine) pipeshell.setSpineSupport(spine) pipeshell.add(wire) pipeshell.setAuxiliarySpine(auxspine, True, False) assert (pipeshell.isReady()) pipeshell.build() faces.extend(pipeshell.shape().Faces) fullshell = Shell(faces) solid = Solid(fullshell) if solid.Volume < 0: solid.reverse() assert (solid.Volume >= 0) return (solid)
def helicalextrusion(wire, height, angle): face_a = Face(wire) face_b = face_a.copy() face_transform = App.Matrix() face_transform.rotateZ(angle) face_transform.move(App.Vector(0,0,height)) face_b . transformShape(face_transform) step = 2 + int(angle / pi * 4 ) angleinc = angle / (step - 1) zinc = height / (step-1) spine = makePolygon([(0, 0, i * zinc) for i in range(step)]) auxspine = makePolygon( [ (cos(i * angleinc), sin(i * angleinc), i * height/(step-1))for i in range(step) ]) faces=[face_a,face_b ] pipeshell = BRepOffsetAPI.MakePipeShell(spine) pipeshell.setSpineSupport(spine) pipeshell.add(wire) pipeshell.setAuxiliarySpine(auxspine,True,False) assert(pipeshell.isReady()) pipeshell.build() faces.extend(pipeshell.shape().Faces) fullshell = Shell(faces) solid = Solid(fullshell) if solid.Volume < 0: solid.reverse() assert(solid.Volume >= 0) return(solid)
def _fuse_nut_ramps_to_bracket(bracket: Part.Solid, thickness: float, set_screw_cutout_length: float, set_screw_cutout_width: float, ramp_height: float) -> Part.Solid: """Fuse nut ramps to bracket so nut doesn't spin when tightening screw. :: |\ | \ |__\ :param bracket: Bracket :param thickness: Thickness :param set_screw_cutout_length: Length of set screw cutout :param set_screw_cutout_width: Width of set screw cutout :param ramp_height: Height of ramp. """ ramp_length = set_screw_cutout_length / 2.0 ramp_angle = (180 - 120) / 2 # Hexagonal nuts have 120 degree angles # opposite = tan(theta) * adjacent (toa in soh-cah-toa rule) height = tan(radians(ramp_angle)) * ramp_length # Right Triangle bottom_left = Vector(0, 0, 0) top_left = Vector(0, 0, height) bottom_right = Vector(ramp_length, 0, 0) vectors = [bottom_left, top_left, bottom_right] face = make_face_from_vectors(vectors) rotation = 45 left_ramp = face.extrude(Vector(0, set_screw_cutout_width, 0)) right_ramp = left_ramp.copy() left_ramp.rotate(Vector(0, 0, 0), Vector(0, 0, -1), rotation) right_ramp.rotate(Vector(0, 0, 0), Vector(0, 0, -1), 180 + rotation) cutout_length_offset = set_screw_cutout_length * cos(radians(rotation)) left_ramp.translate( Vector(thickness * 2, (thickness * 2) + cutout_length_offset, ramp_height)) cutout_width_offset = set_screw_cutout_width * cos(radians(rotation)) right_ramp.translate( Vector((thickness * 2) + cutout_length_offset + cutout_width_offset, (thickness * 2) + cutout_width_offset, ramp_height)) bracket = bracket.fuse(left_ramp) return bracket.fuse(right_ramp)
def execute1(self, fp): fp.gear.z = fp.teeth fp.gear.pressure_angle = fp.pressure_angle.Value * pi / 180. fp.gear.pitch_angle = fp.pitch_angle.Value * pi / 180 fp.gear.backlash = fp.backlash fp.gear._update() pts = fp.gear.points(num=fp.numpoints) tooth = self.create_tooth() teeth = [tooth] rot = App.Matrix() rot.rotateZ(2 * pi / fp.teeth) top_cap = [i.Edges[0] for i in tooth.Faces] bottom_cap = [i.Edges[3] for i in tooth.Faces] for i in range(fp.teeth - 1): new_tooth = teeth[-1].transformGeometry(rot) edge1 = new_tooth.Faces[0].Edges[2] edge2 = teeth[-1].Faces[-1].Edges[1] face1 = make_face(edge1, edge2) teeth.append(face1) teeth.append(new_tooth) top_cap.append(face1.Edges[3]) bottom_cap.append(face1.Edges[1]) top_cap += [i.Edges[0] for i in new_tooth.Faces] bottom_cap += [i.Edges[3] for i in new_tooth.Faces] edge1 = teeth[0].Faces[0].Edges[2] edge2 = teeth[-1].Faces[-1].Edges[1] face1 = make_face(edge1, edge2) teeth.append(face1) top_cap.append(face1.Edges[3]) bottom_cap.append(face1.Edges[1]) top_cap = Face(Wire(top_cap)) bottom_cap = Face(Wire(bottom_cap)) fcs = Compound(teeth).Faces top_cap.reverse() fp.Shape = Solid(Shell(fcs + [top_cap, bottom_cap]))
def helicalextrusion(wire, height, angle): face_a = Face(wire) face_b = face_a.copy() face_transform = App.Matrix() face_transform.rotateZ(angle) face_transform.move(App.Vector(0, 0, height)) face_b . transformShape(face_transform) spine = Wire(Line(fcvec([0., 0, 0]), fcvec([0, 0, height])).toShape()) auxspine = makeHelix(height * 2 * pi / angle, height, 1.) faces = [face_a, face_b] pipeshell = BRepOffsetAPI.MakePipeShell(spine) pipeshell.setSpineSupport(spine) pipeshell.add(wire) pipeshell.setAuxiliarySpine(auxspine, True, False) assert(pipeshell.isReady()) pipeshell.build() faces.extend(pipeshell.shape().Faces) fullshell = Shell(faces) solid = Solid(fullshell) if solid.Volume < 0: solid.reverse() assert(solid.Volume >= 0) return(solid)