00001
00002 #ifndef IG_STAT_SVECTOR_H
00003 #define IG_STAT_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_STAT_VECTOR_H
00027 #include "stat_vector.h"
00028 #endif
00029
00030 #ifndef IG_STAT_SMATRIX_H
00031 #include "stat_smatrix.h"
00032 #endif
00033
00034 namespace CwMtx
00035 {
00036
00037
00038 template <class T = double>
00039 class CWTSSpaceVector: public CWTSVector<3, T>
00040 {
00041 public:
00042 CWTSSpaceVector(): CWTSVector<3, T>() {}
00043 CWTSSpaceVector(const CWTSMatrix<3, 1, T> &mat): CWTSVector<3, T>(mat) {}
00044 CWTSSpaceVector(const CWTSVector<3, T> &vec): CWTSVector<3, T>(vec) {}
00045 CWTSSpaceVector(const CWTSSpaceVector &svec): CWTSVector<3, T>(svec) {}
00046
00047 CWTSSpaceVector(const T &, const T &, const T &);
00048
00049 ~CWTSSpaceVector() {}
00050
00051 CWTSSpaceVector operator +(const CWTSSpaceVector &) const;
00052 CWTSSpaceVector operator -(const CWTSSpaceVector &) const;
00053 CWTSSpaceVector operator -() const;
00054 CWTSSpaceVector operator *(const T &) const;
00055
00056 T operator *(const CWTSSpaceVector &) const;
00057
00058 CWTSSpaceVector operator %(const CWTSSpaceVector &) const;
00059 CWTSSpaceVector operator /(const T &value) const;
00060
00061
00062 CWTSSpaceVector & operator =(const CWTSSpaceVector &);
00063 CWTSSpaceVector & operator +=(const CWTSSpaceVector &);
00064 CWTSSpaceVector & operator -=(const CWTSSpaceVector &);
00065 CWTSSpaceVector & operator *=(const T &);
00066
00067 CWTSSpaceVector & operator %=(const CWTSSpaceVector &);
00068 CWTSSpaceVector & operator /=(const T &value);
00069
00070 void storeOuterProduct(const CWTSSpaceVector &, const CWTSSpaceVector &);
00071
00072
00073 CWTSSpaceVector unit() const { return (*this)/(this->norm()); }
00074 };
00075
00076 template <class T>
00077 inline CWTSSpaceVector<T>::CWTSSpaceVector(const T &elem1,
00078 const T &elem2,
00079 const T &elem3)
00080 :
00081 CWTSVector<3, T>()
00082 {
00083 (*this)[0] = elem1;
00084 (*this)[1] = elem2;
00085 (*this)[2] = elem3;
00086 }
00087
00088 template <class T>
00089 inline CWTSSpaceVector<T>
00090 CWTSSpaceVector<T>::operator /(const T &value) const
00091 {
00092 return (*this)*(CWTSUnity<T>()/value);
00093 }
00094
00095
00096 template <class T>
00097 inline CWTSSpaceVector<T> &
00098 CWTSSpaceVector<T>::operator =(const CWTSSpaceVector<T> &svec)
00099 {
00100 return
00101 static_cast<CWTSSpaceVector &>(CWTSMatrix<3, 1, T>::operator=(svec));
00102 }
00103
00104 template <class T>
00105 inline CWTSSpaceVector<T> &
00106 CWTSSpaceVector<T>::operator +=(const CWTSSpaceVector<T> &svec)
00107 {
00108 return
00109 static_cast<CWTSSpaceVector &>(CWTSMatrix<3, 1, T>::operator+=(svec));
00110 }
00111
00112 template <class T>
00113 inline CWTSSpaceVector<T> &
00114 CWTSSpaceVector<T>::operator -=(const CWTSSpaceVector<T> &svec)
00115 {
00116 return
00117 static_cast<CWTSSpaceVector &>(CWTSMatrix<3, 1, T>::operator-=(svec));
00118 }
00119
00120 template <class T>
00121 inline CWTSSpaceVector<T> &
00122 CWTSSpaceVector<T>::operator *=(const T &value)
00123 {
00124 return
00125 static_cast<CWTSSpaceVector &>(
00126 CWTSMatrix<3, 1, T>::operator*=(value));
00127 }
00128
00129 template <class T>
00130 inline CWTSSpaceVector<T> &
00131 CWTSSpaceVector<T>::operator /=(const T &value)
00132 {
00133 return (*this) *= CWTSUnity<T>()/value;
00134 }
00135
00136
00137 template <class T>
00138 inline CWTSSpaceVector<T> &
00139 CWTSSpaceVector<T>::operator %=(const CWTSSpaceVector<T> &vec)
00140 {
00141 return (*this) = (*this)%vec;
00142 }
00143
00144 template <class T>
00145 CWTSSpaceVector<T>
00146 CWTSSpaceVector<T>::operator +(const CWTSSpaceVector<T> &svec) const
00147 {
00148 return CWTSSpaceVector(*this) += svec;
00149 }
00150
00151 template <class T>
00152 CWTSSpaceVector<T>
00153 CWTSSpaceVector<T>::operator -(const CWTSSpaceVector<T> &svec) const
00154 {
00155 return CWTSSpaceVector(*this) -= svec;
00156 }
00157
00158 template <class T>
00159 CWTSSpaceVector<T>
00160 CWTSSpaceVector<T>::operator -() const
00161 {
00162 return (*this)*(CWTSZero<T>() - CWTSUnity<T>());
00163 }
00164
00165 template <class T>
00166 CWTSSpaceVector<T>
00167 CWTSSpaceVector<T>::operator *(const T &value) const
00168 {
00169 return CWTSSpaceVector(*this) *= value;
00170 }
00171
00172
00173 template <class T>
00174 T
00175 CWTSSpaceVector<T>::operator *(const CWTSSpaceVector<T> &vec) const
00176 {
00177 return CWTSVector<3, T>::operator*(vec);
00178 }
00179
00180 template <class T>
00181 void
00182 CWTSSpaceVector<T>::storeOuterProduct(const CWTSSpaceVector<T> &svecLeft,
00183 const CWTSSpaceVector<T> &svecRight)
00184 {
00185
00186 T svecLeft0 = svecLeft[0];
00187 T svecLeft1 = svecLeft[1];
00188 T svecLeft2 = svecLeft[2];
00189
00190 T svecRight0 = svecRight[0];
00191 T svecRight1 = svecRight[1];
00192 T svecRight2 = svecRight[2];
00193
00194 (*this)[0] = svecLeft1*svecRight2 - svecLeft2*svecRight1;
00195 (*this)[1] = svecLeft2*svecRight0 - svecLeft0*svecRight2;
00196 (*this)[2] = svecLeft0*svecRight1 - svecLeft1*svecRight0;
00197 }
00198
00199 template <class T>
00200 CWTSSpaceVector<T>
00201 CWTSSpaceVector<T>::operator %(const CWTSSpaceVector<T> &svec) const
00202 {
00203 CWTSSpaceVector<T> svecResult;
00204 svecResult.storeOuterProduct(*this, svec);
00205 return svecResult;
00206 }
00207
00208
00209
00210 template <class T>
00211 inline CWTSSpaceVector<T>
00212 operator *(const T &value, const CWTSSpaceVector<T> &svec)
00213 {
00214 return svec*value;
00215 }
00216
00217
00218 template <class T>
00219 CWTSSpaceVector<T>
00220 operator *(const CWTSSquareMatrix<3, T> &smat,
00221 const CWTSSpaceVector<T> &svec)
00222 {
00223 CWTSSpaceVector<T> svecResult;
00224
00225 for (unsigned irow = 0; irow < 3; ++irow)
00226 {
00227 svecResult[irow] = CWTSZero<T>();
00228
00229 for (unsigned icol = 0; icol < 3; ++icol)
00230 {
00231 svecResult[irow] += smat[irow][icol]*svec[icol];
00232 }
00233 }
00234
00235 return svecResult;
00236 }
00237
00238
00239 template <class T>
00240 inline CWTSSpaceVector<T>
00241 sgn(const CWTSSpaceVector<T> &svec)
00242 {
00243 return svec.unit();
00244 }
00245 }
00246
00247 #endif // IG_STAT_SVECTOR_H