def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] point1 = inp # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == point1: raise InvalidInputException dirvec = vec(0, 0, 0) dirvec[direction] = 1 axis = gp.gp_Ax2(point0, dirvec.to_gp_Dir()) d = point0 - inp d[direction] = 0 dist = d.length() a = Geom.Geom_Circle(axis, dist).GetHandle() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() c = BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire() d = BRepBuilderAPI.BRepBuilderAPI_MakeFace(c).Face() self._final = [d] return self._final
def make_spherical_lens2(CT1, CT2, diameter, curvature1, curvature2, centre, direction, x_axis): cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT1-curvature1), gp.gp_Dir(0,sign(curvature1),0), gp.gp_Dir(1,0,0)) circ = Geom.Geom_Circle(cax, abs(curvature1)) h_circ = Geom.Handle_Geom_Circle(circ) cax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,CT2-curvature2), gp.gp_Dir(0,-sign(curvature2),0), gp.gp_Dir(1,0,0)) circ2 = Geom.Geom_Circle(cax2, abs(curvature2)) h_circ2 = Geom.Handle_Geom_Circle(circ2) r = diameter/2. h2 = CT1 - curvature1 + numpy.sqrt(curvature1**2 - r**2)*sign(curvature1) h3 = CT2 - curvature2 + numpy.sqrt(curvature2**2 - r**2)*sign(curvature2) p1 = gp.gp_Pnt(0,0,CT1) p2 = gp.gp_Pnt(r,0,h2) p3 = gp.gp_Pnt(r,0,h3) p4 = gp.gp_Pnt(0,0,CT2) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ2, p3,p4) e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in (e1,e2,e3,e4): print(e) wire.Add(e.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)) solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax) return position_shape(toshape(solid), centre, direction, x_axis)
def make_spherical_lens(CT, diameter, curvature, centre, direction, x_axis): cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT-curvature), gp.gp_Dir(0,1,0), gp.gp_Dir(1,0,0)) circ = Geom.Geom_Circle(cax, curvature) h_circ = Geom.Handle_Geom_Circle(circ) r = diameter/2. h2 = CT - curvature + numpy.sqrt(curvature**2 - r**2) p1 = gp.gp_Pnt(0,0,CT) p2 = gp.gp_Pnt(r,0,h2) p3 = gp.gp_Pnt(r,0,0) p4 = gp.gp_Pnt(0,0,0) #ps = p1,p2,p3,p4 #vs = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(p) for p in ps] e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3,p4) e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in (e1,e2,e3,e4): print(e) wire.Add(e.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)) solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax) return position_shape(toshape(solid), centre, direction, x_axis)
from OCC import Geom, BRepBuilderAPI, gp from viewer import view import numpy curvature = 50.0 ax = gp.gp_Ax2(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(0, 1, 0), gp.gp_Dir(1, 0, 0)) circ = Geom.Geom_Circle(ax, curvature) h_circ = Geom.Handle_Geom_Circle(circ) angle = 1.3 p1 = gp.gp_Pnt(0, 0, curvature) p2 = gp.gp_Pnt(curvature, 0, 0) edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2) view(edge.Shape())