Java Distance Calculate distance(double[] x, int p, int q, int dim)

Here you can find the source of distance(double[] x, int p, int q, int dim)

Description

computes the euclidean distance of two dim-dimensional points

License

Open Source License

Parameter

Parameter Description
x array of coordinates
p number of the first point
q number of the second point
dim dimension of the points

Return

the euclidean distance of the two points

Declaration

public static double distance(double[] x, int p, int q, int dim) 

Method Source Code

//package com.java2s;
/*// w  w w . j  a  v a  2  s  . co  m
 * Copyright (C) 2013-14  Susanne Westphal
 * CONRAD is developed as an Open Source project under the GNU General Public License (GPL).
 */

public class Main {
    /**
     * computes the euclidean distance of two dim-dimensional points
     * 
     * @param x
     *            array of coordinates
     * @param p
     *            number of the first point
     * @param q
     *            number of the second point
     * @param dim
     *            dimension of the points
     * @return the euclidean distance of the two points
     */
    public static double distance(double[] x, int p, int q, int dim) {
        double sum = 0.0;
        for (int i = 0; i < dim; ++i) {
            sum += Math.pow(x[p * dim + i] - x[q * dim + i], 2);
        }
        return Math.sqrt(sum);
    }
}

Related

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