def ConvertBndToShape(theBox): aBaryCenter = theBox.Center() aXDir = theBox.XDirection() aYDir = theBox.YDirection() aZDir = theBox.ZDirection() aHalfX = theBox.XHSize() aHalfY = theBox.YHSize() aHalfZ = theBox.ZHSize() ax = gp_XYZ(aXDir.X(), aXDir.Y(), aXDir.Z()) ay = gp_XYZ(aYDir.X(), aYDir.Y(), aYDir.Z()) az = gp_XYZ(aZDir.X(), aZDir.Y(), aZDir.Z()) p = gp_Pnt(aBaryCenter.X(), aBaryCenter.Y(), aBaryCenter.Z()) anAxes = gp_Ax2(p, gp_Dir(aZDir), gp_Dir(aXDir)) anAxes.SetLocation( gp_Pnt(p.XYZ() - ax * aHalfX - ay * aHalfY - az * aHalfZ)) aBox = BRepPrimAPI_MakeBox(anAxes, 2.0 * aHalfX, 2.0 * aHalfY, 2.0 * aHalfZ).Shape() return aBox
def as_xyz(self): '''returns a gp_XYZ version of self''' return gp_XYZ(*self._pnt.Coord())
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox from OCCT.BRepBuilderAPI import BRepBuilderAPI_GTransform from OCCT.BRepAlgoAPI import BRepAlgoAPI_Common from OCCT.Visualization import BasicViewer 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()