Hi Sam,

I had a similar problem, but from point to a line segment which is
straight. Look at this code, may be it can be of help:



def closestPointOnLineSegment(lineStartPoint, lineEndPoint, pointInSpace,
ignoreNoProjections=True):
    '''
    Find a closest point on the line segment (defined by 2 points) to a
given point in space.
    NOTE: There may be more limitations - be aware when using!
    Based on "Using Vector Mathematic, Finding closest point on a line",
http://nic-gamedev.blogspot.dk/2011/11/using-vector-mathematics-and-bit-of_08.html
    #---parameters---------------------------------------
    # lineStartPoint       # float list     # A list of 3 elements to
represent a point, that defines the start of the line segment.
    # lineEndPoint         # float list     # A list of 3 elements to
represent a point, that defines the end of the line segment.
    # pointInSpace         # float list     # A list of 3 elements to
represent a point in space.
    # ignoreNoProjections  # boolean        # Points in space that have no
perpendicular to the given line segment will be ignored.
    #---return-------------------------------------------
    #                      # float list     # A list of 3 elements to
represent a point between line points, that is closest to the given point
in space.
    #                                       # If ignoreNoProjections=True
and point is outside the segment - will return a zero vector [0.0, 0.0, 0.0]
    #---example------------------------------------------
    # closestPointOnLineSegment(lineStartPoint=[61.87, 4.31, 1.85],
lineEndPoint=[65.97, 4.15, 2.37], pointInSpace=[67.89, 3.71, 2.60])
    #----------------------------------------------------
    author      Alexandra "Sasha" Ciolac
    version     1.1
    last update 07.03.2013
    #---Update log---------------------------------------
   '''
    ac = vecSubtract(vectorA=lineEndPoint, vectorB=lineStartPoint) # Find
vector between start and end of the line
    l2 = vecMag(vector=ac) * vecMag(vector=ac) # Find it's square length
    ba = vecSubtract(vectorA=pointInSpace, vectorB=lineStartPoint)  # Find
vector from point in space to the start of the line
    dot = vecDot(vectorA=ac, vectorB=ba) # get the dotProduct between ac
and ba
    percent = dot / l2 # Find petcentage from start to end point

    # if percent value is less than 0.0 or greater than 1.0, then the point
in space outside of the line segment - exclude them
    if ignoreNoProjections == True:
        if percent < 0.0 or percent > 1.0:
            return [0.0, 0.0, 0.0] # Return a zero vector

    point = vecAdd(vectorA=lineStartPoint,
vectorB=vecMultScalar(scalar=percent, vector=ac)) # Now we can find the
closest point
    return point


Or use a nearestPointOnCurve node and when done - delete it.

Cheers
Sasha




On Tue, Mar 29, 2016 at 9:31 PM, <[email protected]> wrote:

> Hello there,
>
> i have a point in space and a nearby curve that is running close to the
> point but not touching. Is there a special python/pymel way of finding the
> closest point on the curve to this point in space?
>
> any tips welcome,
>
> thanks,
> Sam
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/d9b03275-9cf2-4ef4-8628-e6e3cf88377d%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CANkfTcmC42miQhe26QG-3JJiXFoqZFcT7T%3D1bJLY3bv6FifNBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to