Here you can find the source of distance(final double p1X, final double p1Y, final double p2X, final double p2Y)
public static double distance(final double p1X, final double p1Y, final double p2X, final double p2Y)
//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); } }