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

doubledistPointSegmentSquared(double px, double py, double qx, double qy, double rx, double ry)
dist Point Segment Squared
double sx = px - qx;
double sy = py - qy;
double rScalar = dot(rx, ry, sx, sy) / dot(sx, sy, sx, sy);
if (rScalar <= 0) {
    return distSquared(px, py, qx, qy);
} else if (rScalar >= 1) {
    return distSquared(px, py, qx + rx, qy + ry);
return dot(sx, sy, sx, sy) - rScalar * rScalar * dot(rx, ry, rx, ry);
double[]distribution(int[] values)
distribution
return distribution(values, sum(values));
voiddistsimFeaturesException()
distsim Features Exception
System.err
        .println("You need to specify the DistSimFeatures in the parameters file to use the DistSimPath!");
System.exit(1);
doubledistSphericalEarth(double lat1, double lon1, double lat2, double lon2)
calc distance between two points, using spherical earth (ignoring ellipsoidal effects) calculation.
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
        * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = R * c;
return d * 1000;
doubledistSq(double x1, double y1, double x2, double y2)
dist Sq
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
doubledistSq(double x1, double y1, double z1, double x2, double y2, double z2)
dist Sq
return (sq(x2 - x1) + sq(y2 - y1) + sq(z2 - z1));
doubledistSqr2(double x1, double y1, double x2, double y2)
dist Sqr
x1 -= x2;
y1 -= y2;
return x1 * x1 + y1 * y1;
doubledistSquared(double ax, double ay, double bx, double by)
dist Squared
double dx = bx - ax;
double dy = by - ay;
return dx * dx + dy * dy;
floatdistSquared(float x0, float y0, float x1, float y1)
finds squared distance between two points
return (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
doubledistSquaredCartesian(double[] vec1, double[] vec2)
The square of the cartesian Distance.
double result = 0;
for (int i = 0; i < vec1.length; i++) {
    double v = vec1[i] - vec2[i];
    result += v * v;
return result;