Compute GPS distance
compute two { latitude, longitude, altitude } distance
#
– ellipsoidal distance
– spherical distance
– some online tools
ellipsoidal distance
- 1 both
latitude, longitude, altitude
to ECEF xyz
(WGS84, ENU / NED .. also ok) - 2 compute two 3D points distance
- see one implementation in c++
spherical distance
- NOTE { latitude, longitude } only and DEPRECATED
use haversine formula
Haversine
formula: a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
d = R ⋅ c
where φ is latitude, λ is longitude, R is earth’s radius
(mean radius = 6,371km);
note that angles need to be in radians to pass to trig functions!
- one implementation in c++
- default
er
:kEarthMeanRadius 6371008.771414999850094
- default
// DEPRECATED please use ellipsoidalDistance or lineDistance
double Wgs84::haversineDistance(
double const latitude,
double const longitude,
double const er) const
{
double const latitude1R = DegreeToRadian(this->llh(0));
double const longitude1R = DegreeToRadian(this->llh(1));
double const latitude2R = DegreeToRadian(latitude);
double const longitude2R = DegreeToRadian(longitude);
double const deltaLatitude = latitude2R - latitude1R;// in radians
double const deltaLongitude = longitude2R - longitude1R;// in radians
double const a = Square(::sin(deltaLatitude / 2))
+ (::cos(latitude1R) * ::cos(latitude2R) * Square(
::sin(deltaLongitude / 2)));
double const c = 2 * ::atan2(::sqrt(a), ::sqrt(1 - a));
return er * c;
}
some online tools
- https://en.wikipedia.org/wiki/Latitude#Length_of_a_degree_of_latitude
- https://en.wikipedia.org/wiki/Longitude#Length_of_a_degree_of_longitude
- http://ditu.amap.com/
- Latitude/Longitude Distance Calculator
- https://stevemorse.org/nearest/distance.php