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 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 create_shape(self): d = self.declaration args = [coerce_axis(d.axis), d.radius, d.height] if d.angle: args.append(d.angle) cylinder = BRepPrimAPI_MakeCylinder(*args) self.shape = cylinder.Shape()
class CylinderByAxis(object): """ Create a cylinder. :param float radius: The radius. :param float height: The height. :param axis2: Not yet implemented. Solid will be constructed in xy-plane. :raise NotImplementedError: If an axis is provided. """ def __init__(self, radius, height, axis2=None): if axis2 is None: self._builder = BRepPrimAPI_MakeCylinder(radius, height) else: raise NotImplementedError('Providing Axis2 not yet implemented.') @property def face(self): """ :return: The lateral face of the cylinder :rtype: afem.topology.entities.Face """ return Face(self._builder.Face()) @property def shell(self): """ :return: The cylinder as a shell. :rtype: afem.topology.entities.Shell """ return Shell(self._builder.Shell()) @property def solid(self): """ :return: The cylinder as a solid. :rtype: afem.topology.entities.Solid """ return Solid(self._builder.Solid())
class CylinderByAxis(object): """ Create a cylinder. :param float radius: The radius. :param float height: The height. :param axis2: The axis. """ def __init__(self, radius, height, axis2=None): if axis2 is None: self._builder = BRepPrimAPI_MakeCylinder(radius, height) else: self._builder = BRepPrimAPI_MakeCylinder(axis2, radius, height) @property def face(self): """ :return: The lateral face of the cylinder :rtype: afem.topology.entities.Face """ return Face(self._builder.Face()) @property def shell(self): """ :return: The cylinder as a shell. :rtype: afem.topology.entities.Shell """ return Shell(self._builder.Shell()) @property def solid(self): """ :return: The cylinder as a solid. :rtype: afem.topology.entities.Solid """ return Solid(self._builder.Solid())
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 center_hole(base): cylinder = BRepPrimAPI_MakeCylinder(center_radius, thickness).Shape() cut = BRepAlgoAPI_Cut(base, cylinder) return cut.Shape()
def variable_filleting(event=None): display.EraseAll() # Create Box Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape() # Fillet Rake = BRepFilletAPI_MakeFillet(Box) ex = TopologyExplorer(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 = TopologyExplorer(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 = TopologyExplorer(Box2).edges() next(exp) next(exp) next(exp) afillet.Add(TabPoint, next(exp)) afillet.Build() if afillet.IsDone(): LawEvolvedBox = afillet.Shape() display.DisplayShape(LawEvolvedBox) else: print("aFillet not done.") display.FitAll()
def setUpClass(cls): """ Set up with a BRepPrimAPI_MakeCylinder. """ cls._builder = BRepPrimAPI_MakeCylinder(5, 10)
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()
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 __init__(self, radius, height, axis2=None): if axis2 is None: self._builder = BRepPrimAPI_MakeCylinder(radius, height) else: raise NotImplementedError('Providing Axis2 not yet implemented.')
# Display current quality dc = ais_context.DeviationCoefficient() dc_hlr = ais_context.HLRDeviationCoefficient() da = ais_context.DeviationAngle() da_hlr = ais_context.HLRAngle() print("Default display quality settings:") print("Deviation Coefficient: %f" % dc) print("Deviation Coefficient Hidden Line Removal: %f" % dc_hlr) print("Deviation Angle: %f" % da) print("Deviation Angle Hidden Line Removal: %f" % da_hlr) # # Improve quality by a factor 10 # factor = 20 ais_context.SetDeviationCoefficient(dc / factor) ais_context.SetDeviationAngle(da / factor) ais_context.SetHLRDeviationCoefficient(dc_hlr / factor) ais_context.SetHLRAngle(da_hlr / factor) print("Quality display improved by a factor {0}".format(factor)) # # Displays a cylinder # s = BRepPrimAPI_MakeCylinder(50., 50.).Shape() display.DisplayShape(s) # # Display settings and display loop # display.View_Iso() display.FitAll() start_display()
""" bbox = Bnd_Box() bbox.SetGap(tol) if use_mesh: mesh = BRepMesh_IncrementalMesh() mesh.SetParallelDefault(True) mesh.SetShape(shape) mesh.Perform() if not mesh.IsDone(): raise AssertionError("Mesh not done.") brepbndlib_Add(shape, bbox, use_mesh) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() return xmin, ymin, zmin, xmax, ymax, zmax, xmax - xmin, ymax - ymin, zmax - zmin print("Box bounding box computation") box_shape = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() bb1 = get_boundingbox(box_shape) print(bb1) print("Cylinder bounding box computation") cyl_shape = BRepPrimAPI_MakeCylinder(10., 20.).Shape() bb2 = get_boundingbox(cyl_shape) print(bb2) print("Torus bounding box computation") torus_shape = BRepPrimAPI_MakeCylinder(15., 5.).Shape() bb3 = get_boundingbox(torus_shape) print(bb3)
def __init__(self, radius, height, axis2=None): if axis2 is None: self._builder = BRepPrimAPI_MakeCylinder(radius, height) else: self._builder = BRepPrimAPI_MakeCylinder(axis2, radius, height)