Java Distance Calculate distance(double x0, double y0, double z0, double x1, double y1, double z1)

Here you can find the source of distance(double x0, double y0, double z0, double x1, double y1, double z1)

Description

distance

License

MIT License

Declaration

public static double distance(double x0, double y0, double z0, double x1, double y1, double z1) 

Method Source Code

//package com.java2s;
/**//from w w w. j  a  va  2  s. c  o  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 distance(double x0, double y0, double z0, double x1, double y1, double z1) {
        return Math.sqrt(distanceSq(x0, y0, z0, x1, y1, z1));
    }

    public static double distance(double[] vec1, double[] vec2) {
        return Math.sqrt(distanceSq(vec1, vec2));
    }

    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. distance(double lon1, double lat1, double lon2, double lat2)
  2. distance(double u, double v, double pu, double pv)
  3. distance(double w1, double h1, double w2, double h2, int type)
  4. distance(double x, double y, double xx, double yy)
  5. distance(double x0, double y0, double x1, double y1)
  6. distance(double x1, double y1, double x2, double y2)
  7. distance(double x1, double y1, double x2, double y2)
  8. distance(double x1, double y1, double x2, double y2)
  9. distance(double x1, double y1, double z1, double x2, double y2, double z2)