Java Distance Calculate distance(double[] p1, double[] p2)

Here you can find the source of distance(double[] p1, double[] p2)

Description

distance

License

Open Source License

Declaration

public static double distance(double[] p1, double[] p2) 

Method Source Code

//package com.java2s;

public class Main {
    public static double distance(double[] p1, double[] p2) {
        double sum = 0;
        for (int i = 0; i < p1.length; i++) {
            sum += Math.pow(p1[i] - p2[i], 2);
        }/*from  w  ww . java 2s .  c  o m*/
        return Math.sqrt(sum);
    }

    public static Double distance(Double[] p1, Double[] p2) {
        double sum = 0;
        for (int i = 0; i < p1.length; i++) {
            sum += Math.pow(p1[i] - p2[i], 2);
        }
        return Math.sqrt(sum);
    }
}

Related

  1. distance(double x1, double y1, double x2, double y2)
  2. distance(double x1, double y1, double z1, double x2, double y2, double z2)
  3. distance(double xOrigin, double yOrigin, double xDestination, double yDestination)
  4. distance(double[] a, double[] b)
  5. distance(double[] a, double[] b)
  6. distance(double[] p1, double[] p2)
  7. distance(double[] x, int p, int q, int dim)
  8. distance(final Class child, final Class parent)
  9. distance(final double x, final double y)