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

DoublecomputeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2)
computes the APPROXIMATE distance between 2 points (lat/lon in DEGREES, not radians) forumula described here: http://www.meridianworlddata.com/Distance-Calculation.asp
double x = 69.1 * (lat2 - lat1);
double y = 53.0 * (lon2 - lon1) * Math.cos(lat1 / 57.3);
return Math.sqrt(x * x + y * y);
int[][]computeDistanceMap(int[][] image)
compute Distance Map
for (int y = 0; y < image.length; y++) {
    for (int x = 0; x < image[y].length; x++) {
        if (image[y][x] != 0) {
            image[y][x] = 0;
        } else {
            image[y][x] = image.length + image[y].length;
            if (y > 0)
                image[y][x] = Math.min(image[y][x], image[y - 1][x] + 1);
...
doublecomputeDistanceSqr(double t, double b1, double b2, double b3, double b4, double b5, double b6)
Computes the numerator of d^2 for a given value of t
double s = 2 * t / (1 + t * t);
double c = (1 - t * t) / (1 + t * t);
return b1 * s * s + b2 * c * c + b3 * s * c + b4 * s + b5 * c + b6;
doublecomputeDistanceUsingRadians(double lat1Radians, double lng1Radians, double lat2Radians, double lng2Radians)
Returns the distance in meters between ( lat1 , lng1 ) and ( lat2 , lng2 ).
final double dLat = lat2Radians - lat1Radians;
final double dLng = lng2Radians - lng1Radians;
final double a = haversin(dLat) + Math.cos(lat1Radians) * Math.cos(lat2Radians) * haversin(dLng);
return EARTH_RADIUS * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
doubledist(double lat1, double long1, double lat2, double long2)
distance between two coordinates in kilometers
final double d2r = Math.PI / 180.0;
final double dlong = (long2 - long1) * d2r;
final double dlat = (lat2 - lat1) * d2r;
final double a = Math.pow(Math.sin(dlat / 2.0), 2.0)
        + Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r) * Math.pow(Math.sin(dlong / 2.0), 2.0);
final double c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
final double d = 6367.0 * c;
return d;
...
doubledist(double x1, double y1, double z1, double x2, double y2, double z2)
dist
return sqrt(distSq(x1, y1, z1, x2, y2, z2));
doubledist(final double x0, final double y0, final double x1, final double y1)
Returns the distance between two points in a dual axis cartesian graph.
final double dx = Math.abs(x1 - x0);
final double dy = Math.abs(y1 - y0);
return (Math.sqrt((dx * dx) + (dy * dy)));
floatdist(float x1, float y1, float x2, float y2)
dist
return sqrt(sq(x2 - x1) + sq(y2 - y1));
floatdist(float x1, float y1, float x2, float y2)
dist
double x = x2 - x1;
double y = y2 - y1;
return (float) Math.sqrt((x * x) + (y * y));
floatdist(float x1, float y1, float x2, float y2)
dist
final float x = (x2 - x1);
final float y = (y2 - y1);
return (float) Math.sqrt(x * x + y * y);