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

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

Description

distance

License

Apache License

Return

the squared distance between the two given points

Declaration

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

Method Source Code

//package com.java2s;
/** Copyright 2014 Robin Stumm (serverkorken@gmail.com, http://dermetfan.net)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. */

public class Main {
    /** @return the squared distance between the two given points
     *  @since 0.11.0 */// w ww . j  a v  a 2  s . c  om
    public static float distance2(float x1, float y1, float x2, float y2) {
        float x_dist = x2 - x1, y_dist = y2 - y1;
        return x_dist * x_dist + y_dist * y_dist;
    }
}

Related

  1. distance(int[] a, int[] b)
  2. distance(String a, String b)
  3. distance(String coord1, String coord2, char unit)
  4. distance(String seq1, String seq2)
  5. distance2(float x, float y, float x1, float y1)
  6. distance2(int x1, int y1, int x2, int y2)
  7. distance2d(double x1, double y1, double x2, double y2)
  8. distance2D(double x1, double z1, double x2, double z2)
  9. distance2points3D(double[] p1, double[] p2)