diff --git a/Eci.cpp b/Eci.cpp new file mode 100644 index 0000000..ea6cdb8 --- /dev/null +++ b/Eci.cpp @@ -0,0 +1,38 @@ +#include "Eci.h" + +Eci::Eci(const Julian &date, const CoordGeodetic &geo) +: date_(date) { + + static const double mfactor = Globals::TWOPI() * (Globals::OMEGA_E() / Globals::SEC_PER_DAY()); + const double latitude = geo.GetLatitude(); + const double longitude = geo.GetLongitude(); + const double altitude = geo.GetAltitude(); + + /* + * Calculate Local Mean Sidereal Time for observers longitude + */ + const double theta = date_.ToLMST(longitude); + + const double c = 1.0 / sqrt(1.0 + Globals::F() * (Globals::F() - 2.0) * pow(sin(latitude), 2.0)); + const double s = pow(1.0 - Globals::F(), 2.0) * c; + const double achcp = (Globals::XKMPER() * c + altitude) * cos(latitude); + + position_.SetX(achcp * cos(theta)); + position_.SetY(achcp * sin(theta)); + + position_.SetZ((Globals::XKMPER() * s + altitude) * sin(latitude)); + position_.SetW(sqrt(pow(position_.GetX(), 2.0) + pow(position_.GetY(), 2.0) + pow(position_.GetZ(), 2.0))); + + velocity_.SetX(-mfactor * position_.GetY()); + velocity_.SetY(mfactor * position_.GetX()); + velocity_.SetZ(0.0); + velocity_.SetW(sqrt(pow(velocity_.GetX(), 2.0) + pow(velocity_.GetY(), 2.0))); +} + +Eci::Eci(const Julian &date, const Vector &position, const Vector &velocity) +: date_(date), position_(position), velocity_(velocity) { + +} + +Eci::~Eci(void) { +} diff --git a/Eci.h b/Eci.h new file mode 100644 index 0000000..a14940a --- /dev/null +++ b/Eci.h @@ -0,0 +1,33 @@ +#ifndef ECI_H_ +#define ECI_H_ + +#include "Coord.h" +#include "Vector.h" +#include "Julian.h" + +class Eci { +public: + Eci(const Julian &date, const CoordGeodetic &geo); + Eci(const Julian &date, const Vector &position, const Vector &velocity); + virtual ~Eci(void); + + Vector GetPosition() const { + return position_; + } + + Vector GetVelocity() const { + return velocity_; + } + + Julian GetDate() const { + return date_; + } + +private: + Vector position_; + Vector velocity_; + Julian date_; +}; + +#endif + diff --git a/Globals.h b/Globals.h index 47cd589..f74dc7a 100644 --- a/Globals.h +++ b/Globals.h @@ -8,6 +8,24 @@ public: Globals(void); ~Globals(void); + static const double F() { + /* + * earth flattening + */ + return 1.0 / 298.26; + } + + static const double OMEGA_E() { + /* + * earth rotation per sideral day + */ + return 1.00273790934; + } + + static const double XKMPER() { + return 6378.135; + } + static const double PI() { return 3.14159265358979323846264338327950288419716939937510582; } diff --git a/Observer.cpp b/Observer.cpp index 40a94c1..b6920f1 100644 --- a/Observer.cpp +++ b/Observer.cpp @@ -1,6 +1,19 @@ #include "Observer.h" -Observer::Observer(void) { +#include "Globals.h" + +/* + * in degrees! + */ +Observer::Observer(const double latitude, const double longitude, const double altitude) { + geo_.SetLatitude(Globals::Deg2Rad(latitude)); + geo_.SetLongitude(Globals::Deg2Rad(longitude)); + geo_.SetAltitude(altitude); +} + +Observer::Observer(const CoordGeodetic &geo) +: geo_(geo) { + } Observer::~Observer(void) { diff --git a/Observer.h b/Observer.h index 26a7936..fee247a 100644 --- a/Observer.h +++ b/Observer.h @@ -5,7 +5,8 @@ class Observer { public: - Observer(void); + Observer(const double latitude, const double longitude, const double altitude); + Observer(const CoordGeodetic &geo); virtual ~Observer(void); void SetLocation(const CoordGeodetic& geo) {