1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/common/coordinates.cpp

22 lines
593 B
C++
Raw Normal View History

#include "wgs84.h"
#include "coordinates.h"
double Coordinates::distanceTo(const Coordinates &c) const
{
double dLat = deg2rad(c.lat() - _lat);
double dLon = deg2rad(c.lon() - _lon);
double a = pow(sin(dLat / 2.0), 2.0)
+ cos(deg2rad(_lat)) * cos(deg2rad(c.lat())) * pow(sin(dLon / 2.0), 2.0);
return (WGS84_RADIUS * (2.0 * atan2(sqrt(a), sqrt(1.0 - a))));
}
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const Coordinates &c)
{
dbg.nospace() << qSetRealNumberPrecision(10) << "Coordinates(" << c.lon()
<< ", " << c.lat() << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG