question: public static double distancePointLine ( Coordinate p , Coordinate A , Coordinate B ) { if ( A . x == B . x && A . y == B . y ) return p . distance ( A ) ; double len2 = ( B . x - A . x ) * ( B . x - A . x ) + ( B . y - A . y ) * ( B . y - A . y ) ; double r = ( ( p . x - A . x ) * ( B . x - A . x ) + ( p . y - A . y ) * ( B . y - A . y ) ) / len2 ; if ( r <= 0.0 ) return p . distance ( A ) ; if ( r >= 1.0 ) return p . distance ( B ) ; double s = ( ( A . y - p . y ) * ( B . x - A . x ) - ( A . x - p . x ) * ( B . y - A . y ) ) / len2 ; return Math . abs ( s ) * Math . sqrt ( len2 ) ; }
target:  Computes the distance from a point p to a line segment AB Note: NON-ROBUST!