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

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

Description

Calculates the square of the distance between two points.

License

Open Source License

Parameter

Parameter Description
x1 x-coordinate of point 1
y1 y-coordinate of point 1
x2 x-coordinate of point 2
y2 y-coordinate of point 2

Return

the square of the distance in pixels^2

Declaration

public static double distance2(int x1, int y1, int x2, int y2) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2007, 2014 Intel Corporation, Ericsson
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  w w w  . ja v a 2 s . c o  m
 *     Intel Corporation - Initial API and implementation
 *     Ruslan A. Scherbakov, Intel - Initial API and implementation
 *     Alvaro Sanchez-Leon - Udpated for TMF
 *     Patrick Tasse - Refactoring
 *     Marc-Andre Laperle - Add time zone preference
 *****************************************************************************/

public class Main {
    /**
     * Calculates the square of the distance between two points.
     *
     * @param x1
     *            x-coordinate of point 1
     * @param y1
     *            y-coordinate of point 1
     * @param x2
     *            x-coordinate of point 2
     * @param y2
     *            y-coordinate of point 2
     *
     * @return the square of the distance in pixels^2
     */
    public static double distance2(int x1, int y1, int x2, int y2) {
        int dx = x2 - x1;
        int dy = y2 - y1;
        int d2 = dx * dx + dy * dy;
        return d2;
    }
}

Related

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