com.graphhopper.util

## Interface DistanceCalc

• All Known Implementing Classes:
DistanceCalc2D, DistanceCalc3D, DistanceCalcEarth, DistancePlaneProjection

`public interface DistanceCalc`
Calculates the distance of two points or one point and an edge on earth via haversine formula. Allows subclasses to implement less or more precise calculations.

See http://en.wikipedia.org/wiki/Haversine_formula

Author:
Peter Karich
• ### Method Summary

All Methods
Modifier and TypeMethod and Description
`double``calcCircumference(double lat)`
`GHPoint``calcCrossingPointToEdge(double r_lat_deg, double r_lon_deg, double a_lat_deg, double a_lon_deg, double b_lat_deg, double b_lon_deg)`
`double``calcDenormalizedDist(double normedDist)`
Inverse to calcNormalizedDist.
`double``calcDist(double fromLat, double fromLon, double toLat, double toLon)`
Calculates distance of (from, to) in meter.
`double``calcNormalizedDist(double dist)`
Returns the specified length in normalized meter.
`double``calcNormalizedDist(double fromLat, double fromLon, double toLat, double toLon)`
Calculates in normalized meter
`double``calcNormalizedEdgeDistance(double r_lat_deg, double r_lon_deg, double a_lat_deg, double a_lon_deg, double b_lat_deg, double b_lon_deg)`
This method calculates the distance from r to edge (a, b) where the crossing point is c
`BBox``createBBox(double lat, double lon, double radiusInMeter)`
`boolean``isCrossBoundary(double lon1, double lon2)`
`GHPoint``projectCoordinate(double lat_deg, double lon_deg, double distanceInMeter, double headingClockwiseFromNorth)`
This methods projects a point given in lat and long (in degrees) into a direction, given as heading, measured clockwise from north in degrees.
`boolean``validEdgeDistance(double r_lat_deg, double r_lon_deg, double a_lat_deg, double a_lon_deg, double b_lat_deg, double b_lon_deg)`
This method decides for case 1: if we should use distance(r to edge) where r=(lat,lon) or case 2: min(distance(r to a), distance(r to b)) where edge=(a to b).
• ### Method Detail

• #### createBBox

`BBox createBBox(double lat,                double lon,                double radiusInMeter)`
• #### calcCircumference

`double calcCircumference(double lat)`
• #### calcDist

`double calcDist(double fromLat,                double fromLon,                double toLat,                double toLon)`
Calculates distance of (from, to) in meter.
• #### calcNormalizedDist

`double calcNormalizedDist(double dist)`
Returns the specified length in normalized meter.
• #### calcDenormalizedDist

`double calcDenormalizedDist(double normedDist)`
Inverse to calcNormalizedDist. Returned the length in meter.
• #### calcNormalizedDist

`double calcNormalizedDist(double fromLat,                          double fromLon,                          double toLat,                          double toLon)`
Calculates in normalized meter
• #### validEdgeDistance

`boolean validEdgeDistance(double r_lat_deg,                          double r_lon_deg,                          double a_lat_deg,                          double a_lon_deg,                          double b_lat_deg,                          double b_lon_deg)`
This method decides for case 1: if we should use distance(r to edge) where r=(lat,lon) or case 2: min(distance(r to a), distance(r to b)) where edge=(a to b). Note that due to rounding errors it cannot properly detect if it is case 1 or 90??.
` case 1 (including ):   r  . a-------b `
` case 2: r  .    a-------b `
Returns:
true for case 1 which is "on edge" or the special case of 90?? to the edge
• #### calcNormalizedEdgeDistance

`double calcNormalizedEdgeDistance(double r_lat_deg,                                  double r_lon_deg,                                  double a_lat_deg,                                  double a_lon_deg,                                  double b_lat_deg,                                  double b_lon_deg)`
This method calculates the distance from r to edge (a, b) where the crossing point is c
Returns:
the distance in normalized meter
• #### calcCrossingPointToEdge

`GHPoint calcCrossingPointToEdge(double r_lat_deg,                                double r_lon_deg,                                double a_lat_deg,                                double a_lon_deg,                                double b_lat_deg,                                double b_lon_deg)`
Returns:
the crossing point c of the vertical line from r to line (a, b)
• #### projectCoordinate

`GHPoint projectCoordinate(double lat_deg,                          double lon_deg,                          double distanceInMeter,                          double headingClockwiseFromNorth)`
This methods projects a point given in lat and long (in degrees) into a direction, given as heading, measured clockwise from north in degrees. The distance is passed in km.
• #### isCrossBoundary

`boolean isCrossBoundary(double lon1,                        double lon2)`