Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
wireAdaptor = BRepAdaptor_CompCurve(wire)
curve = BRepAdaptor_HCompCurve(wireAdaptor)
tol = 1e-7
max_segments = 200
max_degrees = 12
approx = Approx_Curve3d(curve, tol, GeomAbs_C2, max_segments, max_degrees)
if (approx.IsDone() and approx.HasResult()):
    an_approximated_curve = approx.Curve()

# there are two ways to project a point on this curve,
# they both give the same restult

# 1st solution: using GeomAPI_ProjectPointOnCurve
point_to_project = gp_Pnt(1., 2., 3.)
projection = GeomAPI_ProjectPointOnCurve(point_to_project,
                                         an_approximated_curve)
# get the results of the projection
projected_point = projection.NearestPoint()
# the number of possible results
nb_results = projection.NbPoints()
print("NbResults : %i" % nb_results)
print("Distance :", projection.LowerDistance())

# 2nd solution : using ShapeAnalysis_Curve().Project
tolerance = 1e-7
proj = gp_Pnt()
distance, parameter = ShapeAnalysis_Curve().Project(an_approximated_curve,
                                                    point_to_project,
                                                    tolerance, proj)
print("Distance :", distance)