Java Distance Calculate calculateDistance(final double x1, final double y1, final double x2, final double y2)

Here you can find the source of calculateDistance(final double x1, final double y1, final double x2, final double y2)

Description

Calculates the distance between the given coordinates

License

Open Source License

Parameter

Parameter Description
x1 x coordinate of the first point
y1 y coordinate of the first point
x2 x coordinate of the second point
y2 y coordinate of the second point

Return

distance

Declaration

public static double calculateDistance(final double x1, final double y1, final double x2, final double y2) 

Method Source Code

//package com.java2s;
/*//from  w  w  w  . ja  v a2  s . c  om
 * USE - UML based specification environment
 * Copyright (C) 1999-2004 Mark Richters, University of Bremen
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

public class Main {
    /**
     * Calculates the distance between the given coordinates
     *
     * @param x1 x coordinate of the first point
     * @param y1 y coordinate of the first point
     * @param x2 x coordinate of the second point
     * @param y2 y coordinate of the second point
     * @return distance
     */
    public static double calculateDistance(final double x1, final double y1, final double x2, final double y2) {
        return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
    }
}

Related

  1. calcDistanceToStop(double startingVelocity, double maxDeceleration)
  2. calculateDistance(double lat1, double lng1, double lat2, double lng2)
  3. calculateDistance(Double lng1, Double lat1, Double lng2, Double lat2)
  4. calculateDistance(Double prevLat, Double prevLon, Double currentLat, Double currentLon)
  5. calculateDistance(double rssi, double txPower)
  6. calculateDistance(float[] vec1, float[] vec2)
  7. calculateDistance(int from, int to)
  8. calculateDistance(int x1, int y1, int z1, int x2, int y2, int z2)
  9. calculateDistance(String firstString, String secondString)