def AddCone(BasePoint, Radius, height, direction=gp_Dir(1, 0, 0)): """Generates a cone shape originating at BasePoint with base Radius and height (points in the direction of input 'direction) Parameters ---------- BasePoint : OCC.gp.gp_Pnt or array length 3 The centre base point Radius : scalar Cone base radius height : scalar Cone height direction : OCC.gp.gp_Dir (default: positive x direction) the direction of the cones axis i.e. normal to the base: defaults to x axis Returns ------- shape : TopoDS_Shape The generated Cone """ try: BasePoint = gp_Pnt(*BasePoint) except: pass ax2 = gp_Ax2(BasePoint, direction) cone = BRepPrimAPI_MakeCone(ax2, Radius, 0, height) return cone.Shape()
def do_cone(): axe = gp_Ax2() axe.SetLocation(gp_Pnt((random_vec() * scope).XYZ())) axe.SetDirection(gp_Dir(random_vec())) cone = BRepPrimAPI_MakeCone( axe, 0, #random.uniform(0,), # r1 random.uniform(10, 30), # r2 random.uniform(30, 1500), # h ) return cone.Shape()
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 makeCone(cls, radius1, radius2, height, pnt=Vector(0, 0, 0), dir=Vector(0, 0, 1), angleDegrees=360): """ Make a cone with given radii and height By default pnt=Vector(0,0,0), dir=Vector(0,0,1) and angle=360' """ return cls( BRepPrimAPI_MakeCone(gp_Ax2(pnt.toPnt(), dir.toDir()), radius1, radius2, height, angleDegrees * DEG2RAD).Shape())
def create_shape(self): d = self.declaration args = [d.axis, d.radius, d.radius2, d.height] if d.angle: args.append(d.angle) self.shape = BRepPrimAPI_MakeCone(*args)
# 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 BconeSm = BRepPrimAPI_MakeCone(p,BIRSm,BCR,BIHSm).Shape() bushing = BRepAlgoAPI_Fuse(bushing, BconeSm).Shape() BSIN = BOR*math.sin(math.radians(BA)) ; BCOS = BOR*math.cos(math.radians(BA)) # create and set up transformation for leftBush ltrsf = gp_Trsf() ltrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(1,0,0)),math.radians(BA)) leftBush = BRepBuilderAPI_Transform(bushing, ltrsf).Shape() ltrsf.SetTranslation(gp_Vec(BIn+BOR,float(TW)/2-BS-BCOS,TH-BSIN)) leftBush = BRepBuilderAPI_Transform(leftBush, ltrsf).Shape() leftBush = BRepAlgoAPI_Cut(leftBush,tank).Shape() # cut common part of bushing and tank
from OCC.Display.SimpleGui import init_display from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCone from OCC.Graphic3d import Graphic3d_NOM_PLASTIC, Graphic3d_NOM_ALUMINIUM from OCC.V3d import V3d_SpotLight, V3d_COMPLETE, V3d_XnegYnegZpos from OCC.Quantity import Quantity_NOC_WHITE, Quantity_NOC_CORAL2, Quantity_NOC_BROWN from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut from OCC.gp import gp_Vec from core_geometry_utils import translate_shp # first create geometry from core_classic_occ_bottle import bottle table = translate_shp( BRepPrimAPI_MakeBox(100, 100, 10).Shape(), gp_Vec(-50, -50, -10)) glass_out = BRepPrimAPI_MakeCone(7, 9, 25).Shape() glass_in = translate_shp( BRepPrimAPI_MakeCone(7, 9, 25).Shape(), gp_Vec(0., 0., 0.2)) glass = BRepAlgoAPI_Cut(glass_out, glass_in).Shape() translated_glass = translate_shp(glass, gp_Vec(-30, -30, 0)) # then inits display display, start_display, add_menu, add_function_to_menu = init_display() # create one spotlight spot_light = V3d_SpotLight(display.Viewer_handle, -100, -100, 100, V3d_XnegYnegZpos, Quantity_NOC_WHITE) ## display the spotlight in rasterized mode spot_light.Display(display.View_handle, V3d_COMPLETE) display.View.SetLightOn()