Java Distance Calculate distSquared(float x0, float y0, float x1, float y1)

Here you can find the source of distSquared(float x0, float y0, float x1, float y1)

Description

finds squared distance between two points

License

Open Source License

Parameter

Parameter Description
x0 x-coordinate of first point
y0 y-coordinate of first point
x1 x-coordinate of second point
y1 y-coordinate of second point

Return

squared distance between points

Declaration

public static float distSquared(float x0, float y0, float x1, float y1) 

Method Source Code

//package com.java2s;
/*//from  ww w  .j  a va 2 s. c  o m
 * Copyright (c) 2011, Paul Hertz This library is free software; you can
 * redistribute it and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation; either version
 * 3.0 of the License, or (at your option) any later version.
 * http://www.gnu.org/licenses/lgpl.html This library 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 Lesser General Public License for more details. You should have
 * received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301, USA
 * 
 * @author      ##author##
 * @modified   ##date##
 * @version      ##version##
 * 
 */

public class Main {
    /**
     * finds squared distance between two points
     * @param x0   x-coordinate of first point
     * @param y0   y-coordinate of first point
     * @param x1   x-coordinate of second point
     * @param y1   y-coordinate of second point
     * @return     squared distance between points
     */
    public static float distSquared(float x0, float y0, float x1, float y1) {
        return (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
    }

    /**
     * finds squared distance between two points
     * @param x0   x-coordinate of first point
     * @param y0   y-coordinate of first point
     * @param x1   x-coordinate of second point
     * @param y1   y-coordinate of second point
     * @return     squared distance between points
     */
    public static double distSquared(double x0, double y0, double x1, double y1) {
        return (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
    }
}

Related

  1. distSphericalEarth(double lat1, double lon1, double lat2, double lon2)
  2. distSq(double x1, double y1, double x2, double y2)
  3. distSq(double x1, double y1, double z1, double x2, double y2, double z2)
  4. distSqr2(double x1, double y1, double x2, double y2)
  5. distSquared(double ax, double ay, double bx, double by)
  6. distSquaredCartesian(double[] vec1, double[] vec2)
  7. distSquareVec3(final float[] v1, final float[] v2)
  8. distSymbol(int dist)
  9. distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)