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

doubleeuclidean(double[] _a, double[] _b)

Computes the euclidean distance between two vector of doubles with equal size.

double toRet = 0;
if (_a.length != _b.length) {
    System.out.println("ERROR: Euclidean can not be used if vectors have different size!");
    toRet = -1;
} else {
    for (int i = 0; i < _a.length; ++i) {
        toRet += (_a[i] - _b[i]) * (_a[i] - _b[i]);
    toRet = Math.sqrt(toRet);
return toRet;
doubleeuclidean(double[] a, double[] b)
Calculates Euclidean distance for a pair of coordinates
if (a.length != b.length) {
    throw new IllegalArgumentException("Arrays must have the same length");
int dim = a.length;
double d = 0;
for (int i = 0; i < dim; i++) {
    d += (a[i] - b[i]) * (a[i] - b[i]);
return Math.sqrt(d);
doubleeuclidean(Double[] a, Double[] b)
Compute the Euclidean distance between two arrays of the same size.
double sum = 0.0;
for (int i = 0; i < a.length; i++) {
    double diff = a[i] - b[i];
    sum += diff * diff;
return Math.sqrt(sum);
doubleeuclidean(double[] features1, double[] features2)
euclidean
double d = 0;
if (features1 == null || features2 == null) {
    return 0;
for (int i = 0; i < features1.length; i++) {
    d += (features1[i] - features2[i]) * (features1[i] - features2[i]);
return Math.sqrt(d);
...
doubleeuclidean(double[] x1, double[] x2)
euclidean
double[] x3 = arraySubtract(x1, x2);
double result = 0;
for (double x : x3)
    if (x != 0)
        result += x * x;
return Math.pow(result, 0.5);
doubleeuclidean(double[] xvalues, double[] yvalues, int[] include)
Returns the euclidean distance between xvalues and yvalues for those include values that are non-zero.
double ddiff;
double ddist;
double dsumsq = 0;
for (int nindex = 0; nindex < include.length; nindex++) {
    if (include[nindex] != 0) {
        ddiff = (xvalues[nindex] - yvalues[nindex]);
        dsumsq += ddiff * ddiff;
ddist = Math.sqrt(dsumsq);
return ddist;
doubleeuclidean_distance(double[] vec1, double[] vec2)
euclideadistance
double dist = 0;
for (int i = 0; i < vec1.length && i < vec2.length; i++)
    dist += Math.pow(vec1[i] - vec2[i], 2);
dist = Math.sqrt(dist);
return dist;
doubleeuclideanDist(double[] ePointOne, double[] ePoint2)
euclidean Dist
double diff;
int i;
double eDist = 0;
for (i = 0; i < ePointOne.length; i++) {
    if (i < ePoint2.length) {
        diff = ePointOne[i] - ePoint2[i];
    } else {
        diff = 0;
...
doubleeuclideanDist(final double[] vec1, final double[] vec2, int n)
Compute the euclidean distance between 2 vectors.
assert vec1 != null;
assert vec2 != null;
assert vec1.length == n;
assert vec2.length == n;
double dist = 0;
for (int i = 0; i < n; i++) {
    dist += Math.pow(vec1[i] - vec2[i], 2);
return Math.sqrt(dist);
doubleeuclideanDist(float[] v1, float[] v2)
euclidean Dist
float dist = 0;
for (int i = 0; i < Math.min(v1.length, v2.length); ++i) {
    dist += (v1[i] - v2[i]) * (v1[i] - v2[i]);
return Math.sqrt(dist);