Here you can find the source of distanceSquared(double x1, double y1, double x2, double y2)
Parameter | Description |
---|---|
x1 | The X coordinate of the first point. |
y1 | The Y coordinate of the first point. |
x2 | The X coordinate of the second point. |
y2 | The Y coordinate of the second point. |
public static double distanceSquared(double x1, double y1, double x2, double y2)
//package com.java2s; /*/*ww w . j a v a2s . c o m*/ * Copyright (C) 2014 Sina Ghaffari (sina.ghaffari@mail.utoronto.ca) & Tristan Homsi (thomsi@uwaterloo.ca) * * This file is part of Simple2D. * Simple2D is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Simple2D 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Simple2D. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Determines the non-squared distance between two hypothetical points. * * @param x1 The X coordinate of the first point. * @param y1 The Y coordinate of the first point. * @param x2 The X coordinate of the second point. * @param y2 The Y coordinate of the second point. * @return The non-squared distance between the first and second points. */ public static double distanceSquared(double x1, double y1, double x2, double y2) { return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); } }