Java Utililty Methods Distance Calculate

List of utility methods to do Distance Calculate

Description

The list of methods to do Distance Calculate are organized into topic(s).

Method

floatdistance(float x1, float y1, float x2, float y2)
2D distance formula.
double xdiff = x2 - x1;
double ydiff = y2 - y1;
return (float) Math.sqrt((xdiff * xdiff + ydiff * ydiff));
floatdistance(float x1, float y1, float x2, float y2)
Returns the distance between two points.
float v1 = Math.abs(x1 - x2);
float v2 = Math.abs(y1 - y2);
return (float) Math.sqrt((v1 * v1) + (v2 * v2));
floatdistance(float x1, float y1, float x2, float y2)
distance
return (float) Math.sqrt((float) Math.pow((x2 - x1), 2.0) + (float) Math.pow((y2 - y1), 2.0));
floatdistance(float[] p1, float[] p2)
distance
return (float) Math.sqrt(squareDistance(p1, p2));
doubledistance(float[] values1, float[] values2)
distance
if (values1 != null && values2 != null) {
    if (values1.length == values2.length) {
        float sum = 0;
        for (int i = 0; i < values1.length; i++) {
            sum += (values2[i] - values1[i]) * (values2[i] - values1[i]);
        return Math.sqrt(sum);
return -1;
doubledistance(int ax, int ay, int bx, int by)
distance
int length_A = 0;
int length_B = 0;
if (bx > ax) {
    length_A = bx - ax;
} else {
    length_A = ax - bx;
if (by > ay) {
...
intdistance(int first, int second)
distance
return NumberOfSetBits(first ^ second);
doubledistance(int fx, int fy, int sx, int sy)
distance
final int dx = sx - fx;
final int dy = sy - fy;
return Math.sqrt(dx * dx + dy * dy);
Stringdistance(int one, int two)
distance
if (one > two) {
    return (one - two) + "px below";
} else {
    return (two - one) + "px above";
doubledistance(int px, int py, int x1, int y1, int x2, int y2)
Calculates the distance between a point and a line segment.
double length2 = distance2(x1, y1, x2, y2);
if (length2 == 0) {
    return Math.sqrt(distance2(px, py, x1, y1));
double r = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / length2;
if (r <= 0.0) {
    return Math.sqrt(distance2(px, py, x1, y1));
if (r >= 1.0) {
    return Math.sqrt(distance2(px, py, x2, y2));
int x = (int) (x1 + r * (x2 - x1));
int y = (int) (y1 + r * (y2 - y1));
return Math.sqrt(distance2(px, py, x, y));