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

distance

License

Open Source License

Return

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;
/**************************************************************************************
 * util_tree/*ww w .  j a  v a 2  s .c  o m*/
 * Copyright (c) 2014-2017 National University of Colombia, https://github.com/remixlab
 * @author Jean Pierre Charalambos, http://otrolado.info/
 *
 * All rights reserved. Library that eases the creation of interactive
 * scenes, released under the terms of the GNU Public License v3.0
 * which is available at http://www.gnu.org/licenses/gpl.html
 **************************************************************************************/

public class Main {
    /**
     * @return Euclidean distance between points (x1,y1) and (x2,y2).
     */
    public static float distance(float x1, float y1, float x2, float y2) {
        return (float) Math.sqrt((float) Math.pow((x2 - x1), 2.0) + (float) Math.pow((y2 - y1), 2.0));
    }

    /**
     * @return Euclidean distance between points (x1,y1,z1) and (x2,y2,z2).
     */
    public static float distance(float x1, float y1, float z1, float x2, float y2, float z2) {
        return (float) Math.sqrt((float) Math.pow((x2 - x1), 2.0) + (float) Math.pow((y2 - y1), 2.0)
                + (float) Math.pow((z2 - z1), 2.0));
    }

    /**
     * @return Euclidean distance between points (x1,y1,z1,rx1,y1,rz1) and
     * (x2,y2,z2,rx2,y2,rz2).
     */
    public static float distance(float x1, float y1, float z1, float rx1, float ry1, float rz1, float x2, float y2,
            float z2, float rx2, float ry2, float rz2) {
        return (float) Math.sqrt((float) Math.pow((x2 - x1), 2.0) + (float) Math.pow((y2 - y1), 2.0)
                + (float) Math.pow((z2 - z1), 2.0) + (float) Math.pow((rx2 - rx1), 2.0)
                + (float) Math.pow((ry2 - ry1), 2.0) + (float) Math.pow((rz2 - rz1), 2.0));
    }
}

Related

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