00001
00002 #ifndef IG_SVECTOR_H
00003 #define IG_SVECTOR_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef IG_VECTOR_H
00027 #include "vector.h"
00028 #endif
00029
00030 #ifndef IG_SMATRIX_H
00031 #include "smatrix.h"
00032 #endif
00033
00034 namespace CwMtx
00035 {
00036
00037
00038 template < class T = double >
00039 class CWTSpaceVector: public CWTVector<T>
00040 {
00041 public:
00042 CWTSpaceVector(): CWTVector<T>(3U) {};
00043 CWTSpaceVector(const CWTMatrix<T> &mat): CWTVector<T>(mat) {};
00044 CWTSpaceVector(const CWTVector<T> &vec): CWTVector<T>(vec) {};
00045 CWTSpaceVector(const CWTSpaceVector &svec): CWTVector<T>(svec) {};
00046
00047 CWTSpaceVector(const T &, const T &, const T &);
00048 CWTSpaceVector(const CWTMatrix<T> &, unsigned, unsigned);
00049 CWTSpaceVector(const CWTVector<T> &vec,
00050 unsigned irowStart): CWTVector<T>(vec,
00051 irowStart,
00052 irowStart + 2) {};
00053
00054 ~CWTSpaceVector() {};
00055
00056 void dimension() { CWTVector<T>::dimension(3); };
00057 void mapInto(const CWTMatrix<T> &mat,
00058 unsigned irowStart,
00059 unsigned icolStart);
00060 void mapInto(const CWTVector<T> &vec,
00061 unsigned irowStart = 0);
00062
00063 CWTSpaceVector operator +(const CWTSpaceVector &) const;
00064 CWTSpaceVector operator -(const CWTSpaceVector &) const;
00065 CWTSpaceVector operator -() const;
00066 CWTSpaceVector operator *(const T &) const;
00067
00068 T operator *(const CWTSpaceVector &) const;
00069
00070 CWTSpaceVector operator %(const CWTSpaceVector &) const;
00071 CWTSpaceVector operator /(const T &value) const;
00072
00073
00074 CWTSpaceVector & operator =(const CWTSpaceVector &);
00075 CWTSpaceVector & operator +=(const CWTSpaceVector &);
00076 CWTSpaceVector & operator -=(const CWTSpaceVector &);
00077 CWTSpaceVector & operator *=(const T &);
00078
00079 CWTSpaceVector & operator %=(const CWTSpaceVector &);
00080 CWTSpaceVector & operator /=(const T &value);
00081
00082 void storeOuterProduct(const CWTSpaceVector &, const CWTSpaceVector &);
00083
00084
00085 CWTSpaceVector unit() const { return (*this)/(this->norm()); }
00086 };
00087
00088
00089
00090
00091 template <class T>
00092 class CWTZero< CWTSpaceVector<T> >: public CWTSpaceVector<T>
00093 {
00094 public:
00095 CWTZero() { fill(CWTZero<T>()); }
00096 };
00097
00098
00099
00100
00101
00102 template < class T >
00103 inline CWTSpaceVector<T>::CWTSpaceVector(const CWTMatrix<T> &mat,
00104 unsigned irowStart,
00105 unsigned icolStart)
00106 :
00107 CWTVector<T>(mat, irowStart, icolStart, irowStart + 2)
00108 {
00109 }
00110
00111 template < class T >
00112 inline CWTSpaceVector<T>::CWTSpaceVector(const T &elem1,
00113 const T &elem2,
00114 const T &elem3)
00115 :
00116 CWTVector<T>(3U)
00117 {
00118 (*this)[0] = elem1;
00119 (*this)[1] = elem2;
00120 (*this)[2] = elem3;
00121 }
00122
00123
00124
00125
00126
00127 template < class T >
00128 inline void CWTSpaceVector<T>::mapInto(const CWTMatrix<T> &mat,
00129 unsigned irowStart,
00130 unsigned icolStart)
00131 {
00132 CWTVector<T>::mapInto(mat, irowStart, icolStart, irowStart + 2);
00133 }
00134
00135 template < class T >
00136 inline void CWTSpaceVector<T>::mapInto(const CWTVector<T> &vec,
00137 unsigned irowStart)
00138 {
00139 CWTVector<T>::mapInto(vec, irowStart, irowStart + 2);
00140 }
00141
00142 template < class T >
00143 inline CWTSpaceVector<T> CWTSpaceVector<T>::operator /(const T &value) const
00144 {
00145
00146
00147
00148 T tTmp = CWTUnity<T>();
00149 tTmp /= value;
00150 return (*this)*tTmp;
00151 }
00152
00153
00154 template < class T >
00155 inline CWTSpaceVector<T> &
00156 CWTSpaceVector<T>::operator =(const CWTSpaceVector<T> &svec)
00157 {
00158 return static_cast<CWTSpaceVector &>(CWTMatrix<T>::operator=(svec));
00159 }
00160
00161 template < class T >
00162 inline CWTSpaceVector<T> &
00163 CWTSpaceVector<T>::operator +=(const CWTSpaceVector<T> &svec)
00164 {
00165 return static_cast<CWTSpaceVector &>(CWTMatrix<T>::operator+=(svec));
00166 }
00167
00168 template < class T >
00169 inline CWTSpaceVector<T> &
00170 CWTSpaceVector<T>::operator -=(const CWTSpaceVector<T> &svec)
00171 {
00172 return static_cast<CWTSpaceVector &>(CWTMatrix<T>::operator-=(svec));
00173 }
00174
00175 template < class T >
00176 inline CWTSpaceVector<T> & CWTSpaceVector<T>::operator *=(const T &value)
00177 {
00178 return static_cast<CWTSpaceVector &>(CWTMatrix<T>::operator*=(value));
00179 }
00180
00181 template < class T >
00182 inline CWTSpaceVector<T> & CWTSpaceVector<T>::operator /=(const T &value)
00183 {
00184
00185
00186
00187 T tTmp = CWTUnity<T>();
00188 tTmp /= value;
00189 return (*this) *= tTmp;
00190 }
00191
00192
00193 template < class T >
00194 inline CWTSpaceVector<T> &
00195 CWTSpaceVector<T>::operator %=(const CWTSpaceVector<T> &vec)
00196 {
00197 return (*this) = (*this)%vec;
00198 }
00199
00200 template < class T >
00201 CWTSpaceVector<T>
00202 CWTSpaceVector<T>::operator +(const CWTSpaceVector<T> &svec) const
00203 {
00204 return CWTSpaceVector(*this) += svec;
00205 }
00206
00207 template < class T >
00208 CWTSpaceVector<T>
00209 CWTSpaceVector<T>::operator -(const CWTSpaceVector<T> &svec) const
00210 {
00211 return CWTSpaceVector(*this) -= svec;
00212 }
00213
00214 template < class T >
00215 CWTSpaceVector<T> CWTSpaceVector<T>::operator -() const
00216 {
00217
00218
00219
00220 T tTmp = CWTZero<T>();
00221 tTmp -= CWTUnity<T>();
00222 return (*this)*tTmp;
00223 }
00224
00225 template < class T >
00226 CWTSpaceVector<T> CWTSpaceVector<T>::operator *(const T &value) const
00227 {
00228 return CWTSpaceVector(*this) *= value;
00229 }
00230
00231
00232 template < class T >
00233 T CWTSpaceVector<T>::operator *(const CWTSpaceVector<T> &vec) const
00234 {
00235 return CWTVector<T>::operator*(vec);
00236 }
00237
00238 template < class T >
00239 void CWTSpaceVector<T>::
00240 storeOuterProduct(const CWTSpaceVector<T> &svecLeft,
00241 const CWTSpaceVector<T> &svecRight)
00242 {
00243
00244 T svecLeft0 = svecLeft[0];
00245 T svecLeft1 = svecLeft[1];
00246 T svecLeft2 = svecLeft[2];
00247
00248 T svecRight0 = svecRight[0];
00249 T svecRight1 = svecRight[1];
00250 T svecRight2 = svecRight[2];
00251
00252 (*this)[0] = svecLeft1*svecRight2 - svecLeft2*svecRight1;
00253 (*this)[1] = svecLeft2*svecRight0 - svecLeft0*svecRight2;
00254 (*this)[2] = svecLeft0*svecRight1 - svecLeft1*svecRight0;
00255 }
00256
00257 template < class T >
00258 CWTSpaceVector<T>
00259 CWTSpaceVector<T>::operator %(const CWTSpaceVector<T> &svec) const
00260 {
00261 CWTSpaceVector<T> svecResult;
00262 svecResult.storeOuterProduct(*this, svec);
00263 return svecResult;
00264 }
00265
00266
00267
00268
00269
00270 template < class T >
00271 inline CWTSpaceVector<T> operator *(const T &value,
00272 const CWTSpaceVector<T> &svec)
00273 {
00274 return svec*value;
00275 }
00276
00277
00278 template < class T >
00279 CWTSpaceVector<T> operator *(const CWTSquareMatrix<T> &smat,
00280 const CWTSpaceVector<T> &svec)
00281 {
00282 CWTSpaceVector<T> svecResult;
00283 svecResult.storeProduct(smat, svec);
00284 return svecResult;
00285 }
00286
00287
00288 template <class T>
00289 inline CWTSpaceVector<T>
00290 sgn(const CWTSpaceVector<T> &svec)
00291 {
00292 return svec.unit();
00293 }
00294 }
00295
00296 #endif // IG_SVECTOR_H