def test_project_point_on_curve(self): '''Test: project point on curve''' P = gp_Pnt(1., 2., 3.) radius = 5. C = Geom_Circle(gp_XOY(), radius) PPC = GeomAPI_ProjectPointOnCurve(P, C) N = PPC.NearestPoint() self.assertIsInstance(N, gp_Pnt) NbResults = PPC.NbPoints() edg = make_edge(C) self.assertFalse(edg.IsNull()) if NbResults > 0: for i in range(1, NbResults+1): Q = PPC.Point(i) self.assertIsInstance(Q, gp_Pnt) distance = PPC.Distance(i) # in any case, it should be > 1 self.assertGreater(distance, 1.) pstring = "N : at Distance : " + repr(PPC.LowerDistance()) for i in range(1, NbResults+1): Q = PPC.Point(i) self.assertIsInstance(Q, gp_Pnt) distance = PPC.Distance(i) # in any case, it should be > 1 self.assertGreater(distance, 1.) pstring = "Q" + repr(i) + ": at Distance :" + repr(PPC.Distance(i)) print(pstring)
def test_pipes(self): '''Test: pipes''' a1 = [] a1.append(gp_Pnt(-4, 0, 2)) a1.append(gp_Pnt(-5, 1, 0)) a1.append(gp_Pnt(-6, 2, -2)) a1.append(gp_Pnt(-5, 4, -7)) a1.append(gp_Pnt(-3, 5, -12)) xxx = point_list_to_TColgp_Array1OfPnt(a1) SPL1 = GeomAPI_PointsToBSpline(xxx).Curve() aPipe = GeomFill_Pipe(SPL1, True) aPipe.Perform(False, False) aSurface = aPipe.Surface() self.assertIsNotNone(aSurface) E = GC_MakeEllipse(gp_XOY(), 2, 1).Value() aPipe2 = GeomFill_Pipe(SPL1, E, GeomFill_IsConstantNormal) aPipe2.Perform(False, False) aSurface2 = aPipe2.Surface() aSurface2.Translate(gp_Vec(5, 0, 0)) TC1 = GC_MakeSegment(gp_Pnt(1, 1, 1), gp_Pnt(2, 2, 2)).Value() TC2 = GC_MakeSegment(gp_Pnt(1, 1, 0), gp_Pnt(3, 2, 1)).Value() aPipe3 = GeomFill_Pipe(SPL1, TC1, TC2) aPipe3.Perform(False, False) aSurface3 = aPipe3.Surface() aSurface3.Translate(gp_Vec(10, 0, 0)) for _, mode in enumerate([GeomFill_IsConstantNormal, GeomFill_IsCorrectedFrenet, GeomFill_IsDarboux, GeomFill_IsFrenet, GeomFill_IsGuideAC, GeomFill_IsGuideACWithContact, GeomFill_IsGuidePlan, GeomFill_IsGuidePlanWithContact]): E = GC_MakeEllipse(gp_XOY(), 2, 1).Value() aPipe2 = GeomFill_Pipe(SPL1, TC1, TC2, mode) aPipe2.Perform(False, False) aSurface2 = aPipe2.Surface() aSurface2.Translate(gp_Vec(5, 5, 0))
def test_point_from_projections(self): '''Test: point from projections''' P = gp_Pnt(7., 8., 9.) radius = 5 SP = Geom_SphericalSurface(gp_Ax3(gp_XOY()), radius) PPS = GeomAPI_ProjectPointOnSurf(P, SP) N = PPS.NearestPoint() self.assertTrue(isinstance(N, gp_Pnt)) NbResults = PPS.NbPoints() if NbResults > 0: for i in range(1, NbResults+1): Q = PPS.Point(i) self.assertTrue(isinstance(Q, gp_Pnt)) distance = PPS.Distance(i) # in any case, it should be > 1 self.assertGreater(distance, 1.) lower_d = PPS.LowerDistance() self.assertGreater(lower_d, 1.) if NbResults > 0: for i in range(1, NbResults+1): Q = PPS.Point(i) distance = PPS.Distance(i) pstring = "Q" + repr(i) + ": at Distance :" + repr(PPS.Distance(i))
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)
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge from OCC.Core.Geom import Geom_CylindricalSurface from OCC.Core.GCE2d import GCE2d_MakeSegment # In[ ]: from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer # In[ ]: # Build an helix aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0) aLine2d = gp_Lin2d (gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0)) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0) helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0, 6.0 * pi).Edge() # In[ ]: my_renderer = JupyterRenderer() # In[ ]:
def round_tooth(wedge): round_x = 2.6 round_z = 0.06 * pitch round_radius = pitch # Determine where the circle used for rounding has to start and stop p2d_1 = gp_Pnt2d(top_radius - round_x, 0) p2d_2 = gp_Pnt2d(top_radius, round_z) # Construct the rounding circle round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01) if (round_circle.NbSolutions() != 2): sys.exit(-2) round_circle_2d_1 = round_circle.ThisSolution(1) round_circle_2d_2 = round_circle.ThisSolution(2) if (round_circle_2d_1.Position().Location().Coord()[1] >= 0): round_circle_2d = round_circle_2d_1 else: round_circle_2d = round_circle_2d_2 # Remove the arc used for rounding trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value() # Calculate extra points used to construct lines p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y()) p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y()) p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y()) p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1) p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1) # Convert the arc and four extra lines into 3D edges plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX())) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge() lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge() lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge() lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge() # Make a wire composed of the edges round_wire = BRepBuilderAPI_MakeWire(arc1) round_wire.Add(lin1) round_wire.Add(lin2) round_wire.Add(lin3) round_wire.Add(lin4) # Turn the wire into a face round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape() # Revolve the face around the Z axis over the tooth angle rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape() # Construct a mirrored copy of the first cutting shape mirror = gp_Trsf() mirror.SetMirror(gp_XOY()) mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape() # and translate it so that it ends up on the other side of the wedge translate = gp_Trsf() translate.SetTranslation(gp_Vec(0, 0, thickness)) rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape() # Cut the wedge using the first and second cutting shape cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape() cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape() return cut_2