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

intdistance(int q1, int r1, int q2, int r2)
Distance between two hexes.
int x1 = q1;
int z1 = r1;
int x2 = q2;
int z2 = r2;
int y1 = -(x1 + z1);
int y2 = -(x2 + z2);
return (Math.abs(x1 - x2) + Math.abs(y1 - y2) + Math.abs(z1 - z2)) / 2;
intdistance(int x, int y, int targetX, int targetY, int minDist, int[] outCoords)
Calculates the distance between real position and a specific point in the grid
int distance = minDist;
if (targetX >= 0 && targetX < 8 && targetY >= 0 && targetY < 13) {
    int dx = (targetX << 5) - ((targetY % 2) << 4) - x;
    int dy = targetY * 28 - y;
    distance = dx * dx + dy * dy;
    if (distance < minDist) {
        outCoords[0] = targetX;
        outCoords[1] = targetY;
...
doubleDistance(int X1, int X2, int Y1, int Y2)
Distance
return Math.sqrt(Exp2(X1 - X2) + Exp2(Y1 - Y2));
doubledistance(int x1, int y1, int x2, int y2)
Calculate the distance between two 2D points.
double dx = x1 - x2;
double dy = y1 - y2;
return Math.sqrt(dx * dx + dy * dy);
intdistance(int x1, int y1, int x2, int y2)
distance
int x = x1 - x2;
int y = y1 - y2;
double d = Math.sqrt(x * x + y * y);
return (int) Math.round(d);
floatdistance(int x1, int y1, int x2, int y2)
distance
return (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
doubledistance(int xa, int ya, int xb, int yb)
distance
return Math.sqrt(distanceSquared(xa, ya, xb, yb));
doubledistance(int[] a, int[] b)
distance
double d = 0;
if (b == null || b.length != a.length)
    throw new RuntimeException("Wa?" + a.length + "\t" + b.length);
for (int i = 0; i < a.length; i++) {
    d += (a[i] - b[i]) * (a[i] - b[i]);
return Math.sqrt(d);
intdistance(String a, String b)
distance
a = a.toLowerCase();
a = a.replaceAll("[^a-zA-Z0-9]", "");
b = b.toLowerCase();
b = b.replaceAll("[^a-zA-Z0-9]", "");
int[] costs = new int[b.length() + 1];
for (int j = 0; j < costs.length; j++) {
    costs[j] = j;
for (int i = 1; i <= a.length(); i++) {
    costs[0] = i;
    int nw = i - 1;
    for (int j = 1; j <= b.length(); j++) {
        int cj = Math.min(1 + Math.min(costs[j], costs[j - 1]),
                a.charAt(i - 1) == b.charAt(j - 1) ? nw : nw + 1);
        nw = costs[j];
        costs[j] = cj;
return costs[b.length()];
doubledistance(String coord1, String coord2, char unit)
distance
String c1[] = coord1.split(",");
String c2[] = coord2.split(",");
return distance(Double.parseDouble(c1[0]), Double.parseDouble(c1[1]), Double.parseDouble(c2[0]),
        Double.parseDouble(c2[1]), unit);