GPS Library  0.1
GPS driver and NMEA parser
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
Pos3DRaw.cpp
Go to the documentation of this file.
1 #include "Pos3DRaw.h"
2 #include <math.h>
3 
4 using namespace GPS;
5 
13 double Pos3Draw::Distance(const Pos3Draw & other) const
14 {
15  static const double Diameter = 12742000; // Earth diameter, in meters
16  double d_lat = sin(0.5 * (GetLatitude().toRadian() - other.GetLatitude().toRadian()));
17  double d_lon = sin(0.5 * (GetLongitude().toRadian() - other.GetLongitude().toRadian()));
18  double multiplier = cos(GetLatitude().toRadian()) * cos(other.GetLatitude().toRadian());
19  double a = d_lat * d_lat + multiplier * d_lon * d_lon;
20  return Diameter * atan2(sqrt(a), sqrt(1.0-a));
21 }
22 
23 std::ostream & operator<<(std::ostream & os, const GPS::Pos3Draw & pos)
24 {
25  return os << "lat=" << pos.GetLatitude() << ", lon=" << pos.GetLongitude() << ", alt=" << pos.GetAltitude();
26 }
27 
28 /* * * * * * * * * * * * * End - of - File * * * * * * * * * * * * * * */