Package com.graphhopper.util
Class DistanceCalcEarth
java.lang.Object
com.graphhopper.util.DistanceCalcEarth
- All Implemented Interfaces:
DistanceCalc
- Direct Known Subclasses:
DistanceCalc3D
,DistanceCalcEuclidean
,DistancePlaneProjection
- Author:
- Peter Karich
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Circumference of the earthstatic final DistanceCalcEarth
static final double
static final double
static final double
mean radius of the earthstatic final double
Radius of the earth at equator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
calcCircumference
(double lat) Circumference of the earth at different latitudes (breitengrad)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
calcDist3D
(double fromLat, double fromLon, double fromHeight, double toLat, double toLon, double toHeight) This implements a rather quick solution to calculate 3D distances on earth using euclidean geometry mixed with Haversine formula used for the on earth distance.double
calcDistance
(PointList pointList) static double
calcDistance
(PointList pointList, boolean is3d) double
calcNormalizedDist
(double dist) Returns the specified length in normalized meter.double
calcNormalizedDist
(double fromLat, double fromLon, double toLat, double toLon) Calculates in normalized meterdouble
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 cdouble
calcNormalizedEdgeDistance3D
(double r_lat_deg, double r_lon_deg, double r_ele_m, double a_lat_deg, double a_lon_deg, double a_ele_m, double b_lat_deg, double b_lon_deg, double b_ele_m) This method calculates the distance from r to edge (a, b) where the crossing point is c including elevationcreateBBox
(double lat, double lon, double radiusInMeter) protected boolean
hasElevationDiff
(double a, double b) intermediatePoint
(double f, double lat1, double lon1, double lat2, double lon2) This methods creates a point (lat, lon in degrees) a fraction of the distance along the path from (lat1, lon1) to (lat2, lon2).boolean
isCrossBoundary
(double lon1, double lon2) boolean
isDateLineCrossOver
(double lon1, double lon2) projectCoordinate
(double latInDeg, double lonInDeg, double distanceInMeter, double headingClockwiseFromNorth) This methods creates a point (lat, lon in degrees) in a certain distance and direction from the specified point (lat, lon in degrees).toString()
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).
-
Field Details
-
R
public static final double Rmean radius of the earth- See Also:
-
R_EQ
public static final double R_EQRadius of the earth at equator- See Also:
-
C
public static final double CCircumference of the earth- See Also:
-
KM_MILE
public static final double KM_MILE- See Also:
-
METERS_PER_DEGREE
public static final double METERS_PER_DEGREE- See Also:
-
DIST_EARTH
-
-
Constructor Details
-
DistanceCalcEarth
public DistanceCalcEarth()
-
-
Method Details
-
calcDist
public double calcDist(double fromLat, double fromLon, double toLat, double toLon) Calculates distance of (from, to) in meter.http://en.wikipedia.org/wiki/Haversine_formula a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2) c = 2.atan2(√a, √(1−a)) d = R.c
- Specified by:
calcDist
in interfaceDistanceCalc
-
calcDist3D
public double calcDist3D(double fromLat, double fromLon, double fromHeight, double toLat, double toLon, double toHeight) This implements a rather quick solution to calculate 3D distances on earth using euclidean geometry mixed with Haversine formula used for the on earth distance. The haversine formula makes not so much sense as it is only important for large distances where then the rather smallish heights would becomes negligible.- Specified by:
calcDist3D
in interfaceDistanceCalc
-
calcDenormalizedDist
public double calcDenormalizedDist(double normedDist) Description copied from interface:DistanceCalc
Inverse to calcNormalizedDist. Returned the length in meter.- Specified by:
calcDenormalizedDist
in interfaceDistanceCalc
-
calcNormalizedDist
public double calcNormalizedDist(double dist) Returns the specified length in normalized meter.- Specified by:
calcNormalizedDist
in interfaceDistanceCalc
-
calcNormalizedDist
public double calcNormalizedDist(double fromLat, double fromLon, double toLat, double toLon) Description copied from interface:DistanceCalc
Calculates in normalized meter- Specified by:
calcNormalizedDist
in interfaceDistanceCalc
-
calcCircumference
public double calcCircumference(double lat) Circumference of the earth at different latitudes (breitengrad)- Specified by:
calcCircumference
in interfaceDistanceCalc
-
isDateLineCrossOver
public boolean isDateLineCrossOver(double lon1, double lon2) -
createBBox
- Specified by:
createBBox
in interfaceDistanceCalc
-
calcNormalizedEdgeDistance
public 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) Description copied from interface:DistanceCalc
This method calculates the distance from r to edge (a, b) where the crossing point is c- Specified by:
calcNormalizedEdgeDistance
in interfaceDistanceCalc
- Returns:
- the distance in normalized meter
-
calcNormalizedEdgeDistance3D
public double calcNormalizedEdgeDistance3D(double r_lat_deg, double r_lon_deg, double r_ele_m, double a_lat_deg, double a_lon_deg, double a_ele_m, double b_lat_deg, double b_lon_deg, double b_ele_m) Description copied from interface:DistanceCalc
This method calculates the distance from r to edge (a, b) where the crossing point is c including elevation- Specified by:
calcNormalizedEdgeDistance3D
in interfaceDistanceCalc
- Returns:
- the distance in normalized meter
-
calcCrossingPointToEdge
public 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) - Specified by:
calcCrossingPointToEdge
in interfaceDistanceCalc
- Returns:
- the crossing point c of the vertical line from r to line (a, b)
-
validEdgeDistance
public 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) Description copied from interface:DistanceCalc
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
- Specified by:
validEdgeDistance
in interfaceDistanceCalc
- Returns:
- true for case 1 which is "on edge" or the special case of 90° to the edge
-
projectCoordinate
public GHPoint projectCoordinate(double latInDeg, double lonInDeg, double distanceInMeter, double headingClockwiseFromNorth) Description copied from interface:DistanceCalc
This methods creates a point (lat, lon in degrees) in a certain distance and direction from the specified point (lat, lon in degrees). The heading is measured clockwise from north in degrees. The distance is passed in meter.- Specified by:
projectCoordinate
in interfaceDistanceCalc
-
intermediatePoint
Description copied from interface:DistanceCalc
This methods creates a point (lat, lon in degrees) a fraction of the distance along the path from (lat1, lon1) to (lat2, lon2).- Specified by:
intermediatePoint
in interfaceDistanceCalc
-
calcDistance
- Specified by:
calcDistance
in interfaceDistanceCalc
-
calcDistance
-
isCrossBoundary
public boolean isCrossBoundary(double lon1, double lon2) - Specified by:
isCrossBoundary
in interfaceDistanceCalc
-
hasElevationDiff
protected boolean hasElevationDiff(double a, double b) -
toString
-