Converted Vector to struct

feature/19
Daniel Warner 2011-05-27 00:22:38 +01:00
parent cb741f3695
commit 5694ce1ffc
5 changed files with 48 additions and 81 deletions

24
Eci.cpp
View File

@ -26,10 +26,10 @@ Eci::Eci(const Julian &date, const CoordGeodetic &geo)
* Z position in km
* W magnitude in km
*/
position_.SetX(achcp * cos(theta));
position_.SetY(achcp * sin(theta));
position_.SetZ((kXKMPER * s + altitude) * sin(latitude));
position_.SetW(position_.GetMagnitude());
position_.x = achcp * cos(theta);
position_.y = achcp * sin(theta);
position_.z = (kXKMPER * s + altitude) * sin(latitude);
position_.w = position_.GetMagnitude();
/*
* X velocity in km/s
@ -37,10 +37,10 @@ Eci::Eci(const Julian &date, const CoordGeodetic &geo)
* Z velocity in km/s
* W magnitude in km/s
*/
velocity_.SetX(-mfactor * position_.GetY());
velocity_.SetY(mfactor * position_.GetX());
velocity_.SetZ(0.0);
velocity_.SetW(velocity_.GetMagnitude());
velocity_.x = -mfactor * position_.y;
velocity_.y = mfactor * position_.x;
velocity_.z = 0.0;
velocity_.w = velocity_.GetMagnitude();
}
Eci::Eci(const Julian &date, const Vector &position)
@ -58,16 +58,16 @@ Eci::~Eci(void) {
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
* const double lon = Globals::Fmod2p(theta - date_.ToGreenwichSiderealTime());
*/
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);
double lat = AcTan(position_.GetZ(), r);
double lat = AcTan(position_.z, r);
double phi = 0.0;
double c = 0.0;
int cnt = 0;
@ -76,7 +76,7 @@ CoordGeodetic Eci::ToGeodetic() const {
phi = lat;
const double sinphi = sin(phi);
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++;
} while (fabs(lat - phi) >= 1e-10 && cnt < 10);

View File

@ -46,7 +46,7 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
Vector range_rate = eci.GetVelocity().Subtract(observers_eci_.GetVelocity());
Vector range = eci.GetPosition().Subtract(observers_eci_.GetPosition());
range.SetW(range.GetMagnitude());
range.w = range.GetMagnitude();
/*
* Calculate Local Mean Sidereal Time for observers longitude
@ -58,14 +58,14 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
double sin_theta = sin(theta);
double cos_theta = cos(theta);
double top_s = sin_lat * cos_theta * range.GetX() +
sin_lat * sin_theta * range.GetY() -
cos_lat * range.GetZ();
double top_e = -sin_theta * range.GetX() +
cos_theta * range.GetY();
double top_z = cos_lat * cos_theta * range.GetX() +
cos_lat * sin_theta * range.GetY() +
sin_lat * range.GetZ();
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)
@ -74,8 +74,8 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
if (az < 0.0)
az += 2.0 * kPI;
double el = asin(top_z / range.GetW());
double rate = range.Dot(range_rate) / range.GetW();
double el = asin(top_z / range.w);
double rate = range.Dot(range_rate) / range.w;
/*
* azimuth in radians
@ -85,7 +85,7 @@ CoordTopographic Observer::GetLookAngle(const Eci &eci) {
*/
CoordTopographic topo(az,
el,
range.GetW(),
range.w,
rate);
return topo;

View File

@ -45,18 +45,18 @@ void RunTle(Tle tle, double start, double end, double inc) {
std::cout.width(17);
std::cout << val << " ";
std::cout.width(16);
std::cout << position.GetX() << " ";
std::cout << position.x << " ";
std::cout.width(16);
std::cout << position.GetY() << " ";
std::cout << position.y << " ";
std::cout.width(16);
std::cout << position.GetZ() << " ";
std::cout << position.z << " ";
std::cout << std::setprecision(9) << std::fixed;
std::cout.width(14);
std::cout << velocity.GetX() << " ";
std::cout << velocity.x << " ";
std::cout.width(14);
std::cout << velocity.GetY() << " ";
std::cout << velocity.y << " ";
std::cout.width(14);
std::cout << velocity.GetZ() << std::endl;
std::cout << velocity.z << std::endl;
} catch (std::exception* ex) {
std::cout << ex->what() << std::endl;

View File

@ -1,7 +1,7 @@
#include "Vector.h"
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
*/
Vector Vector::Subtract(const Vector& vec) const {
return Vector(x_ - vec.x_,
y_ - vec.y_,
z_ - vec.z_,
return Vector(x - vec.x,
y - vec.y,
z - vec.z,
0.0);
}
double Vector::Dot(const Vector& vec) const {
return (x_ * vec.x_) +
(y_ * vec.y_) +
(z_ * vec.z_);
return (x * vec.x) +
(y * vec.y) +
(z * vec.z);
}

View File

@ -3,65 +3,32 @@
#include <cmath>
class Vector {
struct Vector {
public:
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)
: x_(x), y_(y), z_(z), w_(0.0) {
Vector(double x_in, double y_in, double z_in)
: x(x_in), y(y_in), z(z_in), w(0.0) {
}
Vector(double x, double y, double z, double w)
: x_(x), y_(y), z_(z), w_(w) {
Vector(double x_in, double y_in, double z_in, double w_in)
: x(x_in), y(y_in), z(z_in), w(w_in) {
}
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;
Vector Subtract(const Vector& vec) const;
double Dot(const Vector& vec) const;
protected:
double x_;
double y_;
double z_;
double w_;
double x;
double y;
double z;
double w;
};
#endif