Added magnitude method to vector class

feature/19
Daniel Warner 2011-04-03 13:08:31 +01:00
parent 5c02e61ec1
commit 6ca0b50a51
3 changed files with 10 additions and 2 deletions

View File

@ -21,12 +21,12 @@ Eci::Eci(const Julian &date, const CoordGeodetic &geo)
position_.SetY(achcp * sin(theta)); position_.SetY(achcp * sin(theta));
position_.SetZ((Globals::XKMPER() * s + altitude) * sin(latitude)); 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))); position_.SetW(position_.GetMagnitude());
velocity_.SetX(-mfactor * position_.GetY()); velocity_.SetX(-mfactor * position_.GetY());
velocity_.SetY(mfactor * position_.GetX()); velocity_.SetY(mfactor * position_.GetX());
velocity_.SetZ(0.0); velocity_.SetZ(0.0);
velocity_.SetW(sqrt(pow(velocity_.GetX(), 2.0) + pow(velocity_.GetY(), 2.0))); velocity_.SetW(velocity_.GetMagnitude());
} }
Eci::Eci(const Julian &date, const Vector &position, const Vector &velocity) Eci::Eci(const Julian &date, const Vector &position, const Vector &velocity)

View File

@ -1 +1,5 @@
#include "Vector.h" #include "Vector.h"
double Vector::GetMagnitude() const {
return sqrt(x_ * x_ + y_ * y_ + z_ * z_);
}

View File

@ -1,6 +1,8 @@
#ifndef VECTOR_H_ #ifndef VECTOR_H_
#define VECTOR_H_ #define VECTOR_H_
#include <cmath>
class Vector { class Vector {
public: public:
@ -43,6 +45,8 @@ public:
return w_; return w_;
} }
double GetMagnitude() const;
protected: protected:
double x_; double x_;
double y_; double y_;