Dos to unix
parent
3ca8edbc96
commit
84bbd5fa54
164
Eci.cpp
164
Eci.cpp
|
@ -1,82 +1,82 @@
|
|||
#include "Eci.h"
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
void Eci::ToEci(const Julian& date, const CoordGeodetic &g)
|
||||
{
|
||||
/*
|
||||
* set date
|
||||
*/
|
||||
date_ = date;
|
||||
|
||||
static const double mfactor = kTWOPI * (kOMEGA_E / kSECONDS_PER_DAY);
|
||||
|
||||
/*
|
||||
* Calculate Local Mean Sidereal Time for observers longitude
|
||||
*/
|
||||
const double theta = date_.ToLocalMeanSiderealTime(g.longitude);
|
||||
|
||||
/*
|
||||
* take into account earth flattening
|
||||
*/
|
||||
const double c = 1.0
|
||||
/ sqrt(1.0 + kF * (kF - 2.0) * pow(sin(g.latitude), 2.0));
|
||||
const double s = pow(1.0 - kF, 2.0) * c;
|
||||
const double achcp = (kXKMPER * c + g.altitude) * cos(g.latitude);
|
||||
|
||||
/*
|
||||
* X position in km
|
||||
* Y position in km
|
||||
* Z position in km
|
||||
* W magnitude in km
|
||||
*/
|
||||
position_.x = achcp * cos(theta);
|
||||
position_.y = achcp * sin(theta);
|
||||
position_.z = (kXKMPER * s + g.altitude) * sin(g.latitude);
|
||||
position_.w = position_.GetMagnitude();
|
||||
|
||||
/*
|
||||
* X velocity in km/s
|
||||
* Y velocity in km/s
|
||||
* Z velocity in km/s
|
||||
* W magnitude in km/s
|
||||
*/
|
||||
velocity_.x = -mfactor * position_.y;
|
||||
velocity_.y = mfactor * position_.x;
|
||||
velocity_.z = 0.0;
|
||||
velocity_.w = velocity_.GetMagnitude();
|
||||
}
|
||||
|
||||
CoordGeodetic Eci::ToGeodetic() const
|
||||
{
|
||||
const double theta = Util::AcTan(position_.y, position_.x);
|
||||
|
||||
// 0 >= lon < 360
|
||||
// const double lon = Fmod2p(theta - date_.ToGreenwichSiderealTime());
|
||||
// 180 >= lon < 180
|
||||
const double lon = Util::WrapNegPosPI(theta - date_.ToGreenwichSiderealTime());
|
||||
|
||||
const double r = sqrt((position_.x * position_.x)
|
||||
+ (position_.y * position_.y));
|
||||
|
||||
static const double e2 = kF * (2.0 - kF);
|
||||
|
||||
double lat = Util::AcTan(position_.z, r);
|
||||
double phi = 0.0;
|
||||
double c = 0.0;
|
||||
int cnt = 0;
|
||||
|
||||
do
|
||||
{
|
||||
phi = lat;
|
||||
const double sinphi = sin(phi);
|
||||
c = 1.0 / sqrt(1.0 - e2 * sinphi * sinphi);
|
||||
lat = Util::AcTan(position_.z + kXKMPER * c * e2 * sinphi, r);
|
||||
cnt++;
|
||||
}
|
||||
while (fabs(lat - phi) >= 1e-10 && cnt < 10);
|
||||
|
||||
const double alt = r / cos(lat) - kXKMPER * c;
|
||||
|
||||
return CoordGeodetic(lat, lon, alt, true);
|
||||
}
|
||||
#include "Eci.h"
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
void Eci::ToEci(const Julian& date, const CoordGeodetic &g)
|
||||
{
|
||||
/*
|
||||
* set date
|
||||
*/
|
||||
date_ = date;
|
||||
|
||||
static const double mfactor = kTWOPI * (kOMEGA_E / kSECONDS_PER_DAY);
|
||||
|
||||
/*
|
||||
* Calculate Local Mean Sidereal Time for observers longitude
|
||||
*/
|
||||
const double theta = date_.ToLocalMeanSiderealTime(g.longitude);
|
||||
|
||||
/*
|
||||
* take into account earth flattening
|
||||
*/
|
||||
const double c = 1.0
|
||||
/ sqrt(1.0 + kF * (kF - 2.0) * pow(sin(g.latitude), 2.0));
|
||||
const double s = pow(1.0 - kF, 2.0) * c;
|
||||
const double achcp = (kXKMPER * c + g.altitude) * cos(g.latitude);
|
||||
|
||||
/*
|
||||
* X position in km
|
||||
* Y position in km
|
||||
* Z position in km
|
||||
* W magnitude in km
|
||||
*/
|
||||
position_.x = achcp * cos(theta);
|
||||
position_.y = achcp * sin(theta);
|
||||
position_.z = (kXKMPER * s + g.altitude) * sin(g.latitude);
|
||||
position_.w = position_.GetMagnitude();
|
||||
|
||||
/*
|
||||
* X velocity in km/s
|
||||
* Y velocity in km/s
|
||||
* Z velocity in km/s
|
||||
* W magnitude in km/s
|
||||
*/
|
||||
velocity_.x = -mfactor * position_.y;
|
||||
velocity_.y = mfactor * position_.x;
|
||||
velocity_.z = 0.0;
|
||||
velocity_.w = velocity_.GetMagnitude();
|
||||
}
|
||||
|
||||
CoordGeodetic Eci::ToGeodetic() const
|
||||
{
|
||||
const double theta = Util::AcTan(position_.y, position_.x);
|
||||
|
||||
// 0 >= lon < 360
|
||||
// const double lon = Fmod2p(theta - date_.ToGreenwichSiderealTime());
|
||||
// 180 >= lon < 180
|
||||
const double lon = Util::WrapNegPosPI(theta - date_.ToGreenwichSiderealTime());
|
||||
|
||||
const double r = sqrt((position_.x * position_.x)
|
||||
+ (position_.y * position_.y));
|
||||
|
||||
static const double e2 = kF * (2.0 - kF);
|
||||
|
||||
double lat = Util::AcTan(position_.z, r);
|
||||
double phi = 0.0;
|
||||
double c = 0.0;
|
||||
int cnt = 0;
|
||||
|
||||
do
|
||||
{
|
||||
phi = lat;
|
||||
const double sinphi = sin(phi);
|
||||
c = 1.0 / sqrt(1.0 - e2 * sinphi * sinphi);
|
||||
lat = Util::AcTan(position_.z + kXKMPER * c * e2 * sinphi, r);
|
||||
cnt++;
|
||||
}
|
||||
while (fabs(lat - phi) >= 1e-10 && cnt < 10);
|
||||
|
||||
const double alt = r / cos(lat) - kXKMPER * c;
|
||||
|
||||
return CoordGeodetic(lat, lon, alt, true);
|
||||
}
|
||||
|
|
612
Julian.cpp
612
Julian.cpp
|
@ -1,306 +1,306 @@
|
|||
#include "Globals.h"
|
||||
#include "Julian.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
Julian::Julian()
|
||||
{
|
||||
#ifdef WIN32
|
||||
SYSTEMTIME st;
|
||||
GetSystemTime(&st);
|
||||
Initialize(st.wYear,
|
||||
st.wMonth,
|
||||
st.wDay,
|
||||
st.wHour,
|
||||
st.wMinute,
|
||||
(double) st.wSecond + (double) st.wMilliseconds / 1000.0);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
struct tm gmt;
|
||||
gmtime_r(&tv.tv_sec, &gmt);
|
||||
Initialize(gmt.tm_year + 1900,
|
||||
gmt.tm_mon + 1,
|
||||
gmt.tm_mday,
|
||||
gmt.tm_hour,
|
||||
gmt.tm_min,
|
||||
(double) gmt.tm_sec + (double) tv.tv_usec / 1000000.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* create julian date given time_t value
|
||||
*/
|
||||
Julian::Julian(const time_t t)
|
||||
{
|
||||
struct tm ptm;
|
||||
#if WIN32
|
||||
if (gmtime_s(&ptm, &t))
|
||||
{
|
||||
assert(1);
|
||||
}
|
||||
#else
|
||||
if (gmtime_r(&t, &ptm) == NULL)
|
||||
{
|
||||
assert(1);
|
||||
}
|
||||
#endif
|
||||
int year = ptm.tm_year + 1900;
|
||||
double day = ptm.tm_yday + 1 +
|
||||
(ptm.tm_hour +
|
||||
((ptm.tm_min +
|
||||
(ptm.tm_sec / 60.0)) / 60.0)) / 24.0;
|
||||
|
||||
Initialize(year, day);
|
||||
}
|
||||
|
||||
/*
|
||||
* comparison
|
||||
*/
|
||||
bool Julian::operator==(const Julian &date) const
|
||||
{
|
||||
return date_ == date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator!=(const Julian &date) const
|
||||
{
|
||||
return !(*this == date);
|
||||
}
|
||||
|
||||
bool Julian::operator>(const Julian &date) const
|
||||
{
|
||||
return date_ > date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator<(const Julian &date) const {
|
||||
|
||||
return date_ < date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator>=(const Julian &date) const
|
||||
{
|
||||
return date_ >= date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator<=(const Julian &date) const
|
||||
{
|
||||
return date_ <= date.date_ ? true : false;
|
||||
}
|
||||
|
||||
/*
|
||||
* assignment
|
||||
*/
|
||||
Julian& Julian::operator=(const Julian& b)
|
||||
{
|
||||
if (this != &b) {
|
||||
date_ = b.date_;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Julian& Julian::operator=(const double b)
|
||||
{
|
||||
date_ = b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* arithmetic
|
||||
*/
|
||||
Julian Julian::operator +(const Timespan& b) const
|
||||
{
|
||||
return Julian(*this) += b;
|
||||
}
|
||||
|
||||
Julian Julian::operator-(const Timespan& b) const
|
||||
{
|
||||
return Julian(*this) -= b;
|
||||
}
|
||||
|
||||
Timespan Julian::operator-(const Julian& b) const
|
||||
{
|
||||
return Timespan(date_ - b.date_);
|
||||
}
|
||||
|
||||
/*
|
||||
* compound assignment
|
||||
*/
|
||||
Julian & Julian::operator +=(const Timespan& b)
|
||||
{
|
||||
date_ += b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Julian & Julian::operator -=(const Timespan& b)
|
||||
{
|
||||
date_ -= b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* create julian date from year and day of year
|
||||
*/
|
||||
void Julian::Initialize(int year, double day)
|
||||
{
|
||||
year--;
|
||||
|
||||
int A = (year / 100);
|
||||
int B = 2 - A + (A / 4);
|
||||
|
||||
double new_years = static_cast<int> (365.25 * year) +
|
||||
static_cast<int> (30.6001 * 14) +
|
||||
1720994.5 + B;
|
||||
|
||||
date_ = new_years + day;
|
||||
}
|
||||
|
||||
/*
|
||||
* create julian date from individual components
|
||||
* year: 2004
|
||||
* mon: 1-12
|
||||
* day: 1-31
|
||||
* hour: 0-23
|
||||
* min: 0-59
|
||||
* sec: 0-59.99
|
||||
*/
|
||||
void Julian::Initialize(int year, int mon, int day,
|
||||
int hour, int min, double sec)
|
||||
{
|
||||
// Calculate N, the day of the year (1..366)
|
||||
int N;
|
||||
int F1 = (int) ((275.0 * mon) / 9.0);
|
||||
int F2 = (int) ((mon + 9.0) / 12.0);
|
||||
|
||||
if (IsLeapYear(year))
|
||||
{
|
||||
// Leap year
|
||||
N = F1 - F2 + day - 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Common year
|
||||
N = F1 - (2 * F2) + day - 30;
|
||||
}
|
||||
|
||||
double dblDay = N + (hour + (min + (sec / 60.0)) / 60.0) / 24.0;
|
||||
|
||||
Initialize(year, dblDay);
|
||||
}
|
||||
|
||||
/*
|
||||
* converts time to time_t
|
||||
* note: resolution to seconds only
|
||||
*/
|
||||
time_t Julian::ToTime() const
|
||||
{
|
||||
return static_cast<time_t> ((date_ - 2440587.5) * 86400.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Greenwich Mean Sidereal Time
|
||||
*/
|
||||
double Julian::ToGreenwichSiderealTime() const
|
||||
{
|
||||
#if 0
|
||||
const double UT = fmod(jul + 0.5, 1.0);
|
||||
const double TU = (jul - 2451545.0 - UT) / 36525.0;
|
||||
|
||||
double GMST = 24110.54841 + TU *
|
||||
(8640184.812866 + TU * (0.093104 - TU * 6.2e-06));
|
||||
|
||||
GMST = fmod(GMST + SEC_PER_DAY * OMEGA_E * UT, SEC_PER_DAY);
|
||||
|
||||
if (GMST < 0.0)
|
||||
{
|
||||
GMST += SEC_PER_DAY; // "wrap" negative modulo value
|
||||
}
|
||||
|
||||
return (TWOPI * (GMST / SEC_PER_DAY));
|
||||
#endif
|
||||
|
||||
// tut1 = Julian centuries from 2000 Jan. 1 12h UT1
|
||||
// (since J2000 which is 2451545.0)
|
||||
// a Julian century is 36525 days
|
||||
const double tut1 = (date_ - 2451545.0) / 36525.0;
|
||||
|
||||
// Rotation angle in arcseconds
|
||||
double theta = 67310.54841 + (876600.0 * 3600.0 + 8640184.812866) * tut1
|
||||
+ 0.093104 * pow(tut1, 2.0) - 0.0000062 * pow(tut1, 3.0);
|
||||
|
||||
// 360.0 / 86400.0 = 1.0 / 240.0
|
||||
theta = Util::WrapTwoPI(Util::DegreesToRadians(theta / 240.0));
|
||||
|
||||
return theta;
|
||||
|
||||
#if 0
|
||||
static const double C1 = 1.72027916940703639e-2;
|
||||
static const double THGR70 = 1.7321343856509374;
|
||||
static const double FK5R = 5.07551419432269442e-15;
|
||||
|
||||
/*
|
||||
* get integer number of days from 0 jan 1970
|
||||
*/
|
||||
const double ts70 = date_ - 2433281.5 - 7305.0;
|
||||
const double ds70 = floor(ts70 + 1.0e-8);
|
||||
const double tfrac = ts70 - ds70;
|
||||
/*
|
||||
* find greenwich location at epoch
|
||||
*/
|
||||
const double c1p2p = C1 + kTWOPI;
|
||||
double gsto = Util::WrapTwoPI(THGR70 + C1 * ds70 + c1p2p * tfrac
|
||||
+ ts70 * ts70 * FK5R);
|
||||
|
||||
return gsto;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Local Mean Sideral Time
|
||||
*/
|
||||
double Julian::ToLocalMeanSiderealTime(const double& lon) const
|
||||
{
|
||||
return fmod(ToGreenwichSiderealTime() + lon, kTWOPI);
|
||||
}
|
||||
|
||||
void Julian::ToGregorian(struct DateTimeComponents* datetime) const
|
||||
{
|
||||
double jdAdj = GetDate() + 0.5;
|
||||
int Z = (int) jdAdj;
|
||||
double F = jdAdj - Z;
|
||||
|
||||
int A = 0;
|
||||
|
||||
if (Z < 2299161)
|
||||
{
|
||||
A = static_cast<int> (Z);
|
||||
}
|
||||
else
|
||||
{
|
||||
int a = static_cast<int> ((Z - 1867216.25) / 36524.25);
|
||||
A = static_cast<int> (Z + 1 + a - static_cast<int> (a / 4));
|
||||
}
|
||||
|
||||
int B = A + 1524;
|
||||
int C = static_cast<int> ((B - 122.1) / 365.25);
|
||||
int D = static_cast<int> (365.25 * C);
|
||||
int E = static_cast<int> ((B - D) / 30.6001);
|
||||
|
||||
datetime->hours = static_cast<int> (F * 24.0);
|
||||
F -= datetime->hours / 24.0;
|
||||
datetime->minutes = static_cast<int> (F * 1440.0);
|
||||
F -= datetime->minutes / 1440.0;
|
||||
datetime->seconds = F * 86400.0;
|
||||
|
||||
datetime->days = B - D - static_cast<int> (30.6001 * E);
|
||||
datetime->months = E < 14 ? E - 1 : E - 13;
|
||||
datetime->years = datetime->months > 2 ? C - 4716 : C - 4715;
|
||||
}
|
||||
#include "Globals.h"
|
||||
#include "Julian.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
Julian::Julian()
|
||||
{
|
||||
#ifdef WIN32
|
||||
SYSTEMTIME st;
|
||||
GetSystemTime(&st);
|
||||
Initialize(st.wYear,
|
||||
st.wMonth,
|
||||
st.wDay,
|
||||
st.wHour,
|
||||
st.wMinute,
|
||||
(double) st.wSecond + (double) st.wMilliseconds / 1000.0);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
struct tm gmt;
|
||||
gmtime_r(&tv.tv_sec, &gmt);
|
||||
Initialize(gmt.tm_year + 1900,
|
||||
gmt.tm_mon + 1,
|
||||
gmt.tm_mday,
|
||||
gmt.tm_hour,
|
||||
gmt.tm_min,
|
||||
(double) gmt.tm_sec + (double) tv.tv_usec / 1000000.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* create julian date given time_t value
|
||||
*/
|
||||
Julian::Julian(const time_t t)
|
||||
{
|
||||
struct tm ptm;
|
||||
#if WIN32
|
||||
if (gmtime_s(&ptm, &t))
|
||||
{
|
||||
assert(1);
|
||||
}
|
||||
#else
|
||||
if (gmtime_r(&t, &ptm) == NULL)
|
||||
{
|
||||
assert(1);
|
||||
}
|
||||
#endif
|
||||
int year = ptm.tm_year + 1900;
|
||||
double day = ptm.tm_yday + 1 +
|
||||
(ptm.tm_hour +
|
||||
((ptm.tm_min +
|
||||
(ptm.tm_sec / 60.0)) / 60.0)) / 24.0;
|
||||
|
||||
Initialize(year, day);
|
||||
}
|
||||
|
||||
/*
|
||||
* comparison
|
||||
*/
|
||||
bool Julian::operator==(const Julian &date) const
|
||||
{
|
||||
return date_ == date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator!=(const Julian &date) const
|
||||
{
|
||||
return !(*this == date);
|
||||
}
|
||||
|
||||
bool Julian::operator>(const Julian &date) const
|
||||
{
|
||||
return date_ > date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator<(const Julian &date) const {
|
||||
|
||||
return date_ < date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator>=(const Julian &date) const
|
||||
{
|
||||
return date_ >= date.date_ ? true : false;
|
||||
}
|
||||
|
||||
bool Julian::operator<=(const Julian &date) const
|
||||
{
|
||||
return date_ <= date.date_ ? true : false;
|
||||
}
|
||||
|
||||
/*
|
||||
* assignment
|
||||
*/
|
||||
Julian& Julian::operator=(const Julian& b)
|
||||
{
|
||||
if (this != &b) {
|
||||
date_ = b.date_;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Julian& Julian::operator=(const double b)
|
||||
{
|
||||
date_ = b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* arithmetic
|
||||
*/
|
||||
Julian Julian::operator +(const Timespan& b) const
|
||||
{
|
||||
return Julian(*this) += b;
|
||||
}
|
||||
|
||||
Julian Julian::operator-(const Timespan& b) const
|
||||
{
|
||||
return Julian(*this) -= b;
|
||||
}
|
||||
|
||||
Timespan Julian::operator-(const Julian& b) const
|
||||
{
|
||||
return Timespan(date_ - b.date_);
|
||||
}
|
||||
|
||||
/*
|
||||
* compound assignment
|
||||
*/
|
||||
Julian & Julian::operator +=(const Timespan& b)
|
||||
{
|
||||
date_ += b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Julian & Julian::operator -=(const Timespan& b)
|
||||
{
|
||||
date_ -= b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* create julian date from year and day of year
|
||||
*/
|
||||
void Julian::Initialize(int year, double day)
|
||||
{
|
||||
year--;
|
||||
|
||||
int A = (year / 100);
|
||||
int B = 2 - A + (A / 4);
|
||||
|
||||
double new_years = static_cast<int> (365.25 * year) +
|
||||
static_cast<int> (30.6001 * 14) +
|
||||
1720994.5 + B;
|
||||
|
||||
date_ = new_years + day;
|
||||
}
|
||||
|
||||
/*
|
||||
* create julian date from individual components
|
||||
* year: 2004
|
||||
* mon: 1-12
|
||||
* day: 1-31
|
||||
* hour: 0-23
|
||||
* min: 0-59
|
||||
* sec: 0-59.99
|
||||
*/
|
||||
void Julian::Initialize(int year, int mon, int day,
|
||||
int hour, int min, double sec)
|
||||
{
|
||||
// Calculate N, the day of the year (1..366)
|
||||
int N;
|
||||
int F1 = (int) ((275.0 * mon) / 9.0);
|
||||
int F2 = (int) ((mon + 9.0) / 12.0);
|
||||
|
||||
if (IsLeapYear(year))
|
||||
{
|
||||
// Leap year
|
||||
N = F1 - F2 + day - 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Common year
|
||||
N = F1 - (2 * F2) + day - 30;
|
||||
}
|
||||
|
||||
double dblDay = N + (hour + (min + (sec / 60.0)) / 60.0) / 24.0;
|
||||
|
||||
Initialize(year, dblDay);
|
||||
}
|
||||
|
||||
/*
|
||||
* converts time to time_t
|
||||
* note: resolution to seconds only
|
||||
*/
|
||||
time_t Julian::ToTime() const
|
||||
{
|
||||
return static_cast<time_t> ((date_ - 2440587.5) * 86400.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Greenwich Mean Sidereal Time
|
||||
*/
|
||||
double Julian::ToGreenwichSiderealTime() const
|
||||
{
|
||||
#if 0
|
||||
const double UT = fmod(jul + 0.5, 1.0);
|
||||
const double TU = (jul - 2451545.0 - UT) / 36525.0;
|
||||
|
||||
double GMST = 24110.54841 + TU *
|
||||
(8640184.812866 + TU * (0.093104 - TU * 6.2e-06));
|
||||
|
||||
GMST = fmod(GMST + SEC_PER_DAY * OMEGA_E * UT, SEC_PER_DAY);
|
||||
|
||||
if (GMST < 0.0)
|
||||
{
|
||||
GMST += SEC_PER_DAY; // "wrap" negative modulo value
|
||||
}
|
||||
|
||||
return (TWOPI * (GMST / SEC_PER_DAY));
|
||||
#endif
|
||||
|
||||
// tut1 = Julian centuries from 2000 Jan. 1 12h UT1
|
||||
// (since J2000 which is 2451545.0)
|
||||
// a Julian century is 36525 days
|
||||
const double tut1 = (date_ - 2451545.0) / 36525.0;
|
||||
|
||||
// Rotation angle in arcseconds
|
||||
double theta = 67310.54841 + (876600.0 * 3600.0 + 8640184.812866) * tut1
|
||||
+ 0.093104 * pow(tut1, 2.0) - 0.0000062 * pow(tut1, 3.0);
|
||||
|
||||
// 360.0 / 86400.0 = 1.0 / 240.0
|
||||
theta = Util::WrapTwoPI(Util::DegreesToRadians(theta / 240.0));
|
||||
|
||||
return theta;
|
||||
|
||||
#if 0
|
||||
static const double C1 = 1.72027916940703639e-2;
|
||||
static const double THGR70 = 1.7321343856509374;
|
||||
static const double FK5R = 5.07551419432269442e-15;
|
||||
|
||||
/*
|
||||
* get integer number of days from 0 jan 1970
|
||||
*/
|
||||
const double ts70 = date_ - 2433281.5 - 7305.0;
|
||||
const double ds70 = floor(ts70 + 1.0e-8);
|
||||
const double tfrac = ts70 - ds70;
|
||||
/*
|
||||
* find greenwich location at epoch
|
||||
*/
|
||||
const double c1p2p = C1 + kTWOPI;
|
||||
double gsto = Util::WrapTwoPI(THGR70 + C1 * ds70 + c1p2p * tfrac
|
||||
+ ts70 * ts70 * FK5R);
|
||||
|
||||
return gsto;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Local Mean Sideral Time
|
||||
*/
|
||||
double Julian::ToLocalMeanSiderealTime(const double& lon) const
|
||||
{
|
||||
return fmod(ToGreenwichSiderealTime() + lon, kTWOPI);
|
||||
}
|
||||
|
||||
void Julian::ToGregorian(struct DateTimeComponents* datetime) const
|
||||
{
|
||||
double jdAdj = GetDate() + 0.5;
|
||||
int Z = (int) jdAdj;
|
||||
double F = jdAdj - Z;
|
||||
|
||||
int A = 0;
|
||||
|
||||
if (Z < 2299161)
|
||||
{
|
||||
A = static_cast<int> (Z);
|
||||
}
|
||||
else
|
||||
{
|
||||
int a = static_cast<int> ((Z - 1867216.25) / 36524.25);
|
||||
A = static_cast<int> (Z + 1 + a - static_cast<int> (a / 4));
|
||||
}
|
||||
|
||||
int B = A + 1524;
|
||||
int C = static_cast<int> ((B - 122.1) / 365.25);
|
||||
int D = static_cast<int> (365.25 * C);
|
||||
int E = static_cast<int> ((B - D) / 30.6001);
|
||||
|
||||
datetime->hours = static_cast<int> (F * 24.0);
|
||||
F -= datetime->hours / 24.0;
|
||||
datetime->minutes = static_cast<int> (F * 1440.0);
|
||||
F -= datetime->minutes / 1440.0;
|
||||
datetime->seconds = F * 86400.0;
|
||||
|
||||
datetime->days = B - D - static_cast<int> (30.6001 * E);
|
||||
datetime->months = E < 14 ? E - 1 : E - 13;
|
||||
datetime->years = datetime->months > 2 ? C - 4716 : C - 4715;
|
||||
}
|
||||
|
|
126
Observer.cpp
126
Observer.cpp
|
@ -1,63 +1,63 @@
|
|||
#include "Observer.h"
|
||||
|
||||
/*
|
||||
* calculate lookangle between the observer and the passed in Eci object
|
||||
*/
|
||||
CoordTopographic Observer::GetLookAngle(const Eci &eci)
|
||||
{
|
||||
/*
|
||||
* update the observers Eci to match the time of the Eci passed in
|
||||
* if necessary
|
||||
*/
|
||||
UpdateObserversEci(eci.GetDate());
|
||||
|
||||
/*
|
||||
* calculate differences
|
||||
*/
|
||||
Vector range_rate = eci.GetVelocity().Subtract(observers_eci_.GetVelocity());
|
||||
Vector range = eci.GetPosition().Subtract(observers_eci_.GetPosition());
|
||||
|
||||
range.w = range.GetMagnitude();
|
||||
|
||||
/*
|
||||
* Calculate Local Mean Sidereal Time for observers longitude
|
||||
*/
|
||||
double theta = eci.GetDate().ToLocalMeanSiderealTime(geo_.longitude);
|
||||
|
||||
double sin_lat = sin(geo_.latitude);
|
||||
double cos_lat = cos(geo_.latitude);
|
||||
double sin_theta = sin(theta);
|
||||
double cos_theta = cos(theta);
|
||||
|
||||
double top_s = sin_lat * cos_theta * range.x
|
||||
+ sin_lat * sin_theta * range.y - cos_lat * range.z;
|
||||
double top_e = -sin_theta * range.x
|
||||
+ cos_theta * range.y;
|
||||
double top_z = cos_lat * cos_theta * range.x
|
||||
+ cos_lat * sin_theta * range.y + sin_lat * range.z;
|
||||
double az = atan(-top_e / top_s);
|
||||
|
||||
if (top_s > 0.0)
|
||||
{
|
||||
az += kPI;
|
||||
}
|
||||
|
||||
if (az < 0.0)
|
||||
{
|
||||
az += 2.0 * kPI;
|
||||
}
|
||||
|
||||
double el = asin(top_z / range.w);
|
||||
double rate = range.Dot(range_rate) / range.w;
|
||||
|
||||
/*
|
||||
* azimuth in radians
|
||||
* elevation in radians
|
||||
* range in km
|
||||
* range rate in km/s
|
||||
*/
|
||||
return CoordTopographic(az,
|
||||
el,
|
||||
range.w,
|
||||
rate);
|
||||
}
|
||||
#include "Observer.h"
|
||||
|
||||
/*
|
||||
* calculate lookangle between the observer and the passed in Eci object
|
||||
*/
|
||||
CoordTopographic Observer::GetLookAngle(const Eci &eci)
|
||||
{
|
||||
/*
|
||||
* update the observers Eci to match the time of the Eci passed in
|
||||
* if necessary
|
||||
*/
|
||||
UpdateObserversEci(eci.GetDate());
|
||||
|
||||
/*
|
||||
* calculate differences
|
||||
*/
|
||||
Vector range_rate = eci.GetVelocity().Subtract(observers_eci_.GetVelocity());
|
||||
Vector range = eci.GetPosition().Subtract(observers_eci_.GetPosition());
|
||||
|
||||
range.w = range.GetMagnitude();
|
||||
|
||||
/*
|
||||
* Calculate Local Mean Sidereal Time for observers longitude
|
||||
*/
|
||||
double theta = eci.GetDate().ToLocalMeanSiderealTime(geo_.longitude);
|
||||
|
||||
double sin_lat = sin(geo_.latitude);
|
||||
double cos_lat = cos(geo_.latitude);
|
||||
double sin_theta = sin(theta);
|
||||
double cos_theta = cos(theta);
|
||||
|
||||
double top_s = sin_lat * cos_theta * range.x
|
||||
+ sin_lat * sin_theta * range.y - cos_lat * range.z;
|
||||
double top_e = -sin_theta * range.x
|
||||
+ cos_theta * range.y;
|
||||
double top_z = cos_lat * cos_theta * range.x
|
||||
+ cos_lat * sin_theta * range.y + sin_lat * range.z;
|
||||
double az = atan(-top_e / top_s);
|
||||
|
||||
if (top_s > 0.0)
|
||||
{
|
||||
az += kPI;
|
||||
}
|
||||
|
||||
if (az < 0.0)
|
||||
{
|
||||
az += 2.0 * kPI;
|
||||
}
|
||||
|
||||
double el = asin(top_z / range.w);
|
||||
double rate = range.Dot(range_rate) / range.w;
|
||||
|
||||
/*
|
||||
* azimuth in radians
|
||||
* elevation in radians
|
||||
* range in km
|
||||
* range rate in km/s
|
||||
*/
|
||||
return CoordTopographic(az,
|
||||
el,
|
||||
range.w,
|
||||
rate);
|
||||
}
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
#include "OrbitalElements.h"
|
||||
|
||||
OrbitalElements::OrbitalElements(const Tle& tle)
|
||||
{
|
||||
/*
|
||||
* extract and format tle data
|
||||
*/
|
||||
mean_anomoly_ = tle.MeanAnomaly(false);
|
||||
ascending_node_ = tle.RightAscendingNode(false);
|
||||
argument_perigee_ = tle.ArgumentPerigee(false);
|
||||
eccentricity_ = tle.Eccentricity();
|
||||
inclination_ = tle.Inclination(false);
|
||||
mean_motion_ = tle.MeanMotion() * kTWOPI / kMINUTES_PER_DAY;
|
||||
bstar_ = tle.BStar();
|
||||
epoch_ = tle.Epoch();
|
||||
|
||||
/*
|
||||
* recover original mean motion (xnodp) and semimajor axis (aodp)
|
||||
* from input elements
|
||||
*/
|
||||
const double a1 = pow(kXKE / MeanMotion(), kTWOTHIRD);
|
||||
const double cosio = cos(Inclination());
|
||||
const double theta2 = cosio * cosio;
|
||||
const double x3thm1 = 3.0 * theta2 - 1.0;
|
||||
const double eosq = Eccentricity() * Eccentricity();
|
||||
const double betao2 = 1.0 - eosq;
|
||||
const double betao = sqrt(betao2);
|
||||
const double temp = (1.5 * kCK2) * x3thm1 / (betao * betao2);
|
||||
const double del1 = temp / (a1 * a1);
|
||||
const double a0 = a1 * (1.0 - del1 * (1.0 / 3.0 + del1 * (1.0 + del1 * 134.0 / 81.0)));
|
||||
const double del0 = temp / (a0 * a0);
|
||||
|
||||
recovered_mean_motion_ = MeanMotion() / (1.0 + del0);
|
||||
/*
|
||||
* alternative way to calculate
|
||||
* doesnt affect final results
|
||||
* recovered_semi_major_axis_ = pow(XKE / RecoveredMeanMotion(), TWOTHIRD);
|
||||
*/
|
||||
recovered_semi_major_axis_ = a0 / (1.0 - del0);
|
||||
|
||||
/*
|
||||
* find perigee and period
|
||||
*/
|
||||
perigee_ = (RecoveredSemiMajorAxis() * (1.0 - Eccentricity()) - kAE) * kXKMPER;
|
||||
period_ = kTWOPI / RecoveredMeanMotion();
|
||||
}
|
||||
|
||||
#include "OrbitalElements.h"
|
||||
|
||||
OrbitalElements::OrbitalElements(const Tle& tle)
|
||||
{
|
||||
/*
|
||||
* extract and format tle data
|
||||
*/
|
||||
mean_anomoly_ = tle.MeanAnomaly(false);
|
||||
ascending_node_ = tle.RightAscendingNode(false);
|
||||
argument_perigee_ = tle.ArgumentPerigee(false);
|
||||
eccentricity_ = tle.Eccentricity();
|
||||
inclination_ = tle.Inclination(false);
|
||||
mean_motion_ = tle.MeanMotion() * kTWOPI / kMINUTES_PER_DAY;
|
||||
bstar_ = tle.BStar();
|
||||
epoch_ = tle.Epoch();
|
||||
|
||||
/*
|
||||
* recover original mean motion (xnodp) and semimajor axis (aodp)
|
||||
* from input elements
|
||||
*/
|
||||
const double a1 = pow(kXKE / MeanMotion(), kTWOTHIRD);
|
||||
const double cosio = cos(Inclination());
|
||||
const double theta2 = cosio * cosio;
|
||||
const double x3thm1 = 3.0 * theta2 - 1.0;
|
||||
const double eosq = Eccentricity() * Eccentricity();
|
||||
const double betao2 = 1.0 - eosq;
|
||||
const double betao = sqrt(betao2);
|
||||
const double temp = (1.5 * kCK2) * x3thm1 / (betao * betao2);
|
||||
const double del1 = temp / (a1 * a1);
|
||||
const double a0 = a1 * (1.0 - del1 * (1.0 / 3.0 + del1 * (1.0 + del1 * 134.0 / 81.0)));
|
||||
const double del0 = temp / (a0 * a0);
|
||||
|
||||
recovered_mean_motion_ = MeanMotion() / (1.0 + del0);
|
||||
/*
|
||||
* alternative way to calculate
|
||||
* doesnt affect final results
|
||||
* recovered_semi_major_axis_ = pow(XKE / RecoveredMeanMotion(), TWOTHIRD);
|
||||
*/
|
||||
recovered_semi_major_axis_ = a0 / (1.0 - del0);
|
||||
|
||||
/*
|
||||
* find perigee and period
|
||||
*/
|
||||
perigee_ = (RecoveredSemiMajorAxis() * (1.0 - Eccentricity()) - kAE) * kXKMPER;
|
||||
period_ = kTWOPI / RecoveredMeanMotion();
|
||||
}
|
||||
|
||||
|
|
476
RunTest.cpp
476
RunTest.cpp
|
@ -1,238 +1,238 @@
|
|||
#include "Julian.h"
|
||||
#include "Tle.h"
|
||||
#include "SGP4.h"
|
||||
#include "Globals.h"
|
||||
#include "Util.h"
|
||||
#include "Observer.h"
|
||||
#include "CoordGeodetic.h"
|
||||
#include "CoordTopographic.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
void RunTle(Tle tle, double start, double end, double inc)
|
||||
{
|
||||
double current = start;
|
||||
SGP4 model(tle);
|
||||
bool running = true;
|
||||
bool first_run = true;
|
||||
std::cout << " " << std::setprecision(0) << tle.NoradNumber() << " xx" << std::endl;
|
||||
while (running)
|
||||
{
|
||||
try
|
||||
{
|
||||
double val;
|
||||
if (first_run && current != 0.0)
|
||||
{
|
||||
/*
|
||||
* make sure first run is always as zero
|
||||
*/
|
||||
val = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* otherwise run as normal
|
||||
*/
|
||||
val = current;
|
||||
}
|
||||
Eci eci = model.FindPosition(val);
|
||||
|
||||
Vector position = eci.GetPosition();
|
||||
Vector velocity = eci.GetVelocity();
|
||||
|
||||
std::cout << std::setprecision(8) << std::fixed;
|
||||
std::cout.width(17);
|
||||
std::cout << val << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.x << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.y << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.z << " ";
|
||||
std::cout << std::setprecision(9) << std::fixed;
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.x << " ";
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.y << " ";
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.z << std::endl;
|
||||
|
||||
}
|
||||
catch (SatelliteException& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
running = false;
|
||||
}
|
||||
if ((first_run && current == 0.0) || !first_run)
|
||||
{
|
||||
if (current == end)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
else if (current + inc > end)
|
||||
{
|
||||
current = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
current += inc;
|
||||
}
|
||||
}
|
||||
first_run = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void tokenize(const std::string& str, std::vector<std::string>& tokens)
|
||||
{
|
||||
const std::string& delimiters = " ";
|
||||
|
||||
/*
|
||||
* skip delimiters at beginning
|
||||
*/
|
||||
std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
|
||||
|
||||
/*
|
||||
* find first non-delimiter
|
||||
*/
|
||||
std::string::size_type pos = str.find_first_of(delimiters, last_pos);
|
||||
|
||||
while (std::string::npos != pos || std::string::npos != last_pos)
|
||||
{
|
||||
/*
|
||||
* add found token to vector
|
||||
*/
|
||||
tokens.push_back(str.substr(last_pos, pos - last_pos));
|
||||
/*
|
||||
* skip delimiters
|
||||
*/
|
||||
last_pos = str.find_first_not_of(delimiters, pos);
|
||||
/*
|
||||
* find next non-delimiter
|
||||
*/
|
||||
pos = str.find_first_of(delimiters, last_pos);
|
||||
}
|
||||
}
|
||||
|
||||
void RunTest(const char* infile)
|
||||
{
|
||||
std::ifstream file;
|
||||
|
||||
file.open(infile);
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cerr << "Error opening file" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
bool got_first_line = false;
|
||||
std::string line1;
|
||||
std::string line2;
|
||||
std::string parameters;
|
||||
|
||||
while (!file.eof())
|
||||
{
|
||||
std::string line;
|
||||
std::getline(file, line);
|
||||
|
||||
Util::Trim(line);
|
||||
|
||||
/*
|
||||
* skip blank lines or lines starting with #
|
||||
*/
|
||||
if (line.length() == 0 || line[0] == '#')
|
||||
{
|
||||
got_first_line = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* find first line
|
||||
*/
|
||||
if (!got_first_line)
|
||||
{
|
||||
try
|
||||
{
|
||||
Tle::IsValidLine(line, 1);
|
||||
/*
|
||||
* store line and now read in second line
|
||||
*/
|
||||
got_first_line = true;
|
||||
line1 = line;
|
||||
}
|
||||
catch (TleException& e)
|
||||
{
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
std::cerr << line << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* no second chances, second line should follow the first
|
||||
*/
|
||||
got_first_line = false;
|
||||
/*
|
||||
* split line, first 69 is the second line of the tle
|
||||
* the rest is the test parameters, if there is any
|
||||
*/
|
||||
line2 = line.substr(0, 69);
|
||||
double start = 0.0;
|
||||
double end = 1440.0;
|
||||
double inc = 120.0;
|
||||
if (line.length() > 69)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
parameters = line.substr(70, line.length() - 69);
|
||||
tokenize(parameters, tokens);
|
||||
if (tokens.size() >= 3)
|
||||
{
|
||||
start = atof(tokens[0].c_str());
|
||||
end = atof(tokens[1].c_str());
|
||||
inc = atof(tokens[2].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* following line must be the second line
|
||||
*/
|
||||
try
|
||||
{
|
||||
Tle::IsValidLine(line2, 2);
|
||||
Tle tle("Test", line1, line2);
|
||||
RunTle(tle, start, end, inc);
|
||||
}
|
||||
catch (TleException& e)
|
||||
{
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
std::cerr << line << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* close file
|
||||
*/
|
||||
file.close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char* file_name = "SGP4-VER.TLE";
|
||||
|
||||
RunTest(file_name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "Julian.h"
|
||||
#include "Tle.h"
|
||||
#include "SGP4.h"
|
||||
#include "Globals.h"
|
||||
#include "Util.h"
|
||||
#include "Observer.h"
|
||||
#include "CoordGeodetic.h"
|
||||
#include "CoordTopographic.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
void RunTle(Tle tle, double start, double end, double inc)
|
||||
{
|
||||
double current = start;
|
||||
SGP4 model(tle);
|
||||
bool running = true;
|
||||
bool first_run = true;
|
||||
std::cout << " " << std::setprecision(0) << tle.NoradNumber() << " xx" << std::endl;
|
||||
while (running)
|
||||
{
|
||||
try
|
||||
{
|
||||
double val;
|
||||
if (first_run && current != 0.0)
|
||||
{
|
||||
/*
|
||||
* make sure first run is always as zero
|
||||
*/
|
||||
val = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* otherwise run as normal
|
||||
*/
|
||||
val = current;
|
||||
}
|
||||
Eci eci = model.FindPosition(val);
|
||||
|
||||
Vector position = eci.GetPosition();
|
||||
Vector velocity = eci.GetVelocity();
|
||||
|
||||
std::cout << std::setprecision(8) << std::fixed;
|
||||
std::cout.width(17);
|
||||
std::cout << val << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.x << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.y << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.z << " ";
|
||||
std::cout << std::setprecision(9) << std::fixed;
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.x << " ";
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.y << " ";
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.z << std::endl;
|
||||
|
||||
}
|
||||
catch (SatelliteException& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
running = false;
|
||||
}
|
||||
if ((first_run && current == 0.0) || !first_run)
|
||||
{
|
||||
if (current == end)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
else if (current + inc > end)
|
||||
{
|
||||
current = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
current += inc;
|
||||
}
|
||||
}
|
||||
first_run = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void tokenize(const std::string& str, std::vector<std::string>& tokens)
|
||||
{
|
||||
const std::string& delimiters = " ";
|
||||
|
||||
/*
|
||||
* skip delimiters at beginning
|
||||
*/
|
||||
std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
|
||||
|
||||
/*
|
||||
* find first non-delimiter
|
||||
*/
|
||||
std::string::size_type pos = str.find_first_of(delimiters, last_pos);
|
||||
|
||||
while (std::string::npos != pos || std::string::npos != last_pos)
|
||||
{
|
||||
/*
|
||||
* add found token to vector
|
||||
*/
|
||||
tokens.push_back(str.substr(last_pos, pos - last_pos));
|
||||
/*
|
||||
* skip delimiters
|
||||
*/
|
||||
last_pos = str.find_first_not_of(delimiters, pos);
|
||||
/*
|
||||
* find next non-delimiter
|
||||
*/
|
||||
pos = str.find_first_of(delimiters, last_pos);
|
||||
}
|
||||
}
|
||||
|
||||
void RunTest(const char* infile)
|
||||
{
|
||||
std::ifstream file;
|
||||
|
||||
file.open(infile);
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cerr << "Error opening file" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
bool got_first_line = false;
|
||||
std::string line1;
|
||||
std::string line2;
|
||||
std::string parameters;
|
||||
|
||||
while (!file.eof())
|
||||
{
|
||||
std::string line;
|
||||
std::getline(file, line);
|
||||
|
||||
Util::Trim(line);
|
||||
|
||||
/*
|
||||
* skip blank lines or lines starting with #
|
||||
*/
|
||||
if (line.length() == 0 || line[0] == '#')
|
||||
{
|
||||
got_first_line = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* find first line
|
||||
*/
|
||||
if (!got_first_line)
|
||||
{
|
||||
try
|
||||
{
|
||||
Tle::IsValidLine(line, 1);
|
||||
/*
|
||||
* store line and now read in second line
|
||||
*/
|
||||
got_first_line = true;
|
||||
line1 = line;
|
||||
}
|
||||
catch (TleException& e)
|
||||
{
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
std::cerr << line << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* no second chances, second line should follow the first
|
||||
*/
|
||||
got_first_line = false;
|
||||
/*
|
||||
* split line, first 69 is the second line of the tle
|
||||
* the rest is the test parameters, if there is any
|
||||
*/
|
||||
line2 = line.substr(0, 69);
|
||||
double start = 0.0;
|
||||
double end = 1440.0;
|
||||
double inc = 120.0;
|
||||
if (line.length() > 69)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
parameters = line.substr(70, line.length() - 69);
|
||||
tokenize(parameters, tokens);
|
||||
if (tokens.size() >= 3)
|
||||
{
|
||||
start = atof(tokens[0].c_str());
|
||||
end = atof(tokens[1].c_str());
|
||||
inc = atof(tokens[2].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* following line must be the second line
|
||||
*/
|
||||
try
|
||||
{
|
||||
Tle::IsValidLine(line2, 2);
|
||||
Tle tle("Test", line1, line2);
|
||||
RunTle(tle, start, end, inc);
|
||||
}
|
||||
catch (TleException& e)
|
||||
{
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
std::cerr << line << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* close file
|
||||
*/
|
||||
file.close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char* file_name = "SGP4-VER.TLE";
|
||||
|
||||
RunTest(file_name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,46 +1,46 @@
|
|||
#include "SolarPosition.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
Eci SolarPosition::FindPosition(const Julian& j)
|
||||
{
|
||||
const double mjd = j.FromJan1_12h_1900();
|
||||
const double year = 1900 + mjd / 365.25;
|
||||
const double T = (mjd + Delta_ET(year) / kSECONDS_PER_DAY) / 36525.0;
|
||||
const double M = Util::DegreesToRadians(Util::Wrap360(358.47583
|
||||
+ Util::Wrap360(35999.04975 * T)
|
||||
- (0.000150 + 0.0000033 * T) * T * T));
|
||||
const double L = Util::DegreesToRadians(Util::Wrap360(279.69668
|
||||
+ Util::Wrap360(36000.76892 * T)
|
||||
+ 0.0003025 * T*T));
|
||||
const double e = 0.01675104 - (0.0000418 + 0.000000126 * T) * T;
|
||||
const double C = Util::DegreesToRadians((1.919460
|
||||
- (0.004789 + 0.000014 * T) * T) * sin(M)
|
||||
+ (0.020094 - 0.000100 * T) * sin(2 * M)
|
||||
+ 0.000293 * sin(3 * M));
|
||||
const double O = Util::DegreesToRadians(
|
||||
Util::Wrap360(259.18 - 1934.142 * T));
|
||||
const double Lsa = Util::WrapTwoPI(L + C
|
||||
- Util::DegreesToRadians(0.00569 - 0.00479 * sin(O)));
|
||||
const double nu = Util::WrapTwoPI(M + C);
|
||||
double R = 1.0000002 * (1 - e * e) / (1 + e * cos(nu));
|
||||
const double eps = Util::DegreesToRadians(23.452294 - (0.0130125
|
||||
+ (0.00000164 - 0.000000503 * T) * T) * T + 0.00256 * cos(O));
|
||||
R = R * kAU;
|
||||
|
||||
Vector solar_position = Vector(R * cos(Lsa),
|
||||
R * sin(Lsa) * cos(eps),
|
||||
R * sin(Lsa) * sin(eps),
|
||||
R);
|
||||
|
||||
return Eci(j, solar_position);
|
||||
}
|
||||
|
||||
double SolarPosition::Delta_ET(double year) const
|
||||
{
|
||||
return 26.465 + 0.747622 * (year - 1950) + 1.886913
|
||||
* sin(kTWOPI * (year - 1975) / 33);
|
||||
}
|
||||
#include "SolarPosition.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
Eci SolarPosition::FindPosition(const Julian& j)
|
||||
{
|
||||
const double mjd = j.FromJan1_12h_1900();
|
||||
const double year = 1900 + mjd / 365.25;
|
||||
const double T = (mjd + Delta_ET(year) / kSECONDS_PER_DAY) / 36525.0;
|
||||
const double M = Util::DegreesToRadians(Util::Wrap360(358.47583
|
||||
+ Util::Wrap360(35999.04975 * T)
|
||||
- (0.000150 + 0.0000033 * T) * T * T));
|
||||
const double L = Util::DegreesToRadians(Util::Wrap360(279.69668
|
||||
+ Util::Wrap360(36000.76892 * T)
|
||||
+ 0.0003025 * T*T));
|
||||
const double e = 0.01675104 - (0.0000418 + 0.000000126 * T) * T;
|
||||
const double C = Util::DegreesToRadians((1.919460
|
||||
- (0.004789 + 0.000014 * T) * T) * sin(M)
|
||||
+ (0.020094 - 0.000100 * T) * sin(2 * M)
|
||||
+ 0.000293 * sin(3 * M));
|
||||
const double O = Util::DegreesToRadians(
|
||||
Util::Wrap360(259.18 - 1934.142 * T));
|
||||
const double Lsa = Util::WrapTwoPI(L + C
|
||||
- Util::DegreesToRadians(0.00569 - 0.00479 * sin(O)));
|
||||
const double nu = Util::WrapTwoPI(M + C);
|
||||
double R = 1.0000002 * (1 - e * e) / (1 + e * cos(nu));
|
||||
const double eps = Util::DegreesToRadians(23.452294 - (0.0130125
|
||||
+ (0.00000164 - 0.000000503 * T) * T) * T + 0.00256 * cos(O));
|
||||
R = R * kAU;
|
||||
|
||||
Vector solar_position = Vector(R * cos(Lsa),
|
||||
R * sin(Lsa) * cos(eps),
|
||||
R * sin(Lsa) * sin(eps),
|
||||
R);
|
||||
|
||||
return Eci(j, solar_position);
|
||||
}
|
||||
|
||||
double SolarPosition::Delta_ET(double year) const
|
||||
{
|
||||
return 26.465 + 0.747622 * (year - 1950) + 1.886913
|
||||
* sin(kTWOPI * (year - 1975) / 33);
|
||||
}
|
||||
|
|
348
Timespan.cpp
348
Timespan.cpp
|
@ -1,175 +1,175 @@
|
|||
#include "Timespan.h"
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
Timespan::Timespan()
|
||||
: time_span_(0.0) {
|
||||
}
|
||||
|
||||
Timespan::Timespan(const unsigned int days, const unsigned int hours,
|
||||
const unsigned int minutes, const double seconds) {
|
||||
|
||||
SetValue(days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
Timespan::Timespan(const double b) {
|
||||
|
||||
time_span_ = b;
|
||||
}
|
||||
|
||||
Timespan::Timespan(const Timespan& b) {
|
||||
time_span_ = b.time_span_;
|
||||
}
|
||||
|
||||
Timespan::~Timespan(void) {
|
||||
}
|
||||
|
||||
void Timespan::SetValue(const unsigned int days, const unsigned int hours,
|
||||
const unsigned int minutes, const double seconds) {
|
||||
|
||||
time_span_ = static_cast<double> (days);
|
||||
AddHours(hours);
|
||||
AddMinutes(minutes);
|
||||
AddSeconds(seconds);
|
||||
}
|
||||
|
||||
void Timespan::AddDays(const unsigned int days) {
|
||||
time_span_ += static_cast<double> (days);
|
||||
}
|
||||
|
||||
void Timespan::AddHours(const unsigned int hours) {
|
||||
time_span_ += (static_cast<double> (hours) / kHOURS_PER_DAY);
|
||||
}
|
||||
|
||||
void Timespan::AddMinutes(const unsigned int minutes) {
|
||||
time_span_ += (static_cast<double> (minutes) / kMINUTES_PER_DAY);
|
||||
}
|
||||
|
||||
void Timespan::AddSeconds(const double seconds) {
|
||||
time_span_ += (seconds / kSECONDS_PER_DAY);
|
||||
}
|
||||
|
||||
double Timespan::GetTotalDays() const {
|
||||
return time_span_;
|
||||
}
|
||||
|
||||
double Timespan::GetTotalHours() const {
|
||||
return time_span_ * kHOURS_PER_DAY;
|
||||
}
|
||||
|
||||
double Timespan::GetTotalMinutes() const {
|
||||
return time_span_ * kMINUTES_PER_DAY;
|
||||
}
|
||||
|
||||
double Timespan::GetTotalSeconds() const {
|
||||
return time_span_ * kSECONDS_PER_DAY;
|
||||
}
|
||||
|
||||
Timespan& Timespan::operator =(const Timespan& b) {
|
||||
|
||||
if (this != &b) {
|
||||
time_span_ = b.time_span_;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan Timespan::operator +(const Timespan& b) const {
|
||||
|
||||
return Timespan(*this) += b;
|
||||
}
|
||||
|
||||
Timespan Timespan::operator -(const Timespan& b) const {
|
||||
|
||||
return Timespan(*this) -= b;
|
||||
}
|
||||
|
||||
Timespan Timespan::operator/(const double b) const {
|
||||
|
||||
return Timespan(*this) /= b;
|
||||
}
|
||||
|
||||
Timespan Timespan::operator*(const double b) const {
|
||||
|
||||
return Timespan(*this) *= b;
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator+=(const Timespan& b) {
|
||||
|
||||
time_span_ += b.time_span_;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator-=(const Timespan& b) {
|
||||
|
||||
time_span_ -= b.time_span_;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator/=(const double b) {
|
||||
|
||||
time_span_ /= b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator*=(const double b) {
|
||||
|
||||
time_span_ *= b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
bool Timespan::operator ==(const Timespan& b) const {
|
||||
|
||||
if (time_span_ == b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator !=(const Timespan& b) const {
|
||||
|
||||
return !(*this == b);
|
||||
}
|
||||
|
||||
bool Timespan::operator>(const Timespan& b) const {
|
||||
|
||||
if (time_span_ > b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator<(const Timespan& b) const {
|
||||
|
||||
if (time_span_ < b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator >=(const Timespan& b) const {
|
||||
|
||||
if (time_span_ >= b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator <=(const Timespan & b) const {
|
||||
|
||||
if (time_span_ <= b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
double& operator +=(double& a, const Timespan& b) {
|
||||
|
||||
a += b.time_span_;
|
||||
return a;
|
||||
}
|
||||
|
||||
double& operator -=(double& a, const Timespan& b) {
|
||||
|
||||
a -= b.time_span_;
|
||||
return a;
|
||||
#include "Timespan.h"
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
Timespan::Timespan()
|
||||
: time_span_(0.0) {
|
||||
}
|
||||
|
||||
Timespan::Timespan(const unsigned int days, const unsigned int hours,
|
||||
const unsigned int minutes, const double seconds) {
|
||||
|
||||
SetValue(days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
Timespan::Timespan(const double b) {
|
||||
|
||||
time_span_ = b;
|
||||
}
|
||||
|
||||
Timespan::Timespan(const Timespan& b) {
|
||||
time_span_ = b.time_span_;
|
||||
}
|
||||
|
||||
Timespan::~Timespan(void) {
|
||||
}
|
||||
|
||||
void Timespan::SetValue(const unsigned int days, const unsigned int hours,
|
||||
const unsigned int minutes, const double seconds) {
|
||||
|
||||
time_span_ = static_cast<double> (days);
|
||||
AddHours(hours);
|
||||
AddMinutes(minutes);
|
||||
AddSeconds(seconds);
|
||||
}
|
||||
|
||||
void Timespan::AddDays(const unsigned int days) {
|
||||
time_span_ += static_cast<double> (days);
|
||||
}
|
||||
|
||||
void Timespan::AddHours(const unsigned int hours) {
|
||||
time_span_ += (static_cast<double> (hours) / kHOURS_PER_DAY);
|
||||
}
|
||||
|
||||
void Timespan::AddMinutes(const unsigned int minutes) {
|
||||
time_span_ += (static_cast<double> (minutes) / kMINUTES_PER_DAY);
|
||||
}
|
||||
|
||||
void Timespan::AddSeconds(const double seconds) {
|
||||
time_span_ += (seconds / kSECONDS_PER_DAY);
|
||||
}
|
||||
|
||||
double Timespan::GetTotalDays() const {
|
||||
return time_span_;
|
||||
}
|
||||
|
||||
double Timespan::GetTotalHours() const {
|
||||
return time_span_ * kHOURS_PER_DAY;
|
||||
}
|
||||
|
||||
double Timespan::GetTotalMinutes() const {
|
||||
return time_span_ * kMINUTES_PER_DAY;
|
||||
}
|
||||
|
||||
double Timespan::GetTotalSeconds() const {
|
||||
return time_span_ * kSECONDS_PER_DAY;
|
||||
}
|
||||
|
||||
Timespan& Timespan::operator =(const Timespan& b) {
|
||||
|
||||
if (this != &b) {
|
||||
time_span_ = b.time_span_;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan Timespan::operator +(const Timespan& b) const {
|
||||
|
||||
return Timespan(*this) += b;
|
||||
}
|
||||
|
||||
Timespan Timespan::operator -(const Timespan& b) const {
|
||||
|
||||
return Timespan(*this) -= b;
|
||||
}
|
||||
|
||||
Timespan Timespan::operator/(const double b) const {
|
||||
|
||||
return Timespan(*this) /= b;
|
||||
}
|
||||
|
||||
Timespan Timespan::operator*(const double b) const {
|
||||
|
||||
return Timespan(*this) *= b;
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator+=(const Timespan& b) {
|
||||
|
||||
time_span_ += b.time_span_;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator-=(const Timespan& b) {
|
||||
|
||||
time_span_ -= b.time_span_;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator/=(const double b) {
|
||||
|
||||
time_span_ /= b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Timespan & Timespan::operator*=(const double b) {
|
||||
|
||||
time_span_ *= b;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
bool Timespan::operator ==(const Timespan& b) const {
|
||||
|
||||
if (time_span_ == b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator !=(const Timespan& b) const {
|
||||
|
||||
return !(*this == b);
|
||||
}
|
||||
|
||||
bool Timespan::operator>(const Timespan& b) const {
|
||||
|
||||
if (time_span_ > b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator<(const Timespan& b) const {
|
||||
|
||||
if (time_span_ < b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator >=(const Timespan& b) const {
|
||||
|
||||
if (time_span_ >= b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timespan::operator <=(const Timespan & b) const {
|
||||
|
||||
if (time_span_ <= b.time_span_)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
double& operator +=(double& a, const Timespan& b) {
|
||||
|
||||
a += b.time_span_;
|
||||
return a;
|
||||
}
|
||||
|
||||
double& operator -=(double& a, const Timespan& b) {
|
||||
|
||||
a -= b.time_span_;
|
||||
return a;
|
||||
}
|
Loading…
Reference in New Issue