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

LongcalculateDistance(Double lng1, Double lat1, Double lng2, Double lat2)
calculate 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;
return (long) s;
...
DoublecalculateDistance(Double prevLat, Double prevLon, Double currentLat, Double currentLon)
Calculated the distance between 2 points and returns the distance in meters
return distanceMeter(prevLat, prevLon, currentLat, currentLon);
DoublecalculateDistance(double rssi, double txPower)
calculate Distance
double ratio;
ratio = rssi * 1.0 / txPower;
if (ratio < 1.0) {
    return Math.pow(ratio, 10);
} else {
    double distance;
    distance = (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
    return distance;
...
doublecalculateDistance(final double x1, final double y1, final double x2, final double y2)
Calculates the distance between the given coordinates
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
floatcalculateDistance(float[] vec1, float[] vec2)
Calculates distance between 2 vectors
float distance = 0;
float abs1 = 0;
float abs2 = 0;
for (int i = 0; i < vec1.length; i++) {
    distance += vec1[i] * vec2[i];
    abs1 += vec1[i] * vec1[i];
    abs2 += vec2[i] * vec2[i];
if (abs1 != 0 && abs2 != 0) {
    distance /= (Math.sqrt(abs1) * Math.sqrt(abs2));
return distance;
intcalculateDistance(int from, int to)
calculate Distance
return Math.abs(from - to);
doublecalculateDistance(int x1, int y1, int z1, int x2, int y2, int z2)
This method calculated the distance between two points in 3D space
double x_distance = x1 - x2;
double y_distance = y1 - y2;
double z_distance = z1 - z2;
double sum = x_distance * x_distance;
sum += y_distance * y_distance;
sum += z_distance * z_distance;
return Math.sqrt(sum);
intcalculateDistance(String firstString, String secondString)
Calculate the edit distance between two strings.
firstString = firstString.toLowerCase();
secondString = secondString.toLowerCase();
int[] costs = new int[secondString.length() + 1];
for (int j = 0; j < costs.length; j++)
    costs[j] = j;
for (int i = 1; i <= firstString.length(); i++) {
    costs[0] = i;
    int nw = i - 1;
...
doublecalculateDistanceBetween(double sourceLatitude, double sourceLongitude, double destinationLatitude, double destinationLongitude)
calculate Distance Between
double sourceLatitudeRadians = sourceLatitude * DEGREES_TO_RADIANS;
double sourceLongitudeRadians = sourceLongitude * DEGREES_TO_RADIANS;
double destinationLatitudeRadians = destinationLatitude * DEGREES_TO_RADIANS;
double destinationLongitudeRadians = destinationLongitude * DEGREES_TO_RADIANS;
double deltaLatitude = destinationLatitudeRadians - sourceLatitudeRadians;
double deltaLongitude = destinationLongitudeRadians - sourceLongitudeRadians;
double a = Math.pow(Math.sin(deltaLatitude / 2.0), 2.0) + Math.cos(sourceLatitudeRadians)
        * Math.cos(destinationLatitudeRadians) * Math.pow(Math.sin(deltaLongitude / 2.0), 2.0);
...
doublecalculateDistanceInKm(double lat1, double lon1, double lat2, double lon2)
calculate Distance In Km
int R = 6371; 
double dLat = deg2rad(lat2 - lat1); 
double dLon = deg2rad(lon2 - lon1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
        + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(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;
...