Here you can find the source of distance(final double x1, final double y1, final double x2, final double y2)
Parameter | Description |
---|---|
x1 | The first x coordinate. |
y1 | The first y coordinate. |
x2 | The second x coordinate. |
y2 | The second y coordinate. |
static double distance(final double x1, final double y1, final double x2, final double y2)
//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; } }