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

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

Description

Calculate the distance between two coordinates.

License

Apache License

Parameter

Parameter Description
x1 The first x coordinate.
y1 The first y coordinate.
x2 The second x coordinate.
y2 The second y coordinate.

Return

The distance.

Declaration

static double distance(final double x1, final double y1, final double x2, final double y2) 

Method Source Code

//package com.java2s;
/*/* w  ww.j av a  2s  . c om*/
 * Copyright 2004-2005 Revolution Systems Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Calculate the distance between two coordinates.
     *
     * @param x1 The first x coordinate.
     * @param y1 The first y coordinate.
     * @param x2 The second x coordinate.
     * @param y2 The second y coordinate.
     * @return The distance.
     */
    static double distance(final double x1, final double y1, final double x2, final double y2) {
        final double dx = x2 - x1;
        final double dy = y2 - y1;

        final double distance = Math.sqrt(dx * dx + dy * dy);
        return distance;
    }
}

Related

  1. distance(double[] p1, double[] p2)
  2. distance(double[] p1, double[] p2)
  3. distance(double[] x, int p, int q, int dim)
  4. distance(final Class child, final Class parent)
  5. distance(final double x, final double y)
  6. distance(final double x1, final double y1, final double x2, final double y2)
  7. distance(final double[] a, final double[] b)
  8. Distance(final double[] minCorner, final double[] maxCorner)
  9. distance(final double[] p, final double[] q)