def test_circles2d_from_curves(self): '''Test: circles2d from curves''' P1 = gp_Pnt2d(9, 6) P2 = gp_Pnt2d(10, 4) P3 = gp_Pnt2d(6, 7) C = gce_MakeCirc2d(P1, P2, P3).Value() QC = gccent_Outside(C) P4 = gp_Pnt2d(-2, 7) P5 = gp_Pnt2d(12, -3) L = GccAna_Lin2d2Tan(P4, P5, precision_Confusion()).ThisSolution(1) QL = gccent_Unqualified(L) radius = 2. TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision_Confusion()) if TR.IsDone(): NbSol = TR.NbSolutions() for k in range(1, NbSol + 1): circ = TR.ThisSolution(k) # find the solution circle pnt1 = gp_Pnt2d() parsol, pararg = TR.Tangency1(k, pnt1) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the first tangent point pnt2 = gp_Pnt2d() parsol, pararg = TR.Tangency2(k, pnt2) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the second tangent point aLine = GCE2d_MakeSegment(L, -2, 20).Value() self.assertIsInstance(aLine, Geom2d_TrimmedCurve) if TR.IsDone(): NbSol = TR.NbSolutions() for k in range(1, NbSol + 1): circ = TR.ThisSolution(k) aCircle = Geom2d_Circle(circ) self.assertIsInstance(aCircle, Geom2d_Circle) # find the solution circle (index, outvalue, outvalue, gp_Pnt2d) pnt3 = gp_Pnt2d() parsol, pararg = TR.Tangency1(k, pnt3) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the first tangent point pnt4 = gp_Pnt2d() parsol, pararg = TR.Tangency2(k, pnt4) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.)
def test_circles2d_from_curves(self): '''Test: circles2d from curves''' P1 = gp_Pnt2d(9, 6) P2 = gp_Pnt2d(10, 4) P3 = gp_Pnt2d(6, 7) C = gce_MakeCirc2d(P1, P2, P3).Value() QC = gccent_Outside(C) P4 = gp_Pnt2d(-2, 7) P5 = gp_Pnt2d(12, -3) L = GccAna_Lin2d2Tan(P4, P5, precision_Confusion()).ThisSolution(1) QL = gccent_Unqualified(L) radius = 2. TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision_Confusion()) if TR.IsDone(): NbSol = TR.NbSolutions() for k in range(1, NbSol+1): circ = TR.ThisSolution(k) # find the solution circle pnt1 = gp_Pnt2d() parsol, pararg = TR.Tangency1(k, pnt1) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the first tangent point pnt2 = gp_Pnt2d() parsol, pararg = TR.Tangency2(k, pnt2) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the second tangent point aLine = GCE2d_MakeSegment(L, -2, 20).Value() self.assertIsInstance(aLine, Geom2d_TrimmedCurve) if TR.IsDone(): NbSol = TR.NbSolutions() for k in range(1, NbSol+1): circ = TR.ThisSolution(k) aCircle = Geom2d_Circle(circ) self.assertIsInstance(aCircle, Geom2d_Circle) # find the solution circle (index, outvalue, outvalue, gp_Pnt2d) pnt3 = gp_Pnt2d() parsol, pararg = TR.Tangency1(k, pnt3) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the first tangent point pnt4 = gp_Pnt2d() parsol, pararg = TR.Tangency2(k, pnt4) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.)
def test_points_from_intersection(self): '''Test: points from intersection''' PL = gp_Pln(gp_Ax3(gp_XOY())) MinorRadius, MajorRadius = 5, 8 EL = gp_Elips(gp_YOZ(), MajorRadius, MinorRadius) ICQ = IntAna_IntConicQuad(EL, PL, precision_Angular(), precision_Confusion()) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt) aPlane = GC_MakePlane(PL).Value() aSurface = Geom_RectangularTrimmedSurface(aPlane, -8., 8., -12., 12., True, True) self.assertIsNotNone(aSurface) self.assertFalse(aSurface.IsNull()) anEllips = GC_MakeEllipse(EL).Value() self.assertIsInstance(anEllips, Geom_Ellipse) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt)
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 intersect_point(self, x, y): self.Select(x, y) viewLine = self.viewline(x, y) for i in range(len(self.selected_shapes)): hShape = AIS_Shape.DownCast(self.selected_ishapes[i]) shape = hShape.Shape() loc = self.Context.Location(hShape) loc_shape = shape.Located(loc) shapeIntersector = IntCurvesFace_ShapeIntersector() shapeIntersector.Load(loc_shape, precision_Confusion()) shapeIntersector.Perform(viewLine, float("-inf"), float("+inf")) if shapeIntersector.NbPnt() >= 1: ip = shapeIntersector.Pnt(1) return point3(ip), True else: continue return point3(), False
def test_points_from_intersection(self): '''Test: points from intersection''' PL = gp_Pln(gp_Ax3(gp_XOY())) MinorRadius, MajorRadius = 5, 8 EL = gp_Elips(gp_YOZ(), MajorRadius, MinorRadius) ICQ = IntAna_IntConicQuad(EL, PL, precision_Angular(), precision_Confusion()) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt) aPlane = GC_MakePlane(PL).Value() aSurface = Geom_RectangularTrimmedSurface(aPlane, - 8., 8., - 12., 12., True, True) self.assertIsNotNone(aSurface) self.assertFalse(aSurface.IsNull()) anEllips = GC_MakeEllipse(EL).Value() self.assertIsInstance(anEllips, Geom_Ellipse) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt)
def _helix(r, h, step=None, pitch=None, angle=0, left=False): radius = r height = h if pitch: pitch = math.sin(pitch) * 2 * math.pi * r else: pitch = step if pitch < precision_Confusion(): raise Exception("Pitch of helix too small") if height < precision_Confusion(): raise Exception("Height of helix too small") cylAx2 = gp_Ax2(gp_Pnt(0.0, 0.0, 0.0), gp_DZ()) if abs(angle) < precision_Confusion(): # Cylindrical helix if radius < precision_Confusion(): raise Exception("Radius of helix too small") surf = Geom_CylindricalSurface(gp_Ax3(cylAx2), radius) isCylinder = True else: # Conical helix if abs(angle) < precision_Confusion(): raise Exception("Angle of helix too small") surf = Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius) isCylinder = False turns = height / pitch wholeTurns = math.floor(turns) partTurn = turns - wholeTurns aPnt = gp_Pnt2d(0, 0) aDir = gp_Dir2d(2. * math.pi, pitch) coneDir = 1.0 if left: aDir.SetCoord(-2. * math.pi, pitch) coneDir = -1.0 aAx2d = gp_Ax2d(aPnt, aDir) line = Geom2d_Line(aAx2d) beg = line.Value(0) mkWire = BRepBuilderAPI_MakeWire() for i in range(wholeTurns): if isCylinder: end = line.Value( math.sqrt(4.0 * math.pi * math.pi + pitch * pitch) * (i + 1)) else: u = coneDir * (i + 1) * 2.0 * math.pi v = ((i + 1) * pitch) / math.cos(angle) end = gp_Pnt2d(u, v) segm = GCE2d_MakeSegment(beg, end).Value() edgeOnSurf = BRepBuilderAPI_MakeEdge(segm, surf).Edge() mkWire.Add(edgeOnSurf) beg = end if partTurn > precision_Confusion(): if (isCylinder): end = line.Value( math.sqrt(4.0 * math.pi * math.pi + pitch * pitch) * turns) else: u = coneDir * turns * 2.0 * math.pi v = height / math.cos(angle) end = gp_Pnt2d(u, v) segm = GCE2d_MakeSegment(beg, end).Value() edgeOnSurf = BRepBuilderAPI_MakeEdge(segm, surf).Edge() mkWire.Add(edgeOnSurf) shape = mkWire.Wire() breplib.BuildCurves3d(shape) return Shape(shape)
def write_face(self, points_face, list_points_edge, topo_face, toledge): """ Method to recreate a Face associated to a geometric surface after the modification of Face points. It returns a TopoDS_Face. :param points_face: the new face points array. :param list_points_edge: new edge points :param topo_face: the face to be modified :param toledge: tolerance on the surface creation after modification :return: TopoDS_Face (Shape) :rtype: TopoDS_Shape """ # convert Face to Geom B-spline Surface nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_face) nurbs_converter.Perform(topo_face) nurbs_face = nurbs_converter.Shape() topo_nurbsface = topods.Face(nurbs_face) h_geomsurface = BRep_Tool.Surface(topo_nurbsface) h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface) bsurface = h_bsurface nb_u = bsurface.NbUPoles() nb_v = bsurface.NbVPoles() # check consistency if points_face.shape[0] != nb_u * nb_v: raise ValueError("Input control points do not have not have the " "same number as the geometric face!") # cycle on the face points indice_cpt = 0 for iu in range(1, nb_u + 1): for iv in range(1, nb_v + 1): cpt = points_face[indice_cpt] bsurface.SetPole(iu, iv, gp_Pnt(cpt[0], cpt[1], cpt[2])) indice_cpt += 1 # create modified new face new_bspline_tface = BRepBuilderAPI_MakeFace() toler = precision_Confusion() new_bspline_tface.Init(bsurface, False, toler) # cycle on the wires face_wires_explorer = TopExp_Explorer( topo_nurbsface.Oriented(TopAbs_FORWARD), TopAbs_WIRE) ind_edge_total = 0 while face_wires_explorer.More(): # get old wire twire = topods_Wire(face_wires_explorer.Current()) # cycle on the edges ind_edge = 0 wire_explorer_edge = TopExp_Explorer( twire.Oriented(TopAbs_FORWARD), TopAbs_EDGE) # check edges order on the wire mode3d = True tolerance_edges = toledge wire_order = ShapeAnalysis_WireOrder(mode3d, tolerance_edges) # an edge list deformed_edges = [] # cycle on the edges while wire_explorer_edge.More(): tedge = topods_Edge(wire_explorer_edge.Current()) new_bspline_tedge = self.write_edge( list_points_edge[ind_edge_total], tedge) deformed_edges.append(new_bspline_tedge) analyzer = topexp() vfirst = analyzer.FirstVertex(new_bspline_tedge) vlast = analyzer.LastVertex(new_bspline_tedge) pt1 = BRep_Tool.Pnt(vfirst) pt2 = BRep_Tool.Pnt(vlast) wire_order.Add(pt1.XYZ(), pt2.XYZ()) ind_edge += 1 ind_edge_total += 1 wire_explorer_edge.Next() # grouping the edges in a wire, then in the face # check edges order and connectivity within the wire wire_order.Perform() # new wire to be created stol = ShapeFix_ShapeTolerance() new_bspline_twire = BRepBuilderAPI_MakeWire() for order_i in range(1, wire_order.NbEdges() + 1): deformed_edge_i = wire_order.Ordered(order_i) if deformed_edge_i > 0: # insert the deformed edge to the new wire new_edge_toadd = deformed_edges[deformed_edge_i - 1] stol.SetTolerance(new_edge_toadd, toledge) new_bspline_twire.Add(new_edge_toadd) if new_bspline_twire.Error() != 0: stol.SetTolerance(new_edge_toadd, toledge * 10.0) new_bspline_twire.Add(new_edge_toadd) else: deformed_edge_revers = deformed_edges[ np.abs(deformed_edge_i) - 1] stol.SetTolerance(deformed_edge_revers, toledge) new_bspline_twire.Add(deformed_edge_revers) if new_bspline_twire.Error() != 0: stol.SetTolerance(deformed_edge_revers, toledge * 10.0) new_bspline_twire.Add(deformed_edge_revers) # add new wire to the Face new_bspline_tface.Add(new_bspline_twire.Wire()) face_wires_explorer.Next() return topods.Face(new_bspline_tface.Face())