Here you can find the source of DistanceSquareToLine(double x, double y, double x1, double y1, double x2, double y2)
public static double DistanceSquareToLine(double x, double y, double x1, double y1, double x2, double y2)
//package com.java2s; // LICENSE: This file is distributed under the BSD license. import java.awt.Point; import java.awt.geom.Point2D; public class Main { public static double DistanceSquareToLine(double x, double y, double x1, double y1, double x2, double y2) { double d1 = x1 - x2; double d2 = y1 - y2; double d = d1 * d1 + d2 * d2; if (d <= 0) return 0; double n = x * y1 - x1 * y + x1 * y2 - x2 * y1 + x2 * y - x * y2; return n * n / d; }/*w ww .j a v a 2s.c o m*/ /** * * @param pt * @param LinePt1 * @param LinePt2 * @return */ public static double DistanceSquareToLine(Point pt, Point2D.Float LinePt1, Point2D.Float LinePt2) { return DistanceSquareToLine(pt.x, pt.y, LinePt1.x, LinePt1.y, LinePt2.x, LinePt2.y); } }