Java Distance Calculate distanceSq(double[] vec1, double[] vec2)

Here you can find the source of distanceSq(double[] vec1, double[] vec2)

Description

distance Sq

License

MIT License

Declaration

public static double distanceSq(double[] vec1, double[] vec2) 

Method Source Code

//package com.java2s;
/**// w ww . java 2 s  . co  m
* Copyright (c) Lambda Innovation, 2013-2016
* This file is part of LambdaLib modding library.
* https://github.com/LambdaInnovation/LambdaLib
* Licensed under MIT, see project root for more information.
*/

public class Main {
    public static double distanceSq(double[] vec1, double[] vec2) {
        if (vec1.length != vec2.length) {
            throw new RuntimeException("Inconsistent length");
        }

        double ret = 0.0;
        for (int i = 0; i < vec1.length; ++i) {
            double d = vec2[i] - vec1[i];
            ret += d * d;
        }

        return ret;
    }

    public static double distanceSq(double x0, double y0, double z0, double x1, double y1, double z1) {
        return distanceSq(new double[] { x0, y0, z0 }, new double[] { x1, y1, z1 });
    }
}

Related

  1. distancePointToPoint(final double x1, final double y1, final double x2, final double y2)
  2. distancePointToPoint(float x1, float y1, float x2, float y2)
  3. distances(double[][] arr, int[][] partners)
  4. distanceSq(double[] p1, double[] p2, double[] weights)
  5. distanceSQ(double[] pos1, double[] pos2)
  6. distanceSq(float x0, float y0, float x1, float y1)
  7. distanceSq(int x0, int y0, int x1, int y1)
  8. distanceSqr(final float[] a, final float[] b)
  9. DistanceSquareBetweenPoints(double x1, double y1, double x2, double y2)