Ejemplo n.º 1
0
def findPointOnCurve(point, handleCurve, tolerance):
    "return the closest parameter on the curve for the provided point"
    "returns none if a point is not within tolerance"
    gp = GeomAPI.GeomAPI_ProjectPointOnCurve(point, handleCurve)
    gp.Perform(point)
    if gp.NbPoints() > 0 and gp.LowerDistance() <= tolerance:
        #log.debug( "Projection Success!" );
        return [gp.LowerDistanceParameter(),
                gp.NearestPoint()]
    else:
        #log.warn( "Projection Failed.");
        return None
Ejemplo n.º 2
0
def findPointOnCurve(point, handleCurve, tolerance, umin=None, umax=None):
    "return the closest parameter on the curve for the provided point"
    "returns none if a point is not within tolerance"
    if umin is None:
        gp = GeomAPI.GeomAPI_ProjectPointOnCurve(point, handleCurve)
    else:
        gp = GeomAPI.GeomAPI_ProjectPointOnCurve(point, handleCurve, umin,
                                                 umax)
    gp.Perform(point)
    #print "tolerance = %0.3f, nbpoints=%d" % ( tolerance , gp.NbPoints() )
    if gp.NbPoints() > 0 and gp.LowerDistance() <= tolerance:
        #log.debug( "Projection Success!" );
        return [gp.LowerDistanceParameter(),
                gp.NearestPoint()]
    else:
        raise Exception("Projection Failed, try larger Tolerance!")
Ejemplo n.º 3
0
def findParameterOnCurve(point, handleCurve, tolerance):
    "return the closest parameter on the curve for the provided point"
    "returns none if a point is not within tolerance"
    #TODO: Extrema.Extrema_ExtPC will project a point onto an Adaptor_3d Curve
    #so we do not have to approximate with a bspline
    #BrepAdaptor.BrepAdaptor_CompCurve.Trim() will return a trimmed curve between two parameters
    #E1CLib can project points on elementary curves (lines and conics )
    gp = GeomAPI.GeomAPI_ProjectPointOnCurve(point, handleCurve)
    gp.Perform(point)
    if gp.NbPoints() > 0:
        #log.debug( "Projection Success!" );
        return [point, gp.LowerDistanceParameter(),
                gp.LowerDistance()]
    else:
        #log.error( "Projection Failed.");
        return None
Ejemplo n.º 4
0
def projectPointOnCurve2d(handleCurve, point, tolerance):
    "return the closest parameter on the curve for the provided point"
    "returns none if a point is not within tolerance"

    #get start and end params of curve
    curve = handleCurve.GetObject()

    gp = Geom2dAPI.Geom2dAPI_ProjectPointOnCurve(point, handleCurve,
                                                 curve.FirstParameter(),
                                                 curve.LastParameter())
    if gp.NbPoints() > 0 and gp.LowerDistance() <= tolerance:
        #log.debug( "Projection Success!" );
        #print "project success."
        return (gp.LowerDistanceParameter(), gp.NearestPoint())
    else:
        print("Projection Failed.")
        return None