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

def getDistanceToPlaneSegment ( segmentBegin , segmentEnd , point ) : segmentDifference = ( segmentEnd - segmentBegin ) pointMinusSegmentBegin = ( point - segmentBegin ) beginPlaneDot = getDotProduct ( pointMinusSegmentBegin , segmentDifference ) if ( beginPlaneDot <= 0.0 ) : return ( abs ( ( point - segmentBegin ) ) * abs ( ( point - segmentBegin ) ) ) differencePlaneDot = getDotProduct ( segmentDifference , segmentDifference ) if ( differencePlaneDot <= beginPlaneDot ) : return ( abs ( ( point - segmentEnd ) ) * abs ( ( point - segmentEnd ) ) ) intercept = ( beginPlaneDot / differencePlaneDot ) interceptPerpendicular = ( segmentBegin + ( segmentDifference * intercept ) ) return ( abs ( ( point - interceptPerpendicular ) ) * abs ( ( point - interceptPerpendicular ) ) )
get the distance squared from a point to the x & y components of a segment .