Here you can find the source of distance2d(double x1, double y1, double x2, double y2)
public static double distance2d(double x1, double y1, double x2, double y2)
//package com.java2s; public class Main { public static double distance2d(double x1, double y1, double x2, double y2) { double dx = Math.abs(x2 - x1); double dy = Math.abs(y2 - y1); double max = Math.max(dx, dy); if (max == 0) return 0; dx /= max;/*from ww w . j a va 2s . c o m*/ dy /= max; return max * Math.sqrt(dx * dx + dy * dy); } }