Java Distance Calculate distanceFromZero(int x, int y)

Here you can find the source of distanceFromZero(int x, int y)

Description

Calculate the distance between two 2D points.

License

Open Source License

Parameter

Parameter Description
x X coordinate of second point.
y Y coordinate of second point.

Return

Distance between the two points.

Declaration

public static double distanceFromZero(int x, int y) 

Method Source Code

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

public class Main {
    /**//from   www .  j  a  v a 2  s  .  co  m
     * Calculate the distance between two 2D points.
     * Note: For the x and y coordinate of the first point, zero is used.
     *
     * @param x X coordinate of second point.
     * @param y Y coordinate of second point.
     *
     * @return Distance between the two points.
     */
    public static double distanceFromZero(int x, int y) {
        return distance(0, 0, x, y);
    }

    /**
     * Calculate the distance between two 2D points.
     *
     * @param x1 X coordinate of first point.
     * @param y1 Y coordinate of first point.
     * @param x2 X coordinate of second point.
     * @param y2 Y coordinate of second point.
     *
     * @return Distance between the two points.
     */
    public static double distance(int x1, int y1, int x2, int y2) {
        double dx = x1 - x2;
        double dy = y1 - y2;
        return Math.sqrt(dx * dx + dy * dy);
    }
}

Related

  1. distanceDamerauLevenshtein(CharSequence source, CharSequence target)
  2. distanceFast(double lat1, double lon1, double lat2, double lon2)
  3. distanceFrom(double lat1, double long1, double lat2, double long2)
  4. DistanceFromLine(float cx, float cy, float ax, float ay, float bx, float by)
  5. distanceFromLineToPoint(double x1, double y1, double z1, double x2, double y2, double z2, double px, double py, double pz)
  6. distanceHaversine(Double lat1, Double lon1, Double lat2, Double lon2, String param)
  7. distanceInf(double[] p1, double[] p2)
  8. distanceInMeters(double lat1, double lon1, double lat2, double lon2)
  9. distanceInMetersBetween(final double lat1, final double lng1, final double lat2, final double lng2)