Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __VECTOR_H
- #define __VECTOR_H
- #include "debug.h"
- #include "defs.h"
- //____________________________________________________________________________
- //
- // Определение класса вектора
- // Vector of 3 double precision(F64) value.
- class tpVector
- {
- public:
- // Module of the vector.
- inline F64 Mod()const;
- // Normalize of the vector.
- inline tpVector Norm() {return (*this) * (1.0f/Mod());};
- // Element of vector
- F64 operator[] (int i) const { return v[i]; }
- // Reference to element of the vector.
- F64& operator[] (int i) {return v[i];}
- // Constructor.
- tpVector( F64 x0, F64 x1, F64 x2)
- {
- v[0]=x0; v[1]=x1; v[2]=x2;
- };
- protected:
- // Default constructor.
- tpVector()
- {
- v[0] = 0.0;
- v[1] = 0.0;
- v[2] = 0.0;
- };
- // Addition, Subtraction, Multiplication, Division assignment operator.
- inline tpVector& operator+=(const tpVector &a);
- inline tpVector& operator-=(const tpVector &a);
- inline tpVector& operator*=(const F64 a);
- inline tpVector& operator/=(const F64 a);
- tpVector& operator+(const tpVector &b)const
- {tpVector r(*this);return r+=b;};
- tpVector& operator-(const tpVector& b)const
- {tpVector r(*this);return r-=b;};
- tpVector& operator *(const F64 b) const
- {tpVector r(*this);return r*=b;};
- tpVector& operator /(const F64 b) const
- {tpVector r(*this);return r/=b;};
- // Compare operator.
- bool operator <(const tpVector& a) const
- {return (v[0] < a.v[0]) && (v[1] < a.v[1]) && (v[2] < a.v[2]);};
- bool operator <=(const tpVector& a) const
- {return (v[0] <= a.v[0]) && (v[1] <= a.v[1]) && (v[2] <= a.v[2]);};
- friend class tpDecartC;
- friend class tpDecartV;
- friend class tpPolarC;
- protected:
- /// Elements of the vector
- TRM_ALIGN_16(F64 v[3]);
- };
- F64 tpVector::Mod()const
- {
- return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
- };
- tpVector& tpVector::operator +=(const tpVector& a)
- {
- v[0] += a.v[0];
- v[1] += a.v[1];
- v[2] += a.v[2];
- return *this;
- };
- tpVector& tpVector::operator -=(const tpVector& a)
- {
- v[0] -= a.v[0];
- v[1] -= a.v[1];
- v[2] -= a.v[2];
- return *this;
- };
- tpVector& tpVector::operator *=(const F64 a)
- {
- v[0] *= a;
- v[1] *= a;
- v[2] *= a;
- return *this;
- };
- tpVector& tpVector::operator /=(const F64 a)
- {
- v[0] /= a;
- v[1] /= a;
- v[2] /= a;
- return *this;
- };
- /**************************************************************************/
- // 06.09.11 - <math.h> заменен на <qmath.h> для определения M_PI
- /**************************************************************************/
- #ifndef __COORD_H
- #define __COORD_H
- #include <qmath.h>
- #include "params.h"
- #include "mvector.h"
- #include "debug.h"
- #include "defs.h"
- /// type of the "time" value.
- typedef F64 tpTime;
- /// type of the "range" value.
- typedef F64 tpRange;
- /// type of the "velocity" value.
- typedef F64 tpVelocity;
- /// type of the "angle velocity" value.
- typedef F64 tpAngleVel;
- /// Радиус земли - Radius of the Earth [m].
- const tpRange GeoRadius = 6375245;
- /**
- * Эффективный радиус земли
- * const tpRange GeoRadiusEff = 4.*GeoRadius/3.;
- */
- #define GeoRadiusEff 8500326.6
- /// Пересчет градусов в радианы
- template <class T> inline
- F64 GradToRad(T t)
- {return t* F64_DEG_TO_RAD;}
- /// Пересчет радиан в градусы
- template <class T> inline
- F64 RadToGrad(T t)
- {return t* F64_RAD_TO_DEG;}
- //____________________________________________________________________________
- /**
- * Класс, описывающий угловую величину.
- */
- class tpAngle
- {
- public:
- /** Default constructor. */
- tpAngle()
- #ifndef NDEBUG
- : flag(0)
- #endif
- {};
- /** Constructor. */
- tpAngle(const F64 x)
- #ifndef NDEBUG
- : flag(1)
- #endif
- {
- angle = x;
- if(x<-2*M_PI || x>=2*M_PI)
- angle = fmod(x,(F64)2*M_PI);
- if(angle<-M_PI)
- angle+=M_2PI;
- else if(angle>=M_PI)
- angle-=M_2PI;
- };
- operator F64() const { c2assert(flag); return angle; };
- /** Addition assignment operator. */
- tpAngle& operator +=(const tpAngle& d);
- /** Subtraction assignment operator. */
- tpAngle& operator -=(const tpAngle& d);
- private:
- F64 angle;
- #ifndef NDEBUG
- /** Init flag. */
- int flag;
- #endif
- };
- inline tpAngle& tpAngle::operator +=(const tpAngle& d)
- {
- angle = tpAngle(angle+=d);
- return *this;
- }
- inline tpAngle& tpAngle::operator -=(const tpAngle& d)
- {
- angle = tpAngle(angle-=d);
- return *this;
- }
- //*******************************************
- //Функции преобразования углов
- /** Приведение угла в пределы [0, 2*Pi] */
- inline F64 angleNorm(F64 angle)
- {
- while (angle >= M_2PI)
- angle -= M_2PI;
- while (angle < 0)
- angle += M_2PI;
- return angle;
- };
- /** Попадание угла в сектор */
- inline int angleInSector(F64 angle, F64 angle1, F64 angle2)
- {
- if (angle2 > angle1)
- {
- if (angle >= angle1 && angle2 >= angle)
- return 1;
- return 0;
- }
- else
- {
- if (angle >= angle2 && angle1 >= angle)
- return 1;
- return 0;
- }
- };
- /** function-angle normalization: angle [rad] */
- inline F64 NORM_ANGLE_RAD(F64 angle)
- {
- if(angle >= M_2PI)
- return angle-M_2PI;
- else if(angle < 0)
- return angle+M_2PI;
- return angle;
- }
- /** function-angle normalization: angle [deg] */
- inline F64 NORM_ANGLE_GRAD(F64 angle)
- {
- if(angle >= 360)
- return angle-360;
- else if(angle < 0)
- return angle+360;
- return angle;
- }
- /** function - convert angle [deg] to [rad] */
- inline F64 TO_RAD(F64 angle)
- {
- return angle * M_PI_DIV_180; // /180.*M_PI;
- };
- /** function - convert angle [rad] to [deg] */
- inline F64 TO_GRAD(F64 angle)
- {
- return angle * M_180_DIV_PI; // *180./M_PI;
- };
- //******
- class tpDecartV;
- class tpPolarC;
- //____________________________________________________________________________
- // Определение класса вектора декартовых координат
- /**
- * Class of the Cartesian (Decart) coordinates vector.
- * - 1-st element - coordinate X (Nord) [m]
- * - 2-nd element - coordinate Y (Zenith) [m]
- * - 3-rd element - coordinate Z (East) [m]
- */
- class tpDecartC : public tpVector
- {
- public:
- // Default constructor.
- tpDecartC() : tpVector(){};
- tpDecartC(tpRange x, tpRange y, tpRange z) : tpVector(x,y,z){};
- tpDecartC(const tpPolarC& d);
- // Get X (Nord), Get Y (Zenith). Get Z (East)
- tpRange X()const {return v[0];};
- tpRange Y()const {return v[1];};
- tpRange Z()const {return v[2];};
- // Get Altitude.
- tpRange H()
- {
- // return tpRange((*this)[1]
- // + ((*this)[0]*(*this)[0]+(*this)[2]*(*this)[2])/(2.*GeoRadius));
- return tpRange(sqrt( (v[1]+GeoRadiusEff)*(v[1]+GeoRadiusEff)+
- v[0]*v[0]+v[2]*v[2] )- GeoRadiusEff) ;
- };
- tpRange Mod()const {return tpVector::Mod();};
- tpRange Rhor() {return tpRange(sqrt(v[0]*v[0]+v[2]*v[2]));};
- // Addition, Subtraction assignment operator.
- void operator +=(const tpDecartC& d)const
- {const_cast<tpDecartC*>(this)->tpVector::operator+=(d);};
- void operator -=(const tpDecartC& d) const
- {const_cast<tpDecartC*>(this)->tpVector::operator-=(d);};
- // Addition, Subtraction operator.
- const tpDecartC operator+(const tpDecartC& d)const
- {return tpDecartC( tpVector::operator+(d));};
- const tpDecartC operator-(const tpDecartC& d)const
- {return tpDecartC( tpVector::operator-(d));};
- // Division operator.
- const tpDecartV operator /(const tpTime t) const;
- private:
- tpDecartC(const tpVector& d) : tpVector(d){};
- friend class tpDecartV;
- };
- //____________________________________________________________________________
- // Определение класса вектора декартовых скоростей
- /**
- * Class of the velocity vector in the Cartesian coordinate system.
- * - 1-st element - velocity along axis X (Nord) [m/s]
- * - 2-nd element - velocity along axis Y (Zenith) [m/s]
- * - 3-rd element - velocity along axis Z (East) [m/s]
- */
- class tpDecartV : public tpVector
- {
- public:
- // Default constructor.
- tpDecartV() : tpVector(){};
- // Constructor.
- tpDecartV(const tpVelocity x0,const tpVelocity x1,const tpVelocity x2):
- tpVector(x0,x1,x2){};
- // Get velocity along axis X (Nord), axis Y (Zenith), axis Z (East)
- tpVelocity Vx()const {return v[0];};
- tpVelocity Vy()const {return v[1];};
- tpVelocity Vz()const {return v[2];};
- // Calculate full velocity (module of the velocity vector).
- tpVelocity Mod()const
- {
- return tpVector::Mod();
- };
- // Calculate horizontal velocity
- tpVelocity ModXZ()const
- {
- return sqrt(v[0]*v[0] + v[2]*v[2]);
- }
- // Addition, Subtraction assignment operator.
- void operator +=(const tpDecartV& d) const
- {const_cast<tpDecartV*>(this)->tpVector::operator+=(d);};
- void operator -=(const tpDecartV& d) const
- {const_cast<tpDecartV*>(this)->tpVector::operator-=(d);};
- // Addition, Subtraction, Multiplication operator.
- tpDecartV operator+(const tpDecartV& d)const
- {return tpDecartV( tpVector::operator+(d));};
- tpDecartV operator-(const tpDecartV& d)const
- {return tpDecartV( tpVector::operator-(d));};
- tpDecartC operator *(const tpTime t) const;
- // {return tpDecartC(tpVector::operator*(t));};
- private:
- tpDecartV(const tpVector& d) : tpVector(d){};
- friend class tpDecartC;
- };
- inline tpDecartC tpDecartV::operator *(const tpTime t) const
- {
- return tpDecartC(tpVector::operator*(t));
- };
- inline const tpDecartV tpDecartC::operator /(const tpTime t) const
- {
- return tpDecartV(tpVector::operator/(t));
- };
- //____________________________________________________________________________
- class tpAzimuth:public tpAngle
- {
- public:
- tpAzimuth():tpAngle() {};
- tpAzimuth(F64 x):tpAngle(x) {};
- };
- //____________________________________________________________________________
- class tpElevation:public tpAngle
- {
- public:
- tpElevation():tpAngle() {};
- tpElevation(F64 x):tpAngle(x) {};
- };
- //____________________________________________________________________________
- // Определение класса вектора полярных координат
- /**
- * Class of the coordinates vector in the polar coordinate system.
- * It designate for operate witch the vector of the polar coordinates
- * a whole rather than witch separate its element.
- * - 1-vector element - Range [m]
- * - 2-vector element - Azimuth [rad]
- * - 3-vector element - Elevation [rad]
- */
- class tpPolarC : public tpVector
- {
- public:
- // Default constructor.
- tpPolarC() : tpVector(){};
- // Constructor - Create vector of the Polar coordinates.
- tpPolarC(const tpPolarC& c) : tpVector(c){};
- tpPolarC(tpRange r, const tpAzimuth &a, const tpElevation &e):
- tpVector(r,a,e){};
- // Constructor - Create vector of the Decart coordinates.
- tpPolarC(const tpDecartC& d);
- // Get range, azimuth, elevation
- const tpRange& Range()const {return v[0];}
- const tpAzimuth& Azimuth()const {return v[1];}
- const tpElevation& Elevation()const {return v[2];}
- tpPolarC &operator +=(const tpPolarC& d);
- tpPolarC &operator -=(const tpPolarC& d);
- tpPolarC &operator +=(const tpRange& d);
- tpPolarC &operator -=(const tpRange& d);
- tpPolarC &operator +=(const tpAzimuth& d);
- tpPolarC &operator -=(const tpAzimuth& d);
- tpPolarC &operator +=(const tpElevation& d);
- tpPolarC &operator -=(const tpElevation& d);
- tpPolarC operator +(const tpPolarC& d) const
- {return tpPolarC( tpVector::operator+(d));};
- tpPolarC operator -(const tpPolarC& d) const
- {return tpPolarC( tpVector::operator-(d));};
- tpPolarC operator +(const tpRange& d) const;
- tpPolarC operator -(const tpRange& d) const;
- tpPolarC operator +(const tpAzimuth& d) const;
- tpPolarC operator -(const tpAzimuth& d) const;
- tpPolarC operator +(const tpElevation& d) const;
- tpPolarC operator -(const tpElevation& d) const;
- protected:
- F64 Mod()const;
- tpVector Norm()const;
- private:
- tpPolarC(const tpVector& d):tpVector(tpRange(d[0]),
- tpAzimuth(d[1]),tpElevation(d[2])){};
- };
- // inline реализация методов --------------------------------------------
- inline tpPolarC& tpPolarC::operator +=(const tpPolarC& d)
- {
- (*this)[0] += d.Range();
- (*this)[1] = tpAzimuth((*this)[1] + d.Azimuth());
- (*this)[2] = tpElevation((*this)[2] + d.Elevation());
- return *this;
- }
- inline tpPolarC& tpPolarC::operator -=(const tpPolarC& d)
- {
- (*this)[0] -= F64(d.Range());
- (*this)[1] = tpAzimuth((*this)[1]-d.Azimuth());
- (*this)[2] = tpElevation((*this)[2]-d.Elevation());
- return *this;
- }
- inline tpPolarC& tpPolarC::operator +=(const tpRange& r)
- {
- (*this)[0] += r;
- return *this;
- };
- inline tpPolarC& tpPolarC::operator -=(const tpRange& r)
- {
- (*this)[0] -= r;
- return *this;
- };
- inline tpPolarC& tpPolarC::operator +=(const tpAzimuth& a)
- {
- (*this)[1] = tpAzimuth((*this)[1]+F64(a));
- return *this;
- };
- inline tpPolarC& tpPolarC::operator -=(const tpAzimuth& a)
- {
- (*this)[1] = tpAzimuth((*this)[1]-F64(a));
- return *this;
- };
- inline tpPolarC& tpPolarC::operator +=(const tpElevation& e)
- {
- (*this)[2] = tpElevation((*this)[2]+F64(e));
- return *this;
- };
- inline tpPolarC& tpPolarC::operator -=(const tpElevation& e)
- {
- (*this)[2] = tpElevation((*this)[2]-F64(e));
- return *this;
- };
- inline tpPolarC tpPolarC::operator +(const tpRange& r) const
- {
- return tpPolarC(Range()+r,Azimuth(),Elevation());
- };
- inline tpPolarC tpPolarC::operator -(const tpRange& r) const
- {
- return tpPolarC(Range()-r,Azimuth(),Elevation());
- };
- inline tpPolarC tpPolarC::operator +(const tpAzimuth& a) const
- {
- return tpPolarC(Range(),tpAzimuth(Azimuth()+a),Elevation());
- };
- inline tpPolarC tpPolarC::operator -(const tpAzimuth& a) const
- {
- return tpPolarC(Range(),tpAzimuth(Azimuth()-a),Elevation());
- };
- inline tpPolarC tpPolarC::operator +(const tpElevation& e) const
- {
- return tpPolarC(Range(),Azimuth(),tpElevation(Elevation()+e));
- };
- inline tpPolarC tpPolarC::operator -(const tpElevation& e) const
- {
- return tpPolarC(Range(),Azimuth(),tpElevation(Elevation()-e));
- };
- inline tpDecartC::tpDecartC(const tpPolarC& d)
- {
- register tpRange d_hor = d.Range()*cos(d.Elevation());
- *this = tpDecartC( d_hor*cos(d.Azimuth()),
- d.Range()*sin(d.Elevation()),
- d_hor*sin(d.Azimuth()));
- };
- inline tpPolarC::tpPolarC(const tpDecartC& a)
- {
- // initialization intermediate variable
- register F64 sq_d_1_hor= a.X() * a.X() + a.Z() * a.Z();
- register F64 d_1_hor = sqrt( sq_d_1_hor );
- register F64 sq_d_1 = sq_d_1_hor + a.Y() * a.Y();
- register F64 d_1 = sqrt( sq_d_1 );
- // recalculation of coordinates in system of polar coordinates
- *this = tpPolarC( d_1,
- a.Z()!=0 || a.X()!=0 ? atan2(a.Z(),a.X()) : 0,
- a.Y()!=0 || d_1_hor!=0 ? atan2(a.Y(),d_1_hor) : 0 );
- };
- #endif //__COORD_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement