00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00037
00038 inline Vector() : x(0), y(0), z(0) { }
00039
00040 inline Vector(const Vector & v) : x(v.x), y(v.y), z(v.z) { }
00041
00042 inline Vector(double _x, double _y, double _z) : x(_x), y(_y), z(_z) { }
00043
00044
00045 inline double GetX() const { return x; }
00046 inline double GetY() const { return y; }
00047 inline double GetZ() const { return z; }
00048
00049
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
00079 inline Vector operator + () const { return Vector(x,y,z); }
00080 inline Vector operator - () const { return Vector(-x,-y,-z); }
00081
00082
00083
00084
00085
00086
00087 Vector & rotate (const double, const double, const double);
00088
00089
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
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
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
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
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 }
00215
00216 #endif // _ORSA_COORD_H_