def gen_ellipsoid(axs=gp_Ax3(), rxyz=[10, 20, 30]): sphere = BRepPrimAPI_MakeSphere(gp_Ax2(), 1).Solid() loc = set_loc(gp_Ax3(), axs) mat = gp_Mat(rxyz[0], 0, 0, 0, rxyz[1], 0, 0, 0, rxyz[2]) gtrf = gp_GTrsf(mat, gp_XYZ(0, 0, 0)) ellips = BRepBuilderAPI_GTransform(sphere, gtrf).Shape() ellips.Location(loc) return ellips
def gen_ellipsoid_geom(axs=gp_Ax3(), rxyz=[10, 20, 30]): sphere = gp_Sphere(axs, 1) api = Geom_SphericalSurface(sphere) api.Continuity() api.Transform() print(api.Area()) loc = set_loc(gp_Ax3(), axs) mat = gp_Mat(rxyz[0], 0, 0, 0, rxyz[1], 0, 0, 0, rxyz[2]) gtrf = gp_GTrsf(mat, gp_XYZ(0, 0, 0)) ellips = BRepBuilderAPI_GTransform(sphere, gtrf).Shape() ellips.Location(loc) return ellips
def uniform_scale(occtopology, tx, ty, tz, ref_pypt): """ This function uniformly scales an OCCtopology based on the reference point and tx,ty,tz factors. Parameters ---------- occtopology : OCCtopology The OCCtopology to be scaled. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex tx : float The scale factor in the X-axis. ty : float The scale factor in the Y-axis. tz : float The scale factor in the Z-axis. ref_pypt : tuple of floats The OCCtopology will scale in reference to this point. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) Returns ------- scaled topology : OCCtopology (OCCshape) The scaled OCCtopology. """ moved_shape = move(ref_pypt, (0, 0, 0), occtopology) xform = gp_GTrsf() xform.SetVectorialPart(gp_Mat( tx, 0, 0, 0, ty, 0, 0, 0, tz, )) brep = BRepBuilderAPI_GTransform(xform) brep.Perform(moved_shape, True) trsfshape = brep.Shape() move_back_shp = move((0, 0, 0), ref_pypt, trsfshape) return move_back_shp
def transform(self, trans): if isinstance(trans, Transformation): shp = BRepBuilderAPI_Transform( self._shp, trans._trsf, True).Shape() return Shape(shp) if isinstance(trans, GeneralTransformation): shp = BRepBuilderAPI_GTransform( self._shp, trans._gtrsf, True).Shape() return Shape(shp)
def scale_shape(shape, fx, fy, fz): """Scale a shape along the 3 directions @param fx : scale factor in the x direction @param fy : scale factor in the y direction @param fz : scale factor in the z direction @return : the scaled shape """ assert_shape_not_null(shape) scale_trsf = gp_GTrsf() rot = gp_Mat(fx, 0.0, 0.0, 0.0, fy, 0.0, 0.0, 0.0, fz) scale_trsf.SetVectorialPart(rot) shp = BRepBuilderAPI_GTransform(shape, scale_trsf).Shape() return shp
def __init__(self): super().__init__() self.axs = gp_Ax3() self.radi = [500, 200] self.rxyz = [1.5, 1.2, 1.5] mat = gp_Mat(self.rxyz[0], 0, 0, 0, self.rxyz[1], 0, 0, 0, self.rxyz[2]) gtrf = gp_GTrsf(mat, gp_XYZ(0, 0, 0)) #self.t = Geom_ToroidalSurface(self.axs, *self.radi) self.t = Geom_SphericalSurface(self.axs, 100.0) self.face = BRepBuilderAPI_MakeFace(self.t, 1e-6).Face() self.face = BRepBuilderAPI_GTransform(self.face, gtrf).Shape() self.surf = BRep_Tool.Surface(self.face) self.prop = GeomLProp_SLProps(self.surf, 0.0, 0.0, 1, 1.0) self.export_stp(self.face) print(self.t.UPeriod())
def brep_feat_extrusion_protrusion(event=None): # Extrusion S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = TopologyExplorer(S).faces() F = next(faces) surf1 = BRep_Tool_Surface(F) Pl1 = Geom_Plane.DownCast(surf1) D1 = Pl1.Pln().Axis().Direction().Reversed() MW = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(200., -100.), gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(100., -100.), gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(100., -200.), gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200., -200.), gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf1, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) display.EraseAll() MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True) MKP.PerformThruAll() res1 = MKP.Shape() display.DisplayShape(res1) # Protrusion next(faces) F2 = next(faces) surf2 = BRep_Tool_Surface(F2) Pl2 = Geom_Plane.DownCast(surf2) D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200., 100.), gp_Pnt2d(150., 200.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(150., 200.), gp_Pnt2d(100., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) MKF2 = BRepBuilderAPI_MakeFace() MKF2.Init(surf2, False, 1e-6) MKF2.Add(MW2.Wire()) MKF2.Build() FP = MKF2.Face() breplib_BuildCurves3d(FP) MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True) MKP2.PerformThruAll() display.EraseAll() trf = gp_Trsf() trf.SetTranslation(gp_Vec(0, 0, 300)) gtrf = gp_GTrsf() gtrf.SetTrsf(trf) tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True) fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape()) fused.Build() display.DisplayShape(fused.Shape()) display.FitAll()
def utilShapeZScale(shape, scaleK): transform = gp_GTrsf() transform.SetAffinity(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, 1, 0)), scaleK) shape = BRepBuilderAPI_GTransform(shape, transform).Shape() return shape
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_GTransform from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Common from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() orig = gp_Pnt(0., 0., 0.) sphere = BRepPrimAPI_MakeSphere(orig, 50.).Solid() # be careful that the following scale numbers are "not too big", # otherwise boolean operations can be buggy # see isue a1 = 17.1 a2 = 17.1 a3 = 3.5 gTrsf = gp_GTrsf(gp_Mat(a1, 0, 0, 0, a2, 0, 0, 0, a3), gp_XYZ(0., 112.2, 0.)) ellipsoid = BRepBuilderAPI_GTransform(sphere, gTrsf).Shape() # then perform a boolean intersection with a box box = BRepPrimAPI_MakeBox(gp_Pnt(-1000, -1000, -1000), gp_Pnt(1000, 112.2, 1000)).Shape() common = BRepAlgoAPI_Common(box, ellipsoid).Shape() if common.IsNull(): raise AssertionError("common result is Null.") display.DisplayShape(box, color="BLACK", transparency=0.8) display.DisplayShape(ellipsoid, color="BLACK", transparency=0.8) display.DisplayShape(common, color="BLACK", transparency=0.8, update=True) start_display()
def gen_ellipsoid(axs=gp_Ax3(), rxyz=[10, 20, 30]): mat = gp_Mat(rxyz[0], 0, 0, 0, rxyz[1], 0, 0, 0, rxyz[2]) gtrf = gp_GTrsf(mat, gp_XYZ(0, 0, 0)) sphere = BRepPrimAPI_MakeSphere(axs.Ax2(), 1).Solid() ellips = BRepBuilderAPI_GTransform(sphere, gtrf).Shape() return ellips