Euclidean distance

In mathematics, the Euclidean distance or Euclidean metric is the “ordinary” distance between two points that one would measure with a ruler, and is given by the Pythagorean formula.

    /**
     * @param point1   first point
     * @param point2   second point
     * @return  the  Euclidean distance of two points
     */
    public static double getDistance(double[] point1, double[] point2) {
        double distance = 0;
        for (int i = 0; i < point1.length; i++) {
            distance = distance + Math.pow((point1[i] - point2[i]), 2);
        }
        return Math.sqrt(distance);
    }

Tags:

No comments yet.

Leave a Reply