orsa_coord.h

Go to the documentation of this file.
00001 /* 
00002    ORSA - Orbit Reconstruction, Simulation and Analysis
00003    Copyright (C) 2002-2004 Pasquale Tricarico
00004    
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009    
00010    As a special exception, Pasquale Tricarico gives permission to
00011    link this program with Qt commercial edition, and distribute the
00012    resulting executable, without including the source code for the Qt
00013    commercial edition in the source distribution.
00014    
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019    
00020    You should have received a copy of the GNU General Public License
00021    along with this program; if not, write to the Free Software
00022    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef _ORSA_COORD_H_
00026 #define _ORSA_COORD_H_
00027 
00028 #include <vector>
00029 #include <cmath>
00030 #include <limits>
00031 
00032 namespace orsa {
00033   
00034   class Vector {
00035   public:
00036     // constructors
00037     // inline Vector() { x = y = z = 0; }
00038     inline Vector() : x(0), y(0), z(0) { }
00039     // inline Vector(const Vector& v) { x = v.x; y = v.y; z = v.z; }
00040     inline Vector(const Vector & v) : x(v.x), y(v.y), z(v.z) { }
00041     // inline Vector(double _x, double _y, double _z) { x = _x; y = _y; z = _z; }
00042     inline Vector(double _x, double _y, double _z) : x(_x), y(_y), z(_z) { }
00043     
00044     // utils
00045     inline double GetX() const { return x; }
00046     inline double GetY() const { return y; }
00047     inline double GetZ() const { return z; }
00048     
00049     // operators
00050     inline Vector & operator += (const Vector & v) {
00051       x += v.x;
00052       y += v.y;
00053       z += v.z;
00054       return *this;
00055     }
00056    
00057     inline Vector & operator -= (const Vector & v) {
00058       x -= v.x;
00059       y -= v.y;
00060       z -= v.z;
00061       return *this;
00062     }
00063     
00064     inline Vector & operator *= (const double f) {
00065       x *= f;
00066       y *= f;
00067       z *= f;
00068       return *this;
00069     }
00070     
00071     inline Vector & operator /= (const double f) {
00072       x /= f;
00073       y /= f;
00074       z /= f;
00075       return * this;
00076     }
00077     
00078     // sign
00079     inline Vector operator + () const { return Vector(x,y,z); }   
00080     inline Vector operator - () const { return Vector(-x,-y,-z); }    
00081     
00082     // moved outside the class
00083     // inline Vector operator * (const double f) const { return Vector(x*f, y*f, z*f); }   
00084     // inline Vector operator / (const double f) const { return Vector(x/f, y/f, z/f); }
00085     
00086     // rotation
00087     Vector & rotate (const double, const double, const double);
00088     
00089     // set
00090     inline void Set(Vector v) {
00091       x = v.x;
00092       y = v.y;
00093       z = v.z;
00094     }
00095     
00096     inline void Set(double _x, double _y, double _z) {
00097       x = _x;
00098       y = _y;
00099       z = _z;
00100     }
00101     
00102     // metrics
00103     inline double Length() const {
00104       using std::sqrt;
00105       return sqrt( (x*x) +
00106                    (y*y) +
00107                    (z*z) );
00108     }
00109     
00110     inline double LengthSquared() const {
00111       return (x*x) +
00112              (y*y) +
00113              (z*z);
00114     }
00115     
00116     inline double ManhattanLength() const {
00117       using std::fabs;
00118       return (fabs(x)+fabs(y)+fabs(z));
00119     }
00120     
00121     inline bool IsZero() const {
00122       return ((x*x) + (y*y) + (z*z)) < (std::numeric_limits<double>::min() * 1.0e3);
00123     }
00124     
00125     // normalization
00126     inline Vector Normalized() const {
00127       double l = Length();
00128       if (l > (std::numeric_limits<double>::min() * 1.0e3))
00129         return Vector(x/l, y/l, z/l);
00130       else
00131         return Vector(0.0, 0.0, 0.0);
00132     }
00133     
00134     inline Vector & Normalize() {
00135       double l = Length();
00136       if (l > (std::numeric_limits<double>::min() * 1.0e3)) {
00137         x /= l;
00138         y /= l;
00139         z /= l;
00140       } else {
00141         z = 0.0;
00142         y = 0.0;
00143         z = 0.0;
00144       }
00145       return *this;
00146     }
00147     
00148   public:
00149     double x, y, z;
00150   };
00151   
00152   inline Vector operator * (const double f, const Vector & v) {
00153     return Vector(v.x*f, v.y*f, v.z*f);
00154   }
00155   
00156   inline Vector operator * (const Vector & v, const double f) {
00157     return Vector(v.x*f, v.y*f, v.z*f);
00158   }
00159   
00160   inline Vector operator / (const Vector & v, const double f) {
00161     return Vector(v.x/f, v.y/f, v.z/f); 
00162   }
00163   
00164   inline Vector operator + (const Vector& u, const Vector& v) {
00165     return Vector(u.x+v.x,
00166                   u.y+v.y,
00167                   u.z+v.z);
00168   }
00169   
00170   inline Vector operator - (const Vector& u, const Vector& v) {
00171     return Vector(u.x-v.x,
00172                   u.y-v.y,
00173                   u.z-v.z);
00174   }
00175   
00176   inline Vector ExternalProduct (const Vector& u, const Vector& v) {
00177     return Vector (u.y*v.z-u.z*v.y,
00178                    u.z*v.x-u.x*v.z,
00179                    u.x*v.y-u.y*v.x); 
00180   }
00181   
00182   inline Vector Cross (const Vector& u, const Vector& v) {
00183     return Vector (u.y*v.z-u.z*v.y,
00184                    u.z*v.x-u.x*v.z,
00185                    u.x*v.y-u.y*v.x); 
00186   }
00187   
00188   // scalar product
00189   inline double operator * (const Vector& u, const Vector& v) {
00190     return (u.x*v.x+
00191             u.y*v.y+
00192             u.z*v.z);
00193   }  
00194   
00195   inline bool operator == (const Vector &v1, const Vector &v2) {
00196     if (v1.x != v2.x) return false;
00197     if (v1.y != v2.y) return false;
00198     if (v1.z != v2.z) return false;
00199     return true;
00200   }
00201   
00202   inline bool operator != (const Vector &v1, const Vector &v2) {
00203     return !(v1 == v2);
00204   }
00205   
00206   // container for intepolation
00207   class VectorWithParameter : public Vector {
00208   public:
00209     double par;
00210   };
00211   
00212   void Interpolate(const std::vector < VectorWithParameter > v_in, const double x, Vector & v_out, Vector & err_v_out);
00213   
00214 } // namespace orsa
00215 
00216 #endif // _ORSA_COORD_H_

Generated on Fri Nov 3 20:37:41 2006 for liborsa by  doxygen 1.4.7