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

floatdistSquareVec3(final float[] v1, final float[] v2)
Return the squared distance between the given two points described vector v1 and v2.
final float dx = v1[0] - v2[0];
final float dy = v1[1] - v2[1];
final float dz = v1[2] - v2[2];
return dx * dx + dy * dy + dz * dz;
intdistSymbol(int dist)
dist Symbol
if (dist < 193) {
    if (dist < 13) { 
        if (dist < 5) {
            return dist - 1;
        } else if (dist < 7) {
            return 4;
        } else if (dist < 9) {
            return 5;
...
doubledistToRectNode(double[] point, double[] nodeCenter, double nodeRadius)
Calculates distance to the edge of a node.
double dist = 0;
for (int i = 0; i < point.length; i++) {
    double d = 0;
    if (point[i] > nodeCenter[i] + nodeRadius) {
        d = point[i] - (nodeCenter[i] + nodeRadius);
    } else if (point[i] < nodeCenter[i] - nodeRadius) {
        d = nodeCenter[i] - nodeRadius - point[i];
    dist += d * d;
return Math.sqrt(dist);
doubledistUndermod(double a, double b, double mod)
dist Undermod
if (mod < 0) {
    throw new IllegalArgumentException("mod must be positive");
double diff_x = a - b;
double diff_y = b - a;
diff_x = diff_x % mod;
diff_y = diff_y % mod;
if (diff_x < 0) {
...
doubledistVector(double[] vector1, double[] vector2)
dist Vector
int dim = vector1.length;
double sum = 0;
for (int n = 0; n < dim; n++) {
    sum += (vector1[n] - vector2[n]) * (vector1[n] - vector2[n]);
return Math.sqrt(sum);
doubledistVincentyRAD(double lat1, double lon1, double lat2, double lon2)
Calculates the great circle distance using the Vincenty Formula, simplified for a spherical model.
if (lat1 == lat2 && lon1 == lon2)
    return 0.0;
double cosLat1 = Math.cos(lat1);
double cosLat2 = Math.cos(lat2);
double sinLat1 = Math.sin(lat1);
double sinLat2 = Math.sin(lat2);
double dLon = lon2 - lon1;
double cosDLon = Math.cos(dLon);
...
doublegetDistance(double lat1, double lng1, double lat2, double lng2)
get Distance
double radLat1 = rad(lat1);
double radLat2 = rad(lat2);
double a = radLat1 - radLat2;
double b = rad(lng1) - rad(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
        + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
DecimalFormat df = new DecimalFormat("#.000");
...
floatsqrDistance(float x1, float y1, float x2, float y2)
sqr Distance
float dx = x1 - x2;
float dy = y1 - y2;
return dx * dx + dy * dy;
floatsquaredDistance(float[] p, int a, int b)
squared Distance
return (p[a] - p[b]) * (p[a] - p[b]) + (p[a + 1] - p[b + 1]) * (p[a + 1] - p[b + 1]);
doublesquaredEuclideanDistance(double[] x, double[] y)
Compute the squared euclidean distance between two doubles arrays
double dist = 0;
double diff;
for (int i = 0; i < x.length; i++) {
    diff = x[i] - y[i];
    dist += diff * diff;
return dist;