code: public  double distancePointLine(Point2D.Double p1,Point2D.Double p2,Point2D.Double p){
  		double d;
  		double m = (p2.y-p1.y)/(p2.x-p1.x);
  		
  		if(Double.isInfinite(m))
  		{
  			d = Math.abs(p2.x-p.x);
  		}
  		else{
  			double k = -1*m*p1.x+p1.y;
  			d = Math.sqrt( Math.pow( (p.x+m*p.y-m*k)/(m*m+1)-p.x , 2) + Math.pow( m*( (p.x+m*p.y-m*k)/(m*m+1))+k-p.y , 2));
  		}
  		return d;
  	}
docs: Please see
  https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Another_formula
  and
  http://mathworld.wolfram.com/Two-PointForm.html
  @param p1 First point on line
  @param p2 Second point on line
  @param p Point for which the distance should be calculated.
  @return distance of p to line defined by p1&p2