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