Java Distance between Points DistanceSquareToLine(double x, double y, double x1, double y1, double x2, double y2)

Here you can find the source of DistanceSquareToLine(double x, double y, double x1, double y1, double x2, double y2)

Description

Distance Square To Line

License

BSD License

Declaration

public static double DistanceSquareToLine(double x, double y,
            double x1, double y1, double x2, double y2) 

Method Source Code

//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);
    }
}

Related

  1. distance(@Nonnull Point2D pA, @Nonnull Point2D pB)
  2. distance(final double p1X, final double p1Y, final double p2X, final double p2Y)
  3. distance(Point2D a, Point2D b)
  4. getDistance(Point2D point1, Point2D point2)
  5. getDistance(Point2D point1, Point2D point2)
  6. getDistance(Point2D.Double pt1, Point2D.Double pt2)