Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
38
libs/geometry/distance_on_sphere.cpp
Normal file
38
libs/geometry/distance_on_sphere.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#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 = math::DegToRad(lat1Deg);
|
||||
double const lat2 = math::DegToRad(lat2Deg);
|
||||
double const dlat = sin((lat2 - lat1) * 0.5);
|
||||
double const dlon = sin((math::DegToRad(lon2Deg) - math::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);
|
||||
}
|
||||
|
||||
m3::Point<double> ToVector(LatLon const & ll)
|
||||
{
|
||||
double const lat = math::DegToRad(ll.m_lat);
|
||||
double const lon = math::DegToRad(ll.m_lon);
|
||||
return {kEarthRadiusMeters * cos(lat) * cos(lon), kEarthRadiusMeters * cos(lat) * sin(lon),
|
||||
kEarthRadiusMeters * sin(lat)};
|
||||
}
|
||||
|
||||
} // namespace ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue