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

floatdistance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y)
distance_to_endpoint() - distance to closest endpoint
return (float) Math.min(distance(x1, y1, x, y), distance(x2, y2, x, y));
floatdistance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y)
Distance to closest endpoint.
return (float) Math.min(distance(x1, y1, x, y), distance(x2, y2, x, y));
doubledistance_to_line(double x1, double y1, double x2, double y2, double x3, double y3)
Computes the distance from a point to a line segment.
double x12 = x2 - x1;
double y12 = y2 - y1;
double x13 = x3 - x1;
double y13 = y3 - y1;
double D12 = Math.sqrt(x12 * x12 + y12 * y12);
double pp = (x12 * x13 + y12 * y13) / D12;
if (pp < 0.0) {
    return (float) Math.sqrt(x13 * x13 + y13 * y13);
...
intdistanceAbs(final int a, final int b)
distance Abs
return a > b ? a - b : b - a;
doubledistanceBase(double[] coord1, double[] coord2, int order)
Calculates the distance between two coordinates.
if (coord1.length != coord2.length)
    throw new IllegalArgumentException("Number of dimensions is not equal");
final int NUM_DIMENSIONS = coord1.length;
double distance = 0;
for (int d = 0; d < NUM_DIMENSIONS; d++) {
    double absDiff = Math.abs(coord2[d] - coord1[d]);
    distance += Math.pow(absDiff, order);
distance = Math.pow(distance, (1.0 / order));
;
return distance;
doubledistanceBetween(double latitude1, double longitude1, double latitude2, double longitude2)
distance Between
double distance = 0.0;
double deltaLat = Math.toRadians(latitude2 - latitude1);
double deltaLon = Math.toRadians(longitude2 - longitude1);
latitude1 = Math.toRadians(latitude1);
latitude2 = Math.toRadians(latitude2);
longitude1 = Math.toRadians(longitude1);
longitude2 = Math.toRadians(longitude2);
double earthRadius = 6371 * 1000;
...
doubledistanceBetween(double lon, double lat, double otherLon, double otherLat)
Returns the distance between two locations.
double lat1 = lat * Math.PI / 180.0;
double lat2 = otherLat * Math.PI / 180.0;
double lon1 = lon * Math.PI / 180.0;
double lon2 = otherLon * Math.PI / 180.0;
double dellat = Math.sin(0.5 * (lat2 - lat1));
dellat *= dellat;
double dellon = Math.sin(0.5 * (lon2 - lon1));
dellon *= dellon * Math.cos(lat1) * Math.cos(lat2);
...
floatdistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude)
distance Between
float[] results = new float[1];
distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, results);
return results[0];
doubledistanceBetween(double x1, double y1, double x2, double y2)
distance Between
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
doubledistanceBetween(double x1, double y1, double x2, double y2)
Calculates distance between the two points (x1,y1) and (x2,y2)
double delx = x2 - x1;
double dely = y2 - y1;
return Math.sqrt(delx * delx + dely * dely);