Java Utililty Methods Euclidean Distance

List of utility methods to do Euclidean Distance

Description

The list of methods to do Euclidean Distance are organized into topic(s).

Method

doubleeuclideanDistance(double instance1[], double instance2[])
Calculates the Euclidean distance between two instances
double length = 0.0;
for (int i = 0; i < instance1.length; i++) {
    length += (instance1[i] - instance2[i]) * (instance1[i] - instance2[i]);
length = Math.sqrt(length);
return length;
doubleeuclideanDistance(double x1, double y1, double x2, double y2)
euclidean Distance
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
doubleeuclideanDistance(double x1, double y1, double x2, double y2)
euclidean Distance
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
doubleEuclideanDistance(double xSource, double ySource, double xTarget, double yTarget)
Euclidean Distance
double distance = Math.sqrt(Math.pow(xTarget - xSource, 2) + Math.pow(yTarget - ySource, 2));
return distance;
doubleeuclideanDistance(double[] a, double[] b)
euclidean Distance
if (a.length != b.length) {
    throw new IllegalArgumentException("The dimensions have to be equal!");
double sum = 0.0;
for (int i = 0; i < a.length; i++) {
    sum += Math.pow(a[i] - b[i], 2);
return Math.sqrt(sum);
...
doubleeuclideanDistance(double[] coord1, double[] coord2)
Calculates the Euclidean distance between two coordinates.
return distanceBase(coord1, coord2, 2);
doubleeuclideanDistance(double[] data, double[] pattern)
euclidean Distance
if (data.length != pattern.length) {
    throw new IllegalArgumentException("data and pattern need to be of same size");
double dist = 0;
int i = 0;
for (double value : data) {
    dist += (value - pattern[i]) * (value - pattern[i]);
    ++i;
...
doubleeuclideanDistance(double[] l1, double[] l2, boolean weighted)
euclidean Distance
if (weighted) {
    return weightedEuclideanDistance(l1, l2);
} else {
    return standardEuclideanDistance(l1, l2);
doubleeuclideanDistance(double[] p, double[] q)
This returns the distance of two vectors sum(i=1,n) (q_i - p_i)^2
double ret = 0;
for (int i = 0; i < p.length; i++) {
    double diff = (q[i] - p[i]);
    double sq = Math.pow(diff, 2);
    ret += sq;
return ret;
doubleeuclideanDistance(double[] vector)
euclidean Distance
double result = 0.0;
for (double aVector : vector) {
    result += aVector * aVector;
return Math.sqrt(result);