def clone_tooth(base_shape): clone = gp_Trsf() grouped_shape = base_shape # Find a divisor, between 1 and 8, for the number_of teeth multiplier = 1 max_multiplier = 1 for i in range(0, 8): if num_teeth % multiplier == 0: max_multiplier = i + 1 multiplier = max_multiplier for i in range(1, multiplier): clone.SetRotation(gp_OZ(), -i * tooth_angle) rotated_shape = BRepBuilderAPI_Transform(base_shape, clone, True).Shape() grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape() # Rotate the basic tooth and fuse together aggregated_shape = grouped_shape for i in range(1, int(num_teeth / multiplier)): clone.SetRotation(gp_OZ(), -i * multiplier * tooth_angle) rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone, True).Shape() aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, rotated_shape).Shape() cylinder = BRepPrimAPI_MakeCylinder(gp_XOY(), top_radius - roller_diameter, thickness) aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, cylinder.Shape()).Shape() return aggregated_shape
def boolean_cut(base): # Create a cylinder cylinder_radius = 0.25 cylinder_height = 2.0 cylinder_origin = gp_Ax2(gp_Pnt(0.0, 0.0, -cylinder_height / 2.0), gp_Dir(0.0, 0.0, 1.0)) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, cylinder_radius, cylinder_height) # Repeatedly move and subtract it from the input shape move = gp_Trsf() boolean_result = base clone_radius = 1.0 for clone in range(8): angle = clone * pi / 4.0 # Move the cylinder move.SetTranslation( gp_Vec(cos(angle) * clone_radius, sin(angle) * clone_radius, 0.0)) moved_cylinder = BRepBuilderAPI_Transform(cylinder.Shape(), move, True).Shape() # Subtract the moved cylinder from the drilled sphere boolean_result = BRepAlgoAPI_Cut(boolean_result, moved_cylinder).Shape() return boolean_result
def Shape(self): ball_vecs = [] for i in self.balls: ball_vecs.append(gp_Vec(i.getPnt().XYZ())) v_ball_to_ball = ball_vecs[1] - ball_vecs[0] ax = gp_Ax2(gp_Pnt(ball_vecs[0].XYZ()), gp_Dir(v_ball_to_ball.XYZ())) mcyl = BRepPrimAPI_MakeCylinder(ax, self.d_o / 2.0, v_ball_to_ball.Magnitude()) cyl = mcyl.Shape() mch = BRepFilletAPI_MakeChamfer(cyl) endFaces = [] for face in Topo(cyl).faces(): adaptor = BRepAdaptor_Surface(face) if adaptor.GetType() == GeomAbs_Plane: endFaces.append(face) for edge in Topo(face).edges(): mch.Add(self.chamfer_distance, edge, face) try: chamferedCyl = mch.Shape() except: chamferedCyl = cyl print("chamfer on ForceTransferCylinder failed!") mc = BRepAlgoAPI_Cut(chamferedCyl, self.balls[0].Shape()) mc = BRepAlgoAPI_Cut(mc.Shape(), self.balls[1].Shape()) return mc.Shape()
def _add_random_cylinder_fired(self, old, new): brep = BRepPrimAPI_MakeCylinder(random.random() * 50, random.random() * 50).Shape() trsf = gp_Trsf() trsf.SetTranslation( gp_Vec(random.random() * 100, random.random() * 100, random.random() * 100)) brep.Move(TopLoc_Location(trsf)) self.shapes.append(brep)
def min_cylinder(height_dimension, shape, bounding_box): axis = get_axis(height_dimension, bounding_box) lengths = pick_lengths(bounding_box) height_length = height_dimension + '_length' height = bounding_box[height_length] radius = max( [value for key, value in lengths.iteritems() if key != height_length]) / 2 cylinder = BRepPrimAPI_MakeCylinder(axis, radius, height) cut = BRepAlgoAPI_Cut(shape, cylinder.Shape()) return cylinder_dict(cylinder, cut, radius, height)
def testTopoDS_byref_arguments(self): ''' Test byref pass arguments to TopoDS ''' cyl1 = BRepPrimAPI_MakeCylinder(10., 10.).Shape() cyl2 = BRepPrimAPI_MakeCylinder(100., 50.).Shape() c = TopoDS_Compound() bb = TopoDS_Builder() bb.MakeCompound(c) for child in [cyl1, cyl2]: bb.Add(c, child)
def smallest_max_cylinder(shape, bounding_box): # cylinder with diagonal of smaller face of bounding box height, longest_dimension = get_longest_dimension(bounding_box) longest_length = longest_dimension + '_length' lengths = pick_lengths(bounding_box) face_sides = [ value for key, value in lengths.iteritems() if key != longest_length ] radius = math.sqrt(sum([i**2 for i in face_sides])) / 2 # diagonal / 2 axis = get_axis(longest_dimension, bounding_box) cylinder = BRepPrimAPI_MakeCylinder(axis, radius, height) cut = BRepAlgoAPI_Cut(shape, cylinder.Shape()) return cylinder_dict(cylinder, cut, radius, height)
def create(self,center_Pnt,merged_arg=0): self.new_Pnt=center_Pnt self.new_gp_Pnt=gp_Pnt(center_Pnt[0],center_Pnt[1],center_Pnt[2]) self.shape=BRepPrimAPI_MakeSphere(self.new_gp_Pnt,2.1).Shape() display.DisplayShape(self.shape, update=True, color='YELLOW') self.attach_gp_dir=[] self.attach_gp_Ax2=[] self.magnet=[] self.attach_dir = [] for i in range(len(self.attach_pos)): if self.attach_pos[i]!=0: # self.attach_gp_dir.append(i) # self.attach_gp_Ax2.append(i) # self.magnet.append(i) self.dir=merged_arg merge_rotate=[math.cos(i * self.divide_arg)*math.cos(merged_arg)- math.sin(i*self.divide_arg)*math.sin(merged_arg), math.sin(i * self.divide_arg)*math.cos(merged_arg)+ math.cos(i * self.divide_arg)*math.sin(merged_arg),0] self.attach_dir.append([merge_rotate[0],merge_rotate[1],merge_rotate[2]]) self.attach_gp_dir.append(gp_Dir(self.attach_dir[i][0],self.attach_dir[i][1],self.attach_dir[i][2])) self.attach_gp_Ax2.append(gp_Ax2(self.new_gp_Pnt,self.attach_gp_dir[i])) self.magnet.append(BRepPrimAPI_MakeCylinder(self.attach_gp_Ax2[i],0.25,2.4).Shape()) if self.attach_pos[i]==1: display.DisplayShape(self.magnet[i], update=True, color='RED') elif self.attach_pos[i]==-1: display.DisplayShape(self.magnet[i], update=True, color=22)#22 is blue else: self.attach_gp_dir.append(i) self.attach_gp_Ax2.append(i) self.attach_dir.append(i) self.magnet.append(i)
def createModel(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = -self.T * self.shaftDir # extrudeDir is a numpy array boltHead = makePrismFromFace(aFace, extrudeDir) cylOrigin = self.origin boltCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.shaftDir)), self.r, self.H).Shape() whole_Bolt = BRepAlgoAPI_Fuse(boltHead, boltCylinder).Shape() return whole_Bolt
def makeCylinder(cls, radius, height, pnt=Vector(0, 0, 0), dir=Vector(0, 0, 1), angleDegrees=360): """ makeCylinder(radius,height,[pnt,dir,angle]) -- Make a cylinder with a given radius and height By default pnt=Vector(0,0,0),dir=Vector(0,0,1) and angle=360' """ return cls( BRepPrimAPI_MakeCylinder(gp_Ax2(pnt.toPnt(), dir.toDir()), radius, height, angleDegrees * DEG2RAD).Shape())
def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) cylOrigin = self.sec_origin innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r1, self.H).Shape() result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape() return result_shape
def create_model(self): edges = make_edges_from_points(self.points) wire = make_wire_from_edges(edges) aFace = make_face_from_wire(wire) extrudeDir = self.T * self.wDir # extrudeDir is a numpy array prism = make_prism_from_face(aFace, extrudeDir) cylOrigin = self.sec_origin innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(get_gp_pt(cylOrigin), get_gp_dir(self.wDir)), self.r1, self.H).Shape() result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape() return result_shape
def create_model(self): edges = make_edges_from_points(self.points) wire = make_wire_from_edges(edges) aFace = make_face_from_wire(wire) extrudeDir = -self.T * self.shaft_dir # extrudeDir is a numpy array boltHead = make_prism_from_face(aFace, extrudeDir) cylOrigin = self.origin boltCylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(get_gp_pt(cylOrigin), get_gp_dir(self.shaft_dir)), self.r, self.H).Shape() whole_Bolt = BRepAlgoAPI_Fuse(boltHead, boltCylinder).Shape() return whole_Bolt
def _cut_finger_notch(front, dx, dz): finger_width = 2.0 finger_height = 1.0 front = _cut( front, _box(_pnt(dx / 2. - finger_width / 2., 0, dz - finger_height), finger_width, THICKNESS_0, finger_height)) cyl = BRepPrimAPI_MakeCylinder(finger_width / 2.0, THICKNESS_0).Shape() tr = gp.gp_Trsf() tr.SetRotation(gp.gp_Ax1(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(1, 0, 0)), math.pi / 2.0) tr2 = gp.gp_Trsf() tr2.SetTranslation(gp.gp_Vec(dx / 2., THICKNESS_0, dz - finger_height)) tr2.Multiply(tr) cyl = BRepBuilderAPI_Transform(cyl, tr2, True).Shape() front = _cut(front, cyl) return front
def mounting_holes(base): result = base for i in range(0, mounting_hole_count): center = gp_Pnt( cos(i * M_PI / 3) * mounting_radius, sin(i * M_PI / 3) * mounting_radius, 0.0) center_axis = gp_Ax2(center, gp_DZ()) cylinder = BRepPrimAPI_MakeCylinder(center_axis, hole_radius, thickness).Shape() result = BRepAlgoAPI_Cut(result, cylinder).Shape() cone = BRepPrimAPI_MakeCone(center_axis, hole_radius + thickness / 2., hole_radius, thickness / 2.) result = BRepAlgoAPI_Cut(result, cone.Shape()).Shape() return result
def _cut_separator_notch(side, dy, separator_offset, is_left): x = THICKNESS_0 - SEPARATOR_NOTCH_DEPTH if is_left else 0 saw_dy = math.sqrt(2 * SAW_RADIUS * SEPARATOR_NOTCH_DEPTH - math.pow(SEPARATOR_NOTCH_DEPTH, 2)) side = _cut(side, _box(_pnt(x, 0, separator_offset - THICKNESS_0), SEPARATOR_NOTCH_DEPTH, dy - BACK_INSET - THICKNESS_1 - saw_dy, THICKNESS_0)) saw_blade = BRepPrimAPI_MakeCylinder(SAW_RADIUS, THICKNESS_0).Shape() if is_left: saw_blade_x = THICKNESS_0 + SAW_RADIUS - SEPARATOR_NOTCH_DEPTH else: saw_blade_x = -SAW_RADIUS + SEPARATOR_NOTCH_DEPTH _move(saw_blade, saw_blade_x, dy - THICKNESS_0 - saw_dy, separator_offset - THICKNESS_0) side = _cut(side, saw_blade) return side
def createModel(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(prism) anEdgeExplorer = TopExp_Explorer(prism, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17. , aEdge) anEdgeExplorer.Next() prism = mkFillet.Shape() cylOrigin = self.secOrigin innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r1, self.H).Shape() result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape() return result_shape
def createModel(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = -self.T * self.shaftDir # extrudeDir is a numpy array boltHead = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(boltHead) anEdgeExplorer = TopExp_Explorer(boltHead, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17. , aEdge) anEdgeExplorer.Next() boltHead = mkFillet.Shape() cylOrigin = self.origin boltCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.shaftDir)), self.r, self.H).Shape() whole_Bolt = BRepAlgoAPI_Fuse(boltHead,boltCylinder).Shape() mkFillet = BRepFilletAPI_MakeFillet(whole_Bolt) return whole_Bolt
r2 = 1 # gap gap = .47 # hgap hgap = 0. # size of a brick bx = 5 by = 2 bz = 2 sphere1 = BRepPrimAPI_MakeSphere(r1).Shape() sphere2 = BRepPrimAPI_MakeSphere(r2).Shape() cylinder1 = BRepPrimAPI_MakeCylinder(.3, l1).Shape() cylinder2 = BRepPrimAPI_MakeCylinder(.3, l2).Shape() ground = BRepPrimAPI_MakeBox(gp_Pnt(-50, -50, 0), 100., 100., .5).Shape() brick = BRepPrimAPI_MakeBox(gp_Pnt(-bx / 2., -by / 2., -bz / 2.), bx, by, bz).Shape() # Creation of the hdf5 file for input/output with MechanicsHdf5Runner() as io: # io.add_occ_shape('Mass1', sphere1) io.add_occ_shape('Mass2', sphere2) io.add_occ_shape('Arm1', cylinder1) io.add_occ_shape('Arm2', cylinder2) io.add_occ_shape('Ground', ground) io.add_occ_shape('Brick', sphere1)
def variable_filleting(event=None): display.EraseAll() # Create Box Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape() # Fillet Rake = BRepFilletAPI_MakeFillet(Box) ex = Topo(Box).edges() next(ex) next(ex) next(ex) Rake.Add(8, 50, next(ex)) Rake.Build() if Rake.IsDone(): evolvedBox = Rake.Shape() display.DisplayShape(evolvedBox) else: print("Rake not done.") # Create Cylinder Cylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape() fillet = BRepFilletAPI_MakeFillet(Cylinder) TabPoint2 = TColgp_Array1OfPnt2d(0, 20) for i in range(0, 20): Point2d = gp_Pnt2d(i * 2 * pi / 19, 60 * cos(i * pi / 19 - pi / 2) + 10) TabPoint2.SetValue(i, Point2d) exp2 = Topo(Cylinder).edges() fillet.Add(TabPoint2, next(exp2)) fillet.Build() if fillet.IsDone(): LawEvolvedCylinder = fillet.Shape() display.DisplayShape(LawEvolvedCylinder) else: print("fillet not done.") ## TODO : fillet not done P = gp_Pnt(350, 0, 0) Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape() afillet = BRepFilletAPI_MakeFillet(Box2) TabPoint = TColgp_Array1OfPnt2d(1, 6) P1 = gp_Pnt2d(0., 8.) P2 = gp_Pnt2d(0.2, 16.) P3 = gp_Pnt2d(0.4, 25.) P4 = gp_Pnt2d(0.6, 55.) P5 = gp_Pnt2d(0.8, 28.) P6 = gp_Pnt2d(1., 20.) TabPoint.SetValue(1, P1) TabPoint.SetValue(2, P2) TabPoint.SetValue(3, P3) TabPoint.SetValue(4, P4) TabPoint.SetValue(5, P5) TabPoint.SetValue(6, P6) exp = Topo(Box2).edges() next(exp) next(exp) next(exp) afillet.Add(TabPoint, next(exp)) afillet.Build() if afillet.IsDone(): LawEvolvedBox = afillet.Shape() else: print("aFillet not done.") display.DisplayShape(LawEvolvedBox) display.FitAll()
def do_cyl(): axe = gp_Ax2() axe.SetLocation(gp_Pnt((random_vec() * scope).XYZ())) axe.SetDirection(gp_Dir(random_vec())) cyl = BRepPrimAPI_MakeCylinder(axe, random.uniform(8, 36), 5000.) return cyl.Shape()
def create_shape(self): d = self.declaration args = [d.axis, d.radius, d.height] if d.angle: args.append(d.angle) self.shape = BRepPrimAPI_MakeCylinder(*args)
from OCC.BRep import BRep_Builder from OCC.TopoDS import TopoDS_Compound builder.Add(comp, sphere_r1_shape) radius = 1.0 point = gp_Pnt(4., 0., 0.) sphere_r1_t = BRepPrimAPI_MakeSphere(point, radius) sphere_r1_t_shape = sphere_r1_t.Shape() builder.Add(comp, sphere_r1_t_shape) # this cylinder is defined for the visualisation of the axis edge # it may be used for contact also. axis = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, -.05, 0), gp_Dir(0, 1, 0)), .001, .1).Shape() density = 7750.0 steel = Material(density=density) water = Material(density=1000) steel_cm = Material(density=density * 1e-6) tol = 1e-10 def test_sphere_1m(): with MechanicsHdf5Runner() as io: io.add_occ_shape('sphere_r1_shp', sphere_r1_shape) ###############
from OCC.BRepPrimAPI import BRepPrimAPI_MakeCylinder from OCC.BRepBuilderAPI import BRepBuilderAPI_GTransform from OCC.gp import gp_GTrsf, gp_Trsf, gp_Mat from OCC.Precision import Precision_Angular, Precision_Confusion from OCC import StlAPI shape = BRepPrimAPI_MakeCylinder(20, 40).Shape() # This options creates unwanted polygons ''' xform = gp_Trsf() xform.SetValues( 1.5, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, Precision_Angular(), Precision_Confusion() ); brep = BRepBuilderAPI_GTransform(shape, gp_GTrsf(xform), False) ''' # This options works as desired xform = gp_GTrsf() xform.SetVectorialPart(gp_Mat( 1.5, 0, 0, 0, 1, 0, 0, 0,
BCL = BH-BHL-BTL # core length BOR = 3 # outer radius BCR = 2.7 # core radius BIRSm = 3.5 # radius of small CI BIHSm = 0.5 # height of small CI BIRLg = 4 # radius of large CI BIHLg = float(BIRLg*BIHSm)/BIRSm # height of large CI (proportional) BIS = 0.5 # seperation between CIs BIHPack = BIHSm+BIHLg+2*BIS # pack length BIno = int(BCL//BIHPack) # number of packs fitted into core length BIrem = BCL % BIHPack # remainder length # building bushing shape Btap = BRepPrimAPI_MakeCylinder(BOR,BTL).Shape() p = gp_Ax2(gp_Pnt(0,0,BTL),gp_DZ()) # placement Bcore = BRepPrimAPI_MakeCylinder(p,BCR,BCL).Shape() p = gp_Ax2(gp_Pnt(0,0,BTL+BCL),gp_DZ()) # placement Bhead = BRepPrimAPI_MakeCylinder(p,BOR,BHL).Shape() bushing = BRepAlgoAPI_Fuse(Btap, Bcore).Shape() bushing = BRepAlgoAPI_Fuse(bushing, Bhead).Shape() # adding composite insulators to shape BIinit = BTL+float(BIrem)/2+BIS # initial height for first cone for i in range(0,BIno): Bconez = BIinit + i*BIHPack # local height for cones p = gp_Ax2(gp_Pnt(0,0,Bconez),gp_DZ()) # placement BconeLg = BRepPrimAPI_MakeCone(p,BIRLg,BCR,BIHLg).Shape() bushing = BRepAlgoAPI_Fuse(bushing, BconeLg).Shape() p = gp_Ax2(gp_Pnt(0,0,Bconez+BIHLg+BIS),gp_DZ()) # placement
anEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(thickness / 12.0, anEdge) anEdgeExplorer.Next() myBody = mkFillet # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height) neckAxis = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis) myNeckRadius = thickness / 4.0 myNeckHeight = height / 10.0 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myBody = BRepAlgoAPI_Fuse(myBody.Shape(), mkCylinder.Shape()) # Our goal is to find the highest Z face and remove it faceToRemove = None zMax = -1 # We have to work our way through all the faces to find # the highest Z face so we can remove it for the shell aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE) while aFaceExplorer.More(): aFace = topods.Face(aFaceExplorer.Current()) if face_is_plane(aFace): aPlane = geom_plane_from_face(aFace)
def create_single_assembly(self, tire_radius, wheel_radius, struct_length, scale=1): tire_radius = tire_radius wheel_radius = wheel_radius struct_length = struct_length straight_arm_height = tire_radius * 1.5 ring_radius = wheel_radius torus_radius = tire_radius torus = BRepPrimAPI_MakeTorus(torus_radius, ring_radius).Shape() straight_arm_radius = ring_radius / 2 straight_arm = BRepPrimAPI_MakeCylinder(straight_arm_radius, straight_arm_height).Shape() angled_arm_radius = straight_arm_radius angled_arm_height = tire_radius * 1.5 angle = -40 angled_arm = BRepPrimAPI_MakeCylinder(angled_arm_radius, angled_arm_height).Shape() traf = CTiglTransformation() traf.add_rotation_x(angle) angled_arm = traf.transform(angled_arm) traf = CTiglTransformation() traf.add_translation(0, angled_arm_height * sin(angle), 0) angled_arm = traf.transform(angled_arm) traf = CTiglTransformation() traf.add_translation(0, angled_arm_height * cos(angle), angled_arm_height * sin(angle)) straight_arm = traf.transform(straight_arm) arm_assembly = BRepAlgoAPI_Fuse(straight_arm, angled_arm).Shape() traf = CTiglTransformation() traf.add_rotation_x(90) torus = traf.transform(torus) pin_radius = wheel_radius pin_height = tire_radius pin = BRepPrimAPI_MakeCylinder(pin_radius, pin_height).Shape() traf = CTiglTransformation() traf.add_translation(0, 0, -straight_arm_height + torus_radius / 2) torus = traf.transform(torus) traf = CTiglTransformation() traf.add_rotation_x(90) pin = traf.transform(pin) traf = CTiglTransformation() traf.add_translation(0, 0, -straight_arm_height + pin_radius) pin = traf.transform(pin) traf = CTiglTransformation() traf.add_mirroring_at_xzplane() mirrored_arm_assembly = traf.transform(arm_assembly) traf = CTiglTransformation() traf.add_mirroring_at_xzplane() mirrored_pin = traf.transform(pin) arm_assembly = BRepAlgoAPI_Fuse(mirrored_arm_assembly, arm_assembly).Shape() struct_radius = wheel_radius - 0.5 * wheel_radius struct_height = struct_length struct = BRepPrimAPI_MakeCylinder(struct_radius, struct_height).Shape() traf = CTiglTransformation() traf.add_translation(0, 0, torus_radius) struct = traf.transform(struct) pin = BRepAlgoAPI_Fuse(mirrored_pin, pin).Shape() part_1 = BRepAlgoAPI_Fuse(arm_assembly, pin).Shape() part_2 = BRepAlgoAPI_Fuse(part_1, struct).Shape() part_3 = BRepAlgoAPI_Fuse(part_2, pin).Shape() return BRepAlgoAPI_Fuse(part_3, torus).Shape()
def simple_cylinder(event=None): from OCC.BRepPrimAPI import BRepPrimAPI_MakeCylinder s = BRepPrimAPI_MakeCylinder(60, 200).Shape() display.DisplayShape(s)
def center_hole(base): cylinder = BRepPrimAPI_MakeCylinder(center_radius, thickness).Shape() cut = BRepAlgoAPI_Cut(base, cylinder) return cut.Shape()
def TextureRepeat(self, toRepeatU, toRepeatV): self._toRepeatU = toRepeatU self._toRepeatV = toRepeatV def TextureOrigin(self, originU, originV): self._originU = originU self._originV = originV def GetProperties(self): return (self._filename, self._toScaleU, self._toScaleV, self._toRepeatU, self._toRepeatV, self._originU, self._originV) # # First create texture and a material # texture_filename = '../assets/images/ground.bmp' t = Texture(texture_filename) m = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER) # # Displays a cylinder with a material and a texture # s = BRepPrimAPI_MakeCylinder(60, 200) display.DisplayShape(s.Shape(), material=m, texture=t) # # Display settings # display.View_Iso() display.FitAll() start_display()