def revolve(cls, outerWire, innerWires, angleDegrees, axisStart, axisEnd): """ Attempt to revolve the list of wires into a solid in the provided direction :param outerWire: the outermost wire :param innerWires: a list of inner wires :param angleDegrees: the angle to revolve through. :type angleDegrees: float, anything less than 360 degrees will leave the shape open :param axisStart: the start point of the axis of rotation :type axisStart: tuple, a two tuple :param axisEnd: the end point of the axis of rotation :type axisEnd: tuple, a two tuple :return: a Solid object The wires must not intersect * all wires must be closed * there cannot be any intersecting or self-intersecting wires * wires must be listed from outside in * more than one levels of nesting is not supported reliably * the wire(s) that you're revolving cannot be centered This method will attempt to sort the wires, but there is much work remaining to make this method reliable. """ face = Face.makeFromWires(outerWire, innerWires) v1 = Vector(axisStart) v2 = Vector(axisEnd) v2 = v2 - v1 revol_builder = BRepPrimAPI_MakeRevol(face.wrapped, gp_Ax1(v1.toPnt(), v2.toDir()), angleDegrees * DEG2RAD, True) return cls(revol_builder.Shape())
def makeRevolve(face): # Get X axis, which face will be revolved around xaxis = OCC.gp.gp_OX() # Revolve the face around the xaxis diffuser = BRepPrimAPI_MakeRevol(face.Face(), xaxis) if args.v >= 1: print('Geometry is created') return (diffuser)
def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) coneOrigin = self.sec_origin revolve_axis = gp_Ax1(getGpPt(coneOrigin), getGpDir(self.wDir)) aSweep = BRepPrimAPI_MakeRevol(aFace, revolve_axis, math.radians(self.coneAngle)).Shape() return aSweep
def update_shape(self, change): d = self.declaration c = d.shape if d.shape else self.get_shape() #: Build arguments args = [c.shape.Shape(), gp_Ax1(d.position, d.direction)] if d.angle: args.append(d.angle) args.append(d.copy) self.shape = BRepPrimAPI_MakeRevol(*args)
def revolved_cut(base): # Define 7 points face_points = TColgp_Array1OfPnt(1, 7) face_inner_radius = 0.6 pts = [ gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), ] for n, i in enumerate(pts): face_points.SetValue(n + 1, i) # Use these points to create edges and add these edges to a wire hexwire = BRepBuilderAPI_MakeWire() for i in range(1, 7): hexedge = BRepBuilderAPI_MakeEdge(face_points.Value(i), face_points.Value(i + 1)).Edge() hexwire.Add(hexedge) # Turn the wire into a 6 sided face hexface = BRepBuilderAPI_MakeFace(hexwire.Wire()).Face() # Revolve the face around an axis revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis).Shape() # Move the generated shape move = gp_Trsf() move.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, sin(0.5))) moved_shape = BRepBuilderAPI_Transform(revolved_shape, move, False).Shape() # Remove the revolved shape cut = BRepAlgoAPI_Cut(base, moved_shape).Shape() return cut
def revolved_shape(): """ demonstrate how to create a revolved shape from an edge adapted from algotopia.com's opencascade_basic tutorial: http://www.algotopia.com/contents/opencascade/opencascade_basic """ face_inner_radius = 0.6 # point to create an edge from edg_points = [ gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), ] # aggregate edges in wire hexwire = BRepBuilderAPI_MakeWire() for i in range(6): hexedge = BRepBuilderAPI_MakeEdge(edg_points[i], edg_points[i + 1]).Edge() hexwire.Add(hexedge) hexwire_wire = hexwire.Wire() # face from wire hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face() revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) # create revolved shape revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis, math.radians(90.)).Shape() # render wire & revolved shape display.DisplayShape([revolved_shape_, hexwire_wire]) display.FitAll() start_display()
def round_tooth(wedge): round_x = 2.6 round_z = 0.06 * pitch round_radius = pitch # Determine where the circle used for rounding has to start and stop p2d_1 = gp_Pnt2d(top_radius - round_x, 0) p2d_2 = gp_Pnt2d(top_radius, round_z) # Construct the rounding circle round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01) if (round_circle.NbSolutions() != 2): exit(-2) round_circle_2d_1 = round_circle.ThisSolution(1) round_circle_2d_2 = round_circle.ThisSolution(2) if (round_circle_2d_1.Position().Location().Coord()[1] >= 0): round_circle_2d = round_circle_2d_1 else: round_circle_2d = round_circle_2d_2 # Remove the arc used for rounding trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value() # Calculate extra points used to construct lines p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y()) p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y()) p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y()) p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1) p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1) # Convert the arc and four extra lines into 3D edges plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX())) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge() lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge() lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge() lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge() # Make a wire composed of the edges round_wire = BRepBuilderAPI_MakeWire(arc1) round_wire.Add(lin1) round_wire.Add(lin2) round_wire.Add(lin3) round_wire.Add(lin4) # Turn the wire into a face round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape() # Revolve the face around the Z axis over the tooth angle rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape() # Construct a mirrored copy of the first cutting shape mirror = gp_Trsf() mirror.SetMirror(gp_XOY()) mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape() # and translate it so that it ends up on the other side of the wedge translate = gp_Trsf() translate.SetTranslation(gp_Vec(0, 0, thickness)) rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape() # Cut the wedge using the first and second cutting shape cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape() cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape() return cut_2
PFcoil = [] for i in range(len(pf)): c = color[i + 1] PFloop = BRepBuilderAPI_MakePolygon() # create CStop coil = 'Coil{:d}'.format(i) r, z = pf[coil]['r'], pf[coil]['z'] dr, dz = pf[coil]['dr'], pf[coil]['dz'] for sr, sz in zip([-1, 1, 1, -1], [-1, -1, 1, 1]): PFloop.Add(gp_Pnt(sr / 2 * dr, 0, sz / 2 * dz)) PFloop.Close() PFloop = Construct.translate_topods_from_vector(PFloop.Wire(), Construct.gp_Vec(r, 0, z)) PFface = Construct.make_face(PFloop) ax = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) PFcoil.append(BRepPrimAPI_MakeRevol(PFface, ax).Shape()) PFcage = Construct.compound(PFcoil) x3d = Construct.compound([TFcage['wp'], TFcage['case'], PFcage, GScage]) my_renderer = x3dom_renderer.X3DomRenderer() my_renderer.DisplayShape(x3d) prop = GpropsFromShape(TF['case']) print('gprop', prop.volume().Mass()) prop = GProp_GProps() brepgprop_VolumeProperties(TF['case'], prop, 1e-6) print('case volume', prop.Mass()) prop = GProp_GProps() brepgprop_VolumeProperties(TF['wp'], prop, 1e-6)