public static double distancePointLinePerpendicular(Coordinate p,Coordinate A,Coordinate B){
  double len2=(B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
  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);
}

public static double distancePointLinePerpendicular ( Coordinate p , Coordinate A , Coordinate B ) { double len2 = ( B . x - A . x ) * ( B . x - A . x ) + ( B . y - A . y ) * ( B . y - A . y ) ; 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 ) ; }
computes the perpendicular distance from a point p to the ( infinite ) line containing the points ab
