def dist_point_to_segment(p, s0, s1):
p = np.asarray(p, np.float_)<EOL>s0 = np.asarray(s0, np.float_)<EOL>s1 = np.asarray(s1, np.float_)<EOL>v = s1 - s0<EOL>w = p - s0<EOL>c1 = np.dot(w,v);<EOL>if ( c1 <= <NUM_LIT:0> ):<EOL><INDENT>return dist(p, s0);<EOL><DEDENT>c2 = np.dot(v,v)<EOL>if ( c2 <= c1 ):<EOL><INDENT>return dist(p, s1);<EOL><DEDENT>b = c1 / c2<EOL>pb = s0 + b * v;<EOL>return dist(p, pb)<EOL>
Get the distance of a point to a segment.

  *p*, *s0*, *s1* are *xy* sequences

This algorithm from
http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm#Distance%20to%20Ray%20or%20Segment