def getClosestPointOnSegment(segmentBegin, segmentEnd, point):
 segmentDifference = (segmentEnd - segmentBegin)
 if (abs(segmentDifference) <= 0.0):
  return segmentBegin
 pointMinusSegmentBegin = (point - segmentBegin)
 beginPlaneDot = getDotProduct(pointMinusSegmentBegin, segmentDifference)
 differencePlaneDot = getDotProduct(segmentDifference, segmentDifference)
 intercept = (beginPlaneDot / differencePlaneDot)
 intercept = max(intercept, 0.0)
 intercept = min(intercept, 1.0)
 return (segmentBegin + (segmentDifference * intercept))

def getClosestPointOnSegment ( segmentBegin , segmentEnd , point ) : segmentDifference = ( segmentEnd - segmentBegin ) if ( abs ( segmentDifference ) <= 0.0 ) : return segmentBegin pointMinusSegmentBegin = ( point - segmentBegin ) beginPlaneDot = getDotProduct ( pointMinusSegmentBegin , segmentDifference ) differencePlaneDot = getDotProduct ( segmentDifference , segmentDifference ) intercept = ( beginPlaneDot / differencePlaneDot ) intercept = max ( intercept , 0.0 ) intercept = min ( intercept , 1.0 ) return ( segmentBegin + ( segmentDifference * intercept ) )
get the closest point on the segment .