Java Distance Calculate distanceBetween2Points(float p1[], float p2[])

Here you can find the source of distanceBetween2Points(float p1[], float p2[])

Description

Calc distance between 2 points in space

License

Open Source License

Parameter

Parameter Description
p1 a parameter
p2 a parameter

Declaration

public static float distanceBetween2Points(float p1[], float p2[]) 

Method Source Code

//package com.java2s;
/*//w  ww  .  ja v  a  2s .c o  m
 * Copyright (c) 2004-2015 Universidade do Porto - Faculdade de Engenharia
 * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS)
 * All rights reserved.
 * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
 *
 * This file is part of Neptus, Command and Control Framework.
 *
 * Commercial Licence Usage
 * Licencees holding valid commercial Neptus licences may use this file
 * in accordance with the commercial licence agreement provided with the
 * Software or, alternatively, in accordance with the terms contained in a
 * written agreement between you and Universidade do Porto. For licensing
 * terms, conditions, and further information contact lsts@fe.up.pt.
 *
 * European Union Public Licence - EUPL v.1.1 Usage
 * Alternatively, this file may be used under the terms of the EUPL,
 * Version 1.1 only (the "Licence"), appearing in the file LICENSE.md
 * included in the packaging of this file. You may not use this work
 * except in compliance with the Licence. Unless required by applicable
 * law or agreed to in writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the Licence for the specific
 * language governing permissions and limitations at
 * https://www.lsts.pt/neptus/licence.
 *
 * For more information please see <http://lsts.fe.up.pt/neptus>.
 *
 * Author: hfq
 * Jun 21, 2013
 */

public class Main {
    /**
     * Calc distance between 2 points in space
     * @param p1
     * @param p2
     * @return
     */
    public static float distanceBetween2Points(float p1[], float p2[]) {
        return (float) (Math.sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1])
                + (p1[2] - p2[2]) * (p1[2] - p2[2])));

    }

    /**
     * Calc distance between 2 points in space
     * @param p1
     * @param p2
     * @return
     */
    public static double distanceBetween2Points(double[] p1, double[] p2) {
        return (Math.sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1])
                + (p1[2] - p2[2]) * (p1[2] - p2[2])));
    }
}

Related

  1. distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude)
  2. distanceBetween(double x1, double y1, double x2, double y2)
  3. distanceBetween(double x1, double y1, double x2, double y2)
  4. distanceBetween(double xpos1, double ypos1, double xpos2, double ypos2)
  5. distanceBetween2GeoPositionsInMeters(double latA, double lngA, double latB, double lngB)
  6. distanceBetween2Points(float vectorX0, float vectorY0, float vectorXP, float vectorYP)
  7. distanceBetweenPoints(double ax, double ay, double bx, double by)
  8. DistanceBetweenPoints(double x1, double y1, double x2, double y2)
  9. distanceBetweenPoints(float vx, float vy, float wx, float wy)