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 project_point_on_curve(): ''' ''' point_to_project = gp_Pnt(1., 2., 3.) radius = 5. # create a circle, centered at origin with a given radius circle = Geom_Circle(gp_XOY(), radius) display.DisplayShape(circle) display.DisplayShape(point_to_project, update=True) display.DisplayMessage(point_to_project, "P") # project the point P on the circle projection = GeomAPI_ProjectPointOnCurve(point_to_project, circle) # get the results of the projection # the point projected_point = projection.NearestPoint() # the number of possible results nb_results = projection.NbPoints() print("NbResults : %i" % nb_results) pstring = "N : at Distance : %f" % projection.LowerDistance() display.DisplayMessage(projected_point, pstring) # thre maybe many different possible solutions if nb_results > 0: for i in range(1, nb_results+1): Q = projection.Point(i) distance = projection.Distance(i) pstring = "Q%i: at Distance :%f" % (i, distance) display.DisplayShape(Q) display.DisplayMessage(Q, pstring)