All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LatLongAltitude.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "VectorMath.h"
6 #include <vector>
7 
8 namespace Eegeo
9 {
10  namespace Space
11  {
12  class LatLong
13  {
14  public:
15  LatLong(double latitudeInRadians, double longitudeInRadians)
16  : m_latitude(latitudeInRadians)
17  , m_longitude(longitudeInRadians)
18  {
19 
20  }
21 
22  inline double GetLatitude() const { return m_latitude; }
23  inline double GetLongitude() const { return m_longitude; }
24 
25  inline void SetLatitude(double latitude) { m_latitude = latitude; }
26  inline void SetLongitude(double longitude) { m_longitude = longitude; }
27 
28  inline double GetLatitudeInDegrees() const { return Eegeo::Math::Rad2Deg(m_latitude); }
29  inline double GetLongitudeInDegrees() const { return Eegeo::Math::Rad2Deg(m_longitude); }
30 
31  Eegeo::dv3 ToECEF() const;
32  double BearingToInRadians(double latitude, double longitude) const;
33  double BearingToNorthPole() const;
34 
35  static LatLong FromECEF(const Eegeo::dv3& world);
36  static LatLong FromDegrees(double latitudeInDegrees, double longitudeInDegrees);
37  static LatLong FromRadians(double latitudeInRadians, double longitudeInRadians);
38 
39  private:
40  double m_latitude;
41  double m_longitude;
42  };
43 
45  {
46  public:
47  LatLongAltitude(double latitudeInRadians, double longitudeInRadians, double altitudeInMetres)
48  : m_latLong(latitudeInRadians, longitudeInRadians)
49  , m_altitude(altitudeInMetres)
50  {
51 
52  }
53 
54  inline LatLong GetLatLong() const { return m_latLong; }
55 
56  inline double GetAltitude() const { return m_altitude; }
57  inline void SetAltitude(double altitude) { m_altitude = altitude; }
58 
59  inline double GetLatitude() const { return m_latLong.GetLatitude(); }
60  inline double GetLongitude() const { return m_latLong.GetLongitude(); }
61 
62  inline void SetLatitude(double latitude) { m_latLong.SetLatitude(latitude); }
63  inline void SetLongitude(double longitude) { m_latLong.SetLongitude(longitude); }
64 
65  inline double GetLatitudeInDegrees() const { return m_latLong.GetLatitudeInDegrees(); }
66  inline double GetLongitudeInDegrees() const { return m_latLong.GetLongitudeInDegrees(); }
67 
68  Eegeo::dv3 ToECEF() const;
69  double BearingToInRadians(double latitude, double longitude) const;
70  double BearingToNorthPole() const;
71 
72  static LatLongAltitude FromDegrees(double latitudeInDegrees, double longitudeInDegrees, double altitudeInMetres);
73  static LatLongAltitude FromRadians(double latitudeInRadians, double longitudeInRadians, double altitudeInMetres);
74  static LatLongAltitude FromECEF(const Eegeo::dv3& world);
75  static LatLongAltitude FromLatLong(const LatLong& latLong, double altitudeInMetres);
76  static LatLongAltitude Lerp(const LatLongAltitude& from, const LatLongAltitude& to, float t);
77 
78  private:
79  LatLong m_latLong;
80  double m_altitude;
81  };
82 
83  inline double SignedArea(const std::vector<Eegeo::Space::LatLongAltitude>& points)
84  {
85  double a = 0.0;
86  double b = 0.0;
87  for (int i=0; i<points.size()-1; ++i)
88  {
89  a += points.at(i).GetLongitude() * points.at(i+1).GetLatitude();
90  b += points.at(i).GetLatitude() * points.at(i+1).GetLongitude();
91  }
92  return (a-b)/2.0;
93  }
94  }
95 }