From 6ca0b50a51175241586645030a96f37a92a2c096 Mon Sep 17 00:00:00 2001 From: Daniel Warner Date: Sun, 3 Apr 2011 13:08:31 +0100 Subject: [PATCH] Added magnitude method to vector class --- Eci.cpp | 4 ++-- Vector.cpp | 4 ++++ Vector.h | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Eci.cpp b/Eci.cpp index 4d09aae..266a3f5 100644 --- a/Eci.cpp +++ b/Eci.cpp @@ -21,12 +21,12 @@ Eci::Eci(const Julian &date, const CoordGeodetic &geo) 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))); + position_.SetW(position_.GetMagnitude()); 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))); + velocity_.SetW(velocity_.GetMagnitude()); } Eci::Eci(const Julian &date, const Vector &position, const Vector &velocity) diff --git a/Vector.cpp b/Vector.cpp index 37e7137..183fd91 100644 --- a/Vector.cpp +++ b/Vector.cpp @@ -1 +1,5 @@ #include "Vector.h" + +double Vector::GetMagnitude() const { + return sqrt(x_ * x_ + y_ * y_ + z_ * z_); +} diff --git a/Vector.h b/Vector.h index ed8c16d..2b2bb8c 100644 --- a/Vector.h +++ b/Vector.h @@ -1,6 +1,8 @@ #ifndef VECTOR_H_ #define VECTOR_H_ +#include + class Vector { public: @@ -43,6 +45,8 @@ public: return w_; } + double GetMagnitude() const; + protected: double x_; double y_;