Files
comaps/geometry/distance_on_sphere.cpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

30 lines
908 B
C++

#include "geometry/distance_on_sphere.hpp"
#include "base/math.hpp"
#include <algorithm>
#include <cmath>
namespace ms
{
double DistanceOnSphere(double lat1Deg, double lon1Deg, double lat2Deg, double lon2Deg)
{
double const lat1 = base::DegToRad(lat1Deg);
double const lat2 = base::DegToRad(lat2Deg);
double const dlat = sin((lat2 - lat1) * 0.5);
double const dlon = sin((base::DegToRad(lon2Deg) - base::DegToRad(lon1Deg)) * 0.5);
double const y = dlat * dlat + dlon * dlon * cos(lat1) * cos(lat2);
return 2.0 * atan2(sqrt(y), sqrt(std::max(0.0, 1.0 - y)));
}
double DistanceOnEarth(double lat1Deg, double lon1Deg, double lat2Deg, double lon2Deg)
{
return kEarthRadiusMeters * DistanceOnSphere(lat1Deg, lon1Deg, lat2Deg, lon2Deg);
}
double DistanceOnEarth(LatLon const & ll1, LatLon const & ll2)
{
return DistanceOnEarth(ll1.m_lat, ll1.m_lon, ll2.m_lat, ll2.m_lon);
}
} // namespace ms