http://www.movable-type.co.uk/scripts/gis-faq-5.1.html

/**
   *
   * @param lat1     The y coordinate of the first point, in radians
   * @param lon1     The x coordinate of the first point, in radians
   * @param lat2     The y coordinate of the second point, in radians
   * @param lon2     The x coordinate of the second point, in radians
   * @return The distance between the two points, as determined by the Haversine formula, in radians.
   */
  public static double distHaversineRAD(double lat1, double lon1, double lat2, double lon2) {
    //TODO investigate slightly different formula using asin() and min() http://www.movable-type.co.uk/scripts/gis-faq-5.1.html

    // Check for same position
    if (lat1 == lat2 && lon1 == lon2)
      return 0.0;
    double hsinX = Math.sin((lon1 - lon2) * 0.5);
    double hsinY = Math.sin((lat1 - lat2) * 0.5);
    double h = hsinY * hsinY +
            (Math.cos(lat1) * Math.cos(lat2) * hsinX * hsinX);
    return 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h));
  }

  

相关文章:

  • 2021-12-15
  • 2022-01-01
  • 2021-12-06
  • 2022-12-23
  • 2022-01-09
  • 2022-01-23
  • 2021-04-25
  • 2021-05-23
猜你喜欢
  • 2021-12-21
  • 2021-06-24
  • 2021-08-15
  • 2021-12-02
  • 2021-07-28
  • 2021-07-17
  • 2022-12-23
相关资源
相似解决方案