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

doubleCalcDistance(double lat1, double lon1, double lat2, double lon2)
Calculate the distance between two GPS points (without the elevation)
double a, c, dDistance, dLat1InRad, dLong1InRad, dLat2InRad, dLong2InRad, dLongitude, dLatitude;
double kEarthRadiusKms;
kEarthRadiusKms = 6378.14; 
dDistance = 0; 
dLat1InRad = lat1 * (Math.PI / 180.0);
dLong1InRad = lon1 * (Math.PI / 180.0);
dLat2InRad = lat2 * (Math.PI / 180.0);
dLong2InRad = lon2 * (Math.PI / 180.0);
...
doublecalcDistance(double lon1, double lat1, double lon2, double lat2)
calculates the distance in meters between two points in EPSG:4326 coodinates.
double r = 6378.137;
double rad = Math.PI / 180d;
double cose = Math.sin(rad * lon1) * Math.sin(rad * lon2)
        + Math.cos(rad * lon1) * Math.cos(rad * lon2) * Math.cos(rad * (lat1 - lat2));
double dist = r * Math.acos(cose) * Math.cos(rad * Math.min(lat1, lat2));
return dist * 1000 * 0.835;
intcalcDistance(final int coordinate1, final int coordinate2)
calc Distance
return Math.abs(coordinate1 - coordinate2);
intcalcDistance(int ax, int ay, int bx, int by)
calc Distance
int sum1 = bx - ax;
int sum2 = by - ay;
double square = (Math.pow(sum1, 2) + Math.pow(sum2, 2));
int distance = (int) Math.sqrt(square);
return distance;
intcalcDistance(int x1, int y1, int x2, int y2)
calc Distance
return (int) Math.ceil(Math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2));
doublecalcDistanceBetweenCoords(double startLat, double startLon, double endLat, double endLon)
Calculates the distance in meter between to coordinates.
if (startLat == endLat && startLon == endLon) {
    return 0;
return Math.acos(Math.sin(endLat / 180. * Math.PI) * Math.sin(startLat / 180. * Math.PI)
        + Math.cos(endLat / 180. * Math.PI) * Math.cos(startLat / 180. * Math.PI)
                * Math.cos(endLon / 180. * Math.PI - startLon / 180. * Math.PI))
        * 6380. 
        * 1000; 
...
doublecalcDistanceHubery(double lat1, double lng1, double lat2, double lng2, int type)
calc Distance Hubery
switch (type) {
case BESSEL:
    return calcDistOfHubeny(lat1, lng1, lat2, lng2, BESSEL_A, BESSEL_E2, BESSEL_MNUM);
case WGS84:
    return calcDistOfHubeny(lat1, lng1, lat2, lng2, WGS84_A, WGS84_E2, WGS84_MNUM);
case GRS80:
    return calcDistOfHubeny(lat1, lng1, lat2, lng2, GRS80_A, GRS80_E2, GRS80_MNUM);
default:
...
doublecalcDistanceIfAccel(double startVelocity, double accel, double targetVelocity, double duration)
Determine how far the Vehicle will go in the given duration, if it starts at the given starting velocity and accelerates at the given acceleration toward the provided target velocity.
if (accel >= 0.0) {
    if (startVelocity >= targetVelocity) {
        return startVelocity * duration;
    double maxChange = accel * duration;
    double requestedChange = targetVelocity - startVelocity;
    if (requestedChange >= maxChange) {
        return (startVelocity + (maxChange / 2.0)) * duration;
...
doublecalcDistanceToStop(double startingVelocity, double maxDeceleration)
Get the amount of distance it will take to stop, given a starting velocity.
return (-1.0) * startingVelocity * startingVelocity / (2.0 * maxDeceleration);
doublecalculateDistance(double lat1, double lng1, double lat2, double lng2)
calculate Distance
double earthRadius = 6371393.0;
double dLat = Math.toRadians(lat2 - lat1);
double dLng = Math.toRadians(lng2 - lng1);
double sindLat = Math.sin(dLat / 2);
double sindLng = Math.sin(dLng / 2);
double a = Math.pow(sindLat, 2)
        + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
...