Java Distance Calculate calculateDistance(int x1, int y1, int z1, int x2, int y2, int z2)

Here you can find the source of calculateDistance(int x1, int y1, int z1, int x2, int y2, int z2)

Description

This method calculated the distance between two points in 3D space

License

Open Source License

Parameter

Parameter Description
x1 X1
y1 Y1
z1 Z1
x2 X2
y2 Y2
z2 Z2

Return

The distance between the two points

Declaration

public static double calculateDistance(int x1, int y1, int z1, int x2, int y2, int z2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w ww  . j a va 2 s .c  o m*/
     * This method calculated the distance between two points in 3D space
     * @param x1 X1
     * @param y1 Y1
     * @param z1 Z1
     * @param x2 X2
     * @param y2 Y2
     * @param z2 Z2
     * @return The distance between the two points
     */
    public static double calculateDistance(int x1, int y1, int z1, int x2, int y2, int z2) {
        double x_distance = x1 - x2;
        double y_distance = y1 - y2;
        double z_distance = z1 - z2;

        double sum = x_distance * x_distance;
        sum += y_distance * y_distance;
        sum += z_distance * z_distance;

        return Math.sqrt(sum);
    }

    /**
     * This method calculated the distance between two points in 3D space
     * @param a1
     * @param b1
     * @param a2
     * @param b2
     * @return
     */
    public static double calculateDistance(int a1, int b1, int a2, int b2) {
        double a_distance = a1 - a2;
        double b_distance = b1 - b2;

        double sum = a_distance * a_distance;
        sum += b_distance * b_distance;

        return Math.sqrt(sum);
    }
}

Related

  1. calculateDistance(Double prevLat, Double prevLon, Double currentLat, Double currentLon)
  2. calculateDistance(double rssi, double txPower)
  3. calculateDistance(final double x1, final double y1, final double x2, final double y2)
  4. calculateDistance(float[] vec1, float[] vec2)
  5. calculateDistance(int from, int to)
  6. calculateDistance(String firstString, String secondString)
  7. calculateDistanceBetween(double sourceLatitude, double sourceLongitude, double destinationLatitude, double destinationLongitude)
  8. calculateDistanceInKm(double lat1, double lon1, double lat2, double lon2)
  9. calculateDistanceNoNormalization(float[] vec1, float[] vec2)