Java Distance Calculate distance(double[] a, double[] b)

Here you can find the source of distance(double[] a, double[] b)

Description

Calculates the distance between two points represented by (n-dimensional) vectors.

License

Open Source License

Declaration

public static double distance(double[] a, double[] b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w  ww  .  j  av  a 2s . co m*/
     * Calculates the distance between two points represented by (n-dimensional) vectors.
     */
    public static double distance(double[] a, double[] b) {
        double dist = 0;
        for (int i = 0; i < a.length; i++) {
            double d = a[i] - b[i];
            dist += d * d;
        }
        return Math.sqrt(dist);
    }
}

Related

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