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.