def make_ellipsoid(focus1, focus2, major_axis): """ @param focus1: length 3 sequence giving first focus location @param focus2: length 3 sequence giving second focus location @param path_length: major axis length """ f1 = numpy.asarray(focus1) f2 = numpy.asarray(focus2) direction = -(f1 - f2) centre = (f1 + f2)/2. sep = numpy.sqrt((direction**2).sum()) minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 ) sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(minor_axis) scale = gp.gp_GTrsf() scale.SetValue(3,3, major_axis/minor_axis) ellipse = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), scale) loc = gp.gp_Ax3() loc.SetLocation(gp.gp_Pnt(*centre)) loc.SetDirection(gp.gp_Dir(*direction)) tr = gp.gp_Trsf() tr.SetTransformation(loc, gp.gp_Ax3()) trans = BRepBuilderAPI.BRepBuilderAPI_Transform(ellipse.Shape(), tr) shape = toshape(trans) return shape
from viewer import view from OCC import BRepPrimAPI, BRepBuilderAPI, gp, Geom, STEPControl R = 50. sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(R) def scale(sx, sy, sz): t = gp.gp_GTrsf() t.SetValue(1, 1, sx) t.SetValue(2, 2, sy) t.SetValue(3, 3, sz) return t trans = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), scale(1, 1, 2)) step_export = STEPControl.STEPControl_Writer() step_export.Transfer(trans.Shape(), STEPControl.STEPControl_AsIs) step_export.Write("/home/bryan/test_ellipse.stp") #el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), 10, 5) #EL = Geom.Geom_Ellipse(el) #handle = Geom.Handle_Geom_Ellipse(EL) #revolve = BRepPrimAPI.BRepPrimAPI_MakeRevolution(handle, 180) #nurbs = #view(revolve.Shape())
def ScaleY(self, val): v = self.Value(2, 2) self.SetValue(2, 2, val * v) def ScaleZ(self, val): v = self.Value(3, 3) self.SetValue(3, 3, val * v) def Translate(self, dx, dy, dz): self.SetTranslationPart(gp.gp_XYZ(dx, dy, dz)) t = GTransform() t.ScaleZ(2.0) trans = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), t) box = BRepPrimAPI.BRepPrimAPI_MakeBox(100, 100, 100) cut = BRepAlgoAPI.BRepAlgoAPI_Cut(box.Shape(), trans.Shape()) view(cut.Shape()) #step_export = STEPControl.STEPControl_Writer() #step_export.Transfer(trans.Shape(), STEPControl.STEPControl_AsIs) #step_export.Write("/home/bryan/test_ellipse.stp") #el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), 10, 5) #EL = Geom.Geom_Ellipse(el) #handle = Geom.Handle_Geom_Ellipse(EL) #revolve = BRepPrimAPI.BRepPrimAPI_MakeRevolution(handle, 180)