def points_from_intersection(): ''' @param display: ''' plane = gp_Pln(gp_Ax3(gp_XOY())) minor_radius, major_radius = 5., 8. ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius) intersection = IntAna_IntConicQuad(ellips, plane, precision_Angular(), precision_Confusion()) a_plane = GC_MakePlane(plane).Value() a_surface = Geom_RectangularTrimmedSurface(a_plane, -8., 8., -12., 12., True, True) display.DisplayShape(a_surface, update=True) anEllips = GC_MakeEllipse(ellips).Value() display.DisplayShape(anEllips) if intersection.IsDone(): nb_results = intersection.NbPoints() if nb_results > 0: for i in range(1, nb_results + 1): P = intersection.Point(i) pstring = "P%i" % i display.DisplayShape(P) display.DisplayMessage(P, pstring)
def points_from_intersection(event=None): ''' @param display: ''' plane = gp_Pln(gp_Ax3(gp_XOY())) minor_radius, major_radius = 5., 8. ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius) intersection = IntAna_IntConicQuad(ellips, plane, precision_Angular(), precision_Confusion()) a_plane = GC_MakePlane(plane).Value() a_surface = Geom_RectangularTrimmedSurface(a_plane, - 8., 8., - 12., 12., True, True) display.DisplayShape(a_surface, update=True) anEllips = GC_MakeEllipse(ellips).Value() display.DisplayShape(anEllips) if intersection.IsDone(): nb_results = intersection.NbPoints() if nb_results > 0: for i in range(1, nb_results + 1): P = intersection.Point(i) pstring = "P%i" % i display.DisplayShape(P) display.DisplayMessage(P, pstring)
def make_ellipse(p, rx, ry, rotate=0, direction=Z_DIR): """ gp_Elips doesn't allow minor > major so swap and rotate instead if that's the case. """ c = gp_Pnt(*p) if ry > rx: rx, ry = ry, rx # Swap rotate += pi/2 # This only works when rotate == 0 ellipse = gp_Elips(gp_Ax2(c, direction), rx, ry) ellipse.Rotate(gp_Ax1(c, direction), rotate) return ellipse
def edge(event=None): # The blud edge BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) #The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) #The red edge Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi / 2) # The green edge and the both extreme vertex P1 = gp_Pnt(-15, 200, 10) P2 = gp_Pnt(5, 204, 0) P3 = gp_Pnt(15, 200, 0) P4 = gp_Pnt(-15, 20, 15) P5 = gp_Pnt(-5, 20, 0) P6 = gp_Pnt(15, 20, 0) P7 = gp_Pnt(24, 120, 0) P8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, P1) array.SetValue(2, P2) array.SetValue(3, P3) array.SetValue(4, P4) array.SetValue(5, P5) array.SetValue(6, P6) array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') display.DisplayShape(V1.Vertex()) display.DisplayShape(V2.Vertex()) display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') display.DisplayColoredShape(RedEdge.Edge(), 'RED') display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') display.DisplayShape(V3) display.DisplayShape(V4, update=True)
def edge(event=None): # The blud edge BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) #The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) #The red edge Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2) # The green edge and the both extreme vertex P1 = gp_Pnt(-15, 200, 10) P2 = gp_Pnt(5, 204, 0) P3 = gp_Pnt(15, 200, 0) P4 = gp_Pnt(-15, 20, 15) P5 = gp_Pnt(-5, 20, 0) P6 = gp_Pnt(15, 20, 0) P7 = gp_Pnt(24, 120, 0) P8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, P1) array.SetValue(2, P2) array.SetValue(3, P3) array.SetValue(4, P4) array.SetValue(5, P5) array.SetValue(6, P6) array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') display.DisplayShape(V1.Vertex()) display.DisplayShape(V2.Vertex()) display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') display.DisplayColoredShape(RedEdge.Edge(), 'RED') display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') display.DisplayShape(V3) display.DisplayShape(V4, update=True)
def edge(event=None): # The blud edge blue_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) v1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) v2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) yellow_edge = BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex()) # The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) white_edge = BRepBuilderAPI_MakeEdge(line, -20, 10) # The red edge elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) red_edge = BRepBuilderAPI_MakeEdge(elips, 0, math.pi / 2) # The green edge and the both extreme vertex p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 0) p7 = gp_Pnt(24, 120, 0) p8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, p1) array.SetValue(2, p2) array.SetValue(3, p3) array.SetValue(4, p4) array.SetValue(5, p5) array.SetValue(6, p6) array.SetValue(7, p7) array.SetValue(8, p8) curve = Geom_BezierCurve(array) make_edge = BRepBuilderAPI_MakeEdge(curve.GetHandle()) green_edge = make_edge v3 = make_edge.Vertex1() v4 = make_edge.Vertex2() display.DisplayColoredShape(blue_edge.Edge(), 'BLUE') display.DisplayShape(v1.Vertex()) display.DisplayShape(v2.Vertex()) display.DisplayColoredShape(white_edge.Edge(), 'WHITE') display.DisplayColoredShape(yellow_edge.Edge(), 'YELLOW') display.DisplayColoredShape(red_edge.Edge(), 'RED') display.DisplayColoredShape(green_edge.Edge(), 'GREEN') display.DisplayShape(v3) display.DisplayShape(v4, update=True)
def make_ellipsoid_2(focus1, focus2, major_axis): 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 ) el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), major_axis, minor_axis) edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, gp.gp_Pnt(0,0,major_axis), gp.gp_Pnt(0,0,-major_axis)) edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0,0,-major_axis), gp.gp_Pnt(0,0,major_axis)) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() wire.Add(edge1.Edge()) wire.Add(edge2.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) el = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)), numpy.pi*2) 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(el.Shape(), tr) shape = toshape(trans) return shape
#!/usr/bin/python # coding: utf-8 r"""test_revolve.py" """ from math import pi from OCC import BRepPrimAPI, gp, BRepBuilderAPI from viewer import view el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(1, 0, 0)), 20.0, 10.0) edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, gp.gp_Pnt(0, 0, 20), gp.gp_Pnt(0, 0, -20)) edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0, 0, -20), gp.gp_Pnt(0, 0, 20)) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() wire.Add(edge1.Edge()) wire.Add(edge2.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) el = BRepPrimAPI.BRepPrimAPI_MakeRevol( face.Shape(), gp.gp_Ax1(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(0, 0, 1)), pi * 2) # h_curve = Geom.Handle_Geom_Ellipse(curve) # rev = BRepPrimAPI.BRepPrimAPI_MakeRevolution(h_curve, 120.1) # #nurbs = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(rev.Shape()) view(el.Shape())
def _make_ellipse(self): ellipse = gp_Elips(gp_Ax2(gp_Pnt(1, 2, 3), gp_DZ()), 4.0, 2.0) return Shape.cast(BRepBuilderAPI_MakeEdge(ellipse).Edge())
def create_shape(self): d = self.declaration self.make_edge(gp_Elips(d.axis, d.major_radius, d.minor_radius))
from OCC import BRepPrimAPI, Geom, gp, BRepBuilderAPI from viewer import view from math import pi el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), 20.0, 10.0) edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, gp.gp_Pnt(0,0,20), gp.gp_Pnt(0,0,-20)) edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0,0,-20), gp.gp_Pnt(0,0,20)) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() wire.Add(edge1.Edge()) wire.Add(edge2.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) el = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)), pi*2) #h_curve = Geom.Handle_Geom_Ellipse(curve) #rev = BRepPrimAPI.BRepPrimAPI_MakeRevolution(h_curve, 120.1) ##nurbs = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(rev.Shape()) view(el.Shape())
def create_shape(self): d = self.declaration self.make_edge(gp_Elips(d.axis,d.major_radius,d.minor_radius))