Converted Vector to struct
parent
cb741f3695
commit
5694ce1ffc
24
Eci.cpp
24
Eci.cpp
|
@ -26,10 +26,10 @@ Eci::Eci(const Julian &date, const CoordGeodetic &geo)
|
||||||
* Z position in km
|
* Z position in km
|
||||||
* W magnitude in km
|
* W magnitude in km
|
||||||
*/
|
*/
|
||||||
position_.SetX(achcp * cos(theta));
|
position_.x = achcp * cos(theta);
|
||||||
position_.SetY(achcp * sin(theta));
|
position_.y = achcp * sin(theta);
|
||||||
position_.SetZ((kXKMPER * s + altitude) * sin(latitude));
|
position_.z = (kXKMPER * s + altitude) * sin(latitude);
|
||||||
position_.SetW(position_.GetMagnitude());
|
position_.w = position_.GetMagnitude();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* X velocity in km/s
|
* X velocity in km/s
|
||||||
|
@ -37,10 +37,10 @@ Eci::Eci(const Julian &date, const CoordGeodetic &geo)
|
||||||
* Z velocity in km/s
|
* Z velocity in km/s
|
||||||
* W magnitude in km/s
|
* W magnitude in km/s
|
||||||
*/
|
*/
|
||||||
velocity_.SetX(-mfactor * position_.GetY());
|
velocity_.x = -mfactor * position_.y;
|
||||||
velocity_.SetY(mfactor * position_.GetX());
|
velocity_.y = mfactor * position_.x;
|
||||||
velocity_.SetZ(0.0);
|
velocity_.z = 0.0;
|
||||||
velocity_.SetW(velocity_.GetMagnitude());
|
velocity_.w = velocity_.GetMagnitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
Eci::Eci(const Julian &date, const Vector &position)
|
Eci::Eci(const Julian &date, const Vector &position)
|
||||||
|
@ -58,16 +58,16 @@ Eci::~Eci(void) {
|
||||||
|
|
||||||
CoordGeodetic Eci::ToGeodetic() const {
|
CoordGeodetic Eci::ToGeodetic() const {
|
||||||
|
|
||||||
const double theta = AcTan(position_.GetY(), position_.GetX());
|
const double theta = AcTan(position_.y, position_.x);
|
||||||
/*
|
/*
|
||||||
* changes lon to 0>= and <360
|
* changes lon to 0>= and <360
|
||||||
* const double lon = Globals::Fmod2p(theta - date_.ToGreenwichSiderealTime());
|
* const double lon = Globals::Fmod2p(theta - date_.ToGreenwichSiderealTime());
|
||||||
*/
|
*/
|
||||||
const double lon = fmod(theta - date_.ToGreenwichSiderealTime(), kTWOPI);
|
const double lon = fmod(theta - date_.ToGreenwichSiderealTime(), kTWOPI);
|
||||||
const double r = sqrt((position_.GetX() * position_.GetX()) + (position_.GetY() * position_.GetY()));
|
const double r = sqrt((position_.x * position_.x) + (position_.y * position_.y));
|
||||||
static const double e2 = kF * (2.0 - kF);
|
static const double e2 = kF * (2.0 - kF);
|
||||||
|
|
||||||
double lat = AcTan(position_.GetZ(), r);
|
double lat = AcTan(position_.z, r);
|
||||||
double phi = 0.0;
|
double phi = 0.0;
|
||||||
double c = 0.0;
|
double c = 0.0;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
@ -76,7 +76,7 @@ CoordGeodetic Eci::ToGeodetic() const {
|
||||||
phi = lat;
|
phi = lat;
|
||||||
const double sinphi = sin(phi);
|
const double sinphi = sin(phi);
|
||||||
c = 1.0 / sqrt(1.0 - e2 * sinphi * sinphi);
|
c = 1.0 / sqrt(1.0 - e2 * sinphi * sinphi);
|
||||||
lat = AcTan(position_.GetZ() + kXKMPER * c * e2 * sinphi, r);
|
lat = AcTan(position_.z + kXKMPER * c * e2 * sinphi, r);
|
||||||
cnt++;
|
cnt++;
|
||||||
} while (fabs(lat - phi) >= 1e-10 && cnt < 10);
|
} while (fabs(lat - phi) >= 1e-10 && cnt < 10);
|
||||||
|
|
||||||
|
|
24
Observer.cpp
24
Observer.cpp
|
@ -46,7 +46,7 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
|
||||||
Vector range_rate = eci.GetVelocity().Subtract(observers_eci_.GetVelocity());
|
Vector range_rate = eci.GetVelocity().Subtract(observers_eci_.GetVelocity());
|
||||||
Vector range = eci.GetPosition().Subtract(observers_eci_.GetPosition());
|
Vector range = eci.GetPosition().Subtract(observers_eci_.GetPosition());
|
||||||
|
|
||||||
range.SetW(range.GetMagnitude());
|
range.w = range.GetMagnitude();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate Local Mean Sidereal Time for observers longitude
|
* Calculate Local Mean Sidereal Time for observers longitude
|
||||||
|
@ -58,14 +58,14 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
|
||||||
double sin_theta = sin(theta);
|
double sin_theta = sin(theta);
|
||||||
double cos_theta = cos(theta);
|
double cos_theta = cos(theta);
|
||||||
|
|
||||||
double top_s = sin_lat * cos_theta * range.GetX() +
|
double top_s = sin_lat * cos_theta * range.x +
|
||||||
sin_lat * sin_theta * range.GetY() -
|
sin_lat * sin_theta * range.y -
|
||||||
cos_lat * range.GetZ();
|
cos_lat * range.z;
|
||||||
double top_e = -sin_theta * range.GetX() +
|
double top_e = -sin_theta * range.x +
|
||||||
cos_theta * range.GetY();
|
cos_theta * range.y;
|
||||||
double top_z = cos_lat * cos_theta * range.GetX() +
|
double top_z = cos_lat * cos_theta * range.x +
|
||||||
cos_lat * sin_theta * range.GetY() +
|
cos_lat * sin_theta * range.y +
|
||||||
sin_lat * range.GetZ();
|
sin_lat * range.z;
|
||||||
double az = atan(-top_e / top_s);
|
double az = atan(-top_e / top_s);
|
||||||
|
|
||||||
if (top_s > 0.0)
|
if (top_s > 0.0)
|
||||||
|
@ -74,8 +74,8 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
|
||||||
if (az < 0.0)
|
if (az < 0.0)
|
||||||
az += 2.0 * kPI;
|
az += 2.0 * kPI;
|
||||||
|
|
||||||
double el = asin(top_z / range.GetW());
|
double el = asin(top_z / range.w);
|
||||||
double rate = range.Dot(range_rate) / range.GetW();
|
double rate = range.Dot(range_rate) / range.w;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* azimuth in radians
|
* azimuth in radians
|
||||||
|
@ -85,7 +85,7 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
|
||||||
*/
|
*/
|
||||||
CoordTopographic topo(az,
|
CoordTopographic topo(az,
|
||||||
el,
|
el,
|
||||||
range.GetW(),
|
range.w,
|
||||||
rate);
|
rate);
|
||||||
|
|
||||||
return topo;
|
return topo;
|
||||||
|
|
12
RunTest.cpp
12
RunTest.cpp
|
@ -45,18 +45,18 @@ void RunTle(Tle tle, double start, double end, double inc) {
|
||||||
std::cout.width(17);
|
std::cout.width(17);
|
||||||
std::cout << val << " ";
|
std::cout << val << " ";
|
||||||
std::cout.width(16);
|
std::cout.width(16);
|
||||||
std::cout << position.GetX() << " ";
|
std::cout << position.x << " ";
|
||||||
std::cout.width(16);
|
std::cout.width(16);
|
||||||
std::cout << position.GetY() << " ";
|
std::cout << position.y << " ";
|
||||||
std::cout.width(16);
|
std::cout.width(16);
|
||||||
std::cout << position.GetZ() << " ";
|
std::cout << position.z << " ";
|
||||||
std::cout << std::setprecision(9) << std::fixed;
|
std::cout << std::setprecision(9) << std::fixed;
|
||||||
std::cout.width(14);
|
std::cout.width(14);
|
||||||
std::cout << velocity.GetX() << " ";
|
std::cout << velocity.x << " ";
|
||||||
std::cout.width(14);
|
std::cout.width(14);
|
||||||
std::cout << velocity.GetY() << " ";
|
std::cout << velocity.y << " ";
|
||||||
std::cout.width(14);
|
std::cout.width(14);
|
||||||
std::cout << velocity.GetZ() << std::endl;
|
std::cout << velocity.z << std::endl;
|
||||||
|
|
||||||
} catch (std::exception* ex) {
|
} catch (std::exception* ex) {
|
||||||
std::cout << ex->what() << std::endl;
|
std::cout << ex->what() << std::endl;
|
||||||
|
|
14
Vector.cpp
14
Vector.cpp
|
@ -1,7 +1,7 @@
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
|
|
||||||
double Vector::GetMagnitude() const {
|
double Vector::GetMagnitude() const {
|
||||||
return sqrt(x_ * x_ + y_ * y_ + z_ * z_);
|
return sqrt(x * x + y * y + z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -9,15 +9,15 @@ double Vector::GetMagnitude() const {
|
||||||
* and return result
|
* and return result
|
||||||
*/
|
*/
|
||||||
Vector Vector::Subtract(const Vector& vec) const {
|
Vector Vector::Subtract(const Vector& vec) const {
|
||||||
return Vector(x_ - vec.x_,
|
return Vector(x - vec.x,
|
||||||
y_ - vec.y_,
|
y - vec.y,
|
||||||
z_ - vec.z_,
|
z - vec.z,
|
||||||
0.0);
|
0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Vector::Dot(const Vector& vec) const {
|
double Vector::Dot(const Vector& vec) const {
|
||||||
|
|
||||||
return (x_ * vec.x_) +
|
return (x * vec.x) +
|
||||||
(y_ * vec.y_) +
|
(y * vec.y) +
|
||||||
(z_ * vec.z_);
|
(z * vec.z);
|
||||||
}
|
}
|
||||||
|
|
53
Vector.h
53
Vector.h
|
@ -3,65 +3,32 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
class Vector {
|
struct Vector {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Vector(void)
|
Vector(void)
|
||||||
: x_(0.0), y_(0.0), z_(0.0), w_(0.0) {
|
: x(0.0), y(0.0), z(0.0), w(0.0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector(double x, double y, double z)
|
Vector(double x_in, double y_in, double z_in)
|
||||||
: x_(x), y_(y), z_(z), w_(0.0) {
|
: x(x_in), y(y_in), z(z_in), w(0.0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector(double x, double y, double z, double w)
|
Vector(double x_in, double y_in, double z_in, double w_in)
|
||||||
: x_(x), y_(y), z_(z), w_(w) {
|
: x(x_in), y(y_in), z(z_in), w(w_in) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Vector() {
|
virtual ~Vector() {
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetX(const double& x) {
|
|
||||||
x_ = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetY(const double& y) {
|
|
||||||
y_ = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetZ(const double& z) {
|
|
||||||
z_ = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetW(const double& w) {
|
|
||||||
w_ = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetX() const {
|
|
||||||
return x_;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetY() const {
|
|
||||||
return y_;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetZ() const {
|
|
||||||
return z_;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetW() const {
|
|
||||||
return w_;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetMagnitude() const;
|
double GetMagnitude() const;
|
||||||
Vector Subtract(const Vector& vec) const;
|
Vector Subtract(const Vector& vec) const;
|
||||||
double Dot(const Vector& vec) const;
|
double Dot(const Vector& vec) const;
|
||||||
|
|
||||||
protected:
|
double x;
|
||||||
double x_;
|
double y;
|
||||||
double y_;
|
double z;
|
||||||
double z_;
|
double w;
|
||||||
double w_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue