Java Distance Calculate squareDistance(final double[] a, final double[] b)

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

Description

get the squared length of (a - b).

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Declaration

public static double squareDistance(final double[] a, final double[] b) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w  ww . j ava  2 s.co  m*/
     * get the squared length of (a - b).
     * 
     * @param a
     * @param b
     */
    public static double squareDistance(final double[] a, final double[] b) {
        assert rows(a) == rows(b);
        final int rows = rows(a);
        double squ_len = 0.0;
        for (int i = 0; i < rows; ++i)
            squ_len += (a[i] - b[i]) * (a[i] - b[i]);
        return squ_len;
    }

    public static int rows(final double[] a) {
        return a.length;
    }

    public static int rows(final double[][] A) {
        return A.length;
    }
}

Related

  1. squaredEuclideanDistance(double[] x, double[] y)
  2. squareDist31TileMetric(int x1, int y1, int x2, int y2)
  3. squareDistance(double pointAX, double pointAY, double pointBX, double pointBY)
  4. squareDistance(double x1, double y1, double x2, double y2)
  5. squaredistance(double[] v1, double[] v2)
  6. squareLength(final float x1, final float y1, final float z1, final float x2, final float y2, final float z2)
  7. squareSegmentDistance(float[] p, int a, int b, int c)