Here you can find the source of distance(float x1, float y1, float x2, float y2)
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 |
public static float distance(float x1, float y1, float x2, float y2)
//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)); } }