Here you can find the source of distance2(int x1, int y1, int x2, int y2)
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 |
public static double distance2(int x1, int y1, int x2, int y2)
//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; } }