Here you can find the source of distanceBetween(double xpos1, double ypos1, double xpos2, double ypos2)
public static double distanceBetween(double xpos1, double ypos1, double xpos2, double ypos2)
//package com.java2s; //License from project: Open Source License public class Main { public static double distanceBetween(double xpos1, double ypos1, double xpos2, double ypos2) { //uses Pythagrean Theorem to calculate distance /*//from ww w. j a v a 2s . co m * A X * |\ * | \ c - distance/hypotenuse * | \ * | \ * |____X B */ double a = xpos1 - xpos2; double b = ypos1 - ypos2; double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); return c; } }