Welcome to mirror list, hosted at ThFree Co, Russian Federation.

distance_on_sphere.hpp « geometry - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: efba329e3d4ebae6833f963228a98fe7b0ea5825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "base/base.hpp"
#include "geometry/latlon.hpp"

// namespace ms - "math on sphere", similar to the namespaces m2 and mn.
namespace ms
{

// Earth radius in meters.
inline double EarthRadiusMeters() { return 6378000; }
// Length of one degree square at the equator in meters.
inline double OneDegreeEquatorLengthMeters() { return 111319.49079; }

// Distance on unit sphere between (lat1, lon1) and (lat2, lon2).
// lat1, lat2, lon1, lon2 - in degrees.
double DistanceOnSphere(double lat1Deg, double lon1Deg, double lat2Deg, double lon2Deg);

// Area on unit sphere for a triangle (ll1, ll2, ll3).
double AreaOnSphere(LatLon const & ll1, LatLon const & ll2, LatLon const & ll3);

// Distance in meteres on Earth between (lat1, lon1) and (lat2, lon2).
// lat1, lat2, lon1, lon2 - in degrees.
inline double DistanceOnEarth(double lat1Deg, double lon1Deg, double lat2Deg, double lon2Deg)
{
  return EarthRadiusMeters() * DistanceOnSphere(lat1Deg, lon1Deg, lat2Deg, lon2Deg);
}

inline double DistanceOnEarth(LatLon const & ll1, LatLon const & ll2)
{
  return DistanceOnEarth(ll1.lat, ll1.lon, ll2.lat, ll2.lon);
}

inline double AreaOnEarth(LatLon const & ll1, LatLon const & ll2, LatLon const & ll3)
{
  return OneDegreeEquatorLengthMeters() * OneDegreeEquatorLengthMeters() * AreaOnSphere(ll1, ll2, ll3);
}

}  // namespace ms