Updated Vector
parent
6e2de1facd
commit
c6132e513f
3
Makefile
3
Makefile
|
@ -17,8 +17,7 @@ SOURCES=Eci.cpp \
|
|||
OrbitalElements.cpp \
|
||||
SGP4.cpp \
|
||||
Timespan.cpp \
|
||||
Tle.cpp \
|
||||
Vector.cpp
|
||||
Tle.cpp
|
||||
OBJECTS=$(SOURCES:.cpp=.o)
|
||||
SGP4LIB=libsgp4.a
|
||||
|
||||
|
|
23
Vector.cpp
23
Vector.cpp
|
@ -1,23 +0,0 @@
|
|||
#include "Vector.h"
|
||||
|
||||
double Vector::GetMagnitude() const {
|
||||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
/*
|
||||
* subtract (this) - (v)
|
||||
* and return result
|
||||
*/
|
||||
Vector Vector::Subtract(const Vector& vec) const {
|
||||
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);
|
||||
}
|
88
Vector.h
88
Vector.h
|
@ -2,28 +2,87 @@
|
|||
#define VECTOR_H_
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
struct Vector {
|
||||
struct Vector
|
||||
{
|
||||
public:
|
||||
|
||||
Vector(void)
|
||||
: x(0.0), y(0.0), z(0.0), w(0.0) {
|
||||
Vector()
|
||||
: x(0.0), y(0.0), z(0.0), 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 xx, double yy, double zz)
|
||||
: x(xx), y(yy), z(zz), w(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
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) {
|
||||
Vector(double xx, double yy, double zz, double ww)
|
||||
: x(xx), y(yy), z(zz), w(ww)
|
||||
{
|
||||
}
|
||||
|
||||
Vector(const Vector& v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
|
||||
virtual ~Vector() {
|
||||
};
|
||||
virtual ~Vector()
|
||||
{
|
||||
}
|
||||
|
||||
double GetMagnitude() const;
|
||||
Vector Subtract(const Vector& vec) const;
|
||||
double Dot(const Vector& vec) const;
|
||||
Vector& operator=(const Vector& v)
|
||||
{
|
||||
if (this != &v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
double GetMagnitude() const
|
||||
{
|
||||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
Vector Subtract(const Vector& v) const
|
||||
{
|
||||
/*
|
||||
* subtract (this) - (v)
|
||||
* and return result
|
||||
*/
|
||||
return Vector(x - v.x,
|
||||
y - v.y,
|
||||
z - v.z,
|
||||
0.0);
|
||||
}
|
||||
|
||||
double Dot(const Vector& vec) const
|
||||
{
|
||||
return (x * vec.x) +
|
||||
(y * vec.y) +
|
||||
(z * vec.z);
|
||||
}
|
||||
|
||||
std::string ToString() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::right << std::fixed << std::setprecision(2);
|
||||
ss << "X: " << std::setw(8) << x;
|
||||
ss << ", Y: " << std::setw(8) << y;
|
||||
ss << ", Z: " << std::setw(8) << z;
|
||||
ss << ", W: " << std::setw(8) << w;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
double x;
|
||||
double y;
|
||||
|
@ -31,4 +90,9 @@ public:
|
|||
double w;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& strm, const Vector& v)
|
||||
{
|
||||
return strm << v.ToString();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue