Class DistanceCalcEarth

java.lang.Object
com.graphhopper.util.DistanceCalcEarth
All Implemented Interfaces:
DistanceCalc
Direct Known Subclasses:
DistanceCalc3D, DistanceCalcEuclidean, DistancePlaneProjection

public class DistanceCalcEarth extends Object implements DistanceCalc
Author:
Peter Karich
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Circumference of the earth
    static final DistanceCalcEarth
     
    static final double
     
    static final double
     
    static final double
    mean radius of the earth
    static final double
    Radius of the earth at equator
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    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
     
    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 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
    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)
    This method calculates the distance from r to edge (a, b) where the crossing point is c including elevation
    createBBox(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).
     
    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).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • 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 interface DistanceCalc
    • 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 interface DistanceCalc
    • calcDenormalizedDist

      public double calcDenormalizedDist(double normedDist)
      Description copied from interface: DistanceCalc
      Inverse to calcNormalizedDist. Returned the length in meter.
      Specified by:
      calcDenormalizedDist in interface DistanceCalc
    • calcNormalizedDist

      public double calcNormalizedDist(double dist)
      Returns the specified length in normalized meter.
      Specified by:
      calcNormalizedDist in interface DistanceCalc
    • 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 interface DistanceCalc
    • calcCircumference

      public double calcCircumference(double lat)
      Circumference of the earth at different latitudes (breitengrad)
      Specified by:
      calcCircumference in interface DistanceCalc
    • isDateLineCrossOver

      public boolean isDateLineCrossOver(double lon1, double lon2)
    • createBBox

      public BBox createBBox(double lat, double lon, double radiusInMeter)
      Specified by:
      createBBox in interface DistanceCalc
    • 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 interface DistanceCalc
      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 interface DistanceCalc
      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 interface DistanceCalc
      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 interface DistanceCalc
      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 interface DistanceCalc
    • intermediatePoint

      public GHPoint intermediatePoint(double f, double lat1, double lon1, double lat2, double lon2)
      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 interface DistanceCalc
    • calcDistance

      public double calcDistance(PointList pointList)
      Specified by:
      calcDistance in interface DistanceCalc
    • calcDistance

      public static double calcDistance(PointList pointList, boolean is3d)
    • isCrossBoundary

      public boolean isCrossBoundary(double lon1, double lon2)
      Specified by:
      isCrossBoundary in interface DistanceCalc
    • hasElevationDiff

      protected boolean hasElevationDiff(double a, double b)
    • toString

      public String toString()
      Overrides:
      toString in class Object