Java Distance Calculate distance(float x1, float y1, float x2, float y2)

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

Description

Returns the distance between two points.

License

Open Source License

Parameter

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

Return

the Euclidean distance between points (x1,y1) and (x2,y2)

Declaration

public static float distance(float x1, float y1, float x2, float y2) 

Method Source Code

//package com.java2s;
/*//  w ww .ja  v  a2  s.c o m
 * opsu! - an open-source osu! client
 * Copyright (C) 2014, 2015 Jeffrey Han
 *
 * opsu! 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 3 of the License, or
 * (at your option) any later version.
 *
 * opsu! 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 opsu!.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Returns the distance between two points.
     * @param x1 the x-component of the first point
     * @param y1 the y-component of the first point
     * @param x2 the x-component of the second point
     * @param y2 the y-component of the second point
     * @return the Euclidean distance between points (x1,y1) and (x2,y2)
     */
    public static float distance(float x1, float y1, float x2, float y2) {
        float v1 = Math.abs(x1 - x2);
        float v2 = Math.abs(y1 - y2);
        return (float) Math.sqrt((v1 * v1) + (v2 * v2));
    }
}

Related

  1. distance(float value1, float value2)
  2. distance(float value1, float value2)
  3. distance(float value1, float value2)
  4. distance(float x1, float x2, float y1, float y2)
  5. distance(float x1, float y1, float x2, float y2)
  6. distance(float x1, float y1, float x2, float y2)
  7. distance(float[] p1, float[] p2)
  8. distance(float[] values1, float[] values2)
  9. distance(int ax, int ay, int bx, int by)