Java Distance between Points distance(final double p1X, final double p1Y, final double p2X, final double p2Y)

Here you can find the source of distance(final double p1X, final double p1Y, final double p2X, final double p2Y)

Description

distance

License

Open Source License

Declaration

public static double distance(final double p1X, final double p1Y, final double p2X, final double p2Y) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class Main {
    public static double distance(final double p1X, final double p1Y, final double p2X, final double p2Y) {
        return Math.sqrt((p1X - p2X) * (p1X - p2X) + (p1Y - p2Y) * (p1Y - p2Y));
    }/*from  w  ww .  jav a2s.c o m*/

    public static double distance(final Point2D p1, final Point2D p2) {
        return Math.sqrt((p1.getX() - p2.getX()) * (p1.getX() - p2.getX())
                + (p1.getY() - p2.getY()) * (p1.getY() - p2.getY()));
    }

    /**
     * Distance.
     *
     * @param rect
     *          the rect
     * @param p
     *          the p
     * @return the double
     */
    public static double distance(final Rectangle2D rect, final Point2D p) {
        final double dx = Math.max(rect.getMinX() - p.getX(), p.getX() - rect.getMaxX());
        final double dy = Math.max(rect.getMinY() - p.getY(), p.getY() - rect.getMaxY());
        return Math.sqrt(dx * dx + dy * dy);
    }
}

Related

  1. distance(@Nonnull Point2D pA, @Nonnull Point2D pB)
  2. distance(Point2D a, Point2D b)
  3. DistanceSquareToLine(double x, double y, double x1, double y1, double x2, double y2)
  4. getDistance(Point2D point1, Point2D point2)
  5. getDistance(Point2D point1, Point2D point2)