Java Distance Calculate squaredEuclideanDistance(double[] x, double[] y)

Here you can find the source of squaredEuclideanDistance(double[] x, double[] y)

Description

Compute the squared euclidean distance between two doubles arrays

License

Open Source License

Parameter

Parameter Description
x a parameter
y a parameter

Return

the *squared* euclidean distance

Declaration

public static double squaredEuclideanDistance(double[] x, double[] y) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2014  C?ssio M. M. Pereira
    //from  w w  w.j  a  v a2s  .  co m
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

public class Main {
    /**
     * Compute the squared euclidean distance between two doubles arrays
     * @param x
     * @param y
     * @return the *squared* euclidean distance
     */
    public static double squaredEuclideanDistance(double[] x, double[] y) {
        double dist = 0;
        double diff;

        for (int i = 0; i < x.length; i++) {
            diff = x[i] - y[i];
            dist += diff * diff;
        }

        return dist;
    }
}

Related

  1. distVector(double[] vector1, double[] vector2)
  2. distVincentyRAD(double lat1, double lon1, double lat2, double lon2)
  3. getDistance(double lat1, double lng1, double lat2, double lng2)
  4. sqrDistance(float x1, float y1, float x2, float y2)
  5. squaredDistance(float[] p, int a, int b)
  6. squareDist31TileMetric(int x1, int y1, int x2, int y2)
  7. squareDistance(double pointAX, double pointAY, double pointBX, double pointBY)
  8. squareDistance(double x1, double y1, double x2, double y2)
  9. squaredistance(double[] v1, double[] v2)