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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef FGCOLUMNVECTOR3_H
00036 #define FGCOLUMNVECTOR3_H
00037
00038
00039
00040
00041
00042 #include <cstdlib>
00043 #include <string>
00044 #include <fstream>
00045 #include <iostream>
00046 #include <cmath>
00047
00048 using std::ostream;
00049 using std::istream;
00050 using std::cerr;
00051 using std::cout;
00052 using std::endl;
00053 using std::sqrt;
00054 using std::string;
00055
00056 #include "FGJSBBase.h"
00057
00058
00059
00060
00061
00062 #define ID_COLUMNVECTOR3 "$Id: FGColumnVector3.h,v 1.9 2008/07/22 02:42:17 jberndt Exp $"
00063
00064
00065
00066
00067
00068 namespace JSBSim {
00069
00070
00071
00072
00073
00079
00080
00081
00082
00083 class FGColumnVector3 : public FGJSBBase
00084 {
00085 public:
00088 FGColumnVector3(void);
00089
00095 FGColumnVector3(double X, double Y, double Z) {
00096 data[0] = X;
00097 data[1] = Y;
00098 data[2] = Z;
00099 Debug(0);
00100 }
00101
00105 FGColumnVector3(const FGColumnVector3& v) {
00106 data[0] = v.data[0];
00107 data[1] = v.data[1];
00108 data[2] = v.data[2];
00109 Debug(0);
00110 }
00111
00113 ~FGColumnVector3(void) { Debug(1); }
00114
00120 double operator()(unsigned int idx) const { return Entry(idx); }
00121
00127 double& operator()(unsigned int idx) { return Entry(idx); }
00128
00137 double Entry(unsigned int idx) const { return data[idx-1]; }
00138
00147 double& Entry(unsigned int idx) { return data[idx-1]; }
00148
00152 string Dump(string delimeter) const;
00153
00157 FGColumnVector3& operator=(const FGColumnVector3& b) {
00158 data[0] = b.data[0];
00159 data[1] = b.data[1];
00160 data[2] = b.data[2];
00161 return *this;
00162 }
00163
00167 bool operator==(const FGColumnVector3& b) const {
00168 return data[0] == b.data[0] && data[1] == b.data[1] && data[2] == b.data[2];
00169 }
00170
00174 bool operator!=(const FGColumnVector3& b) const { return ! operator==(b); }
00175
00180 FGColumnVector3 operator*(const double scalar) const {
00181 return FGColumnVector3(scalar*Entry(1), scalar*Entry(2), scalar*Entry(3));
00182 }
00183
00188 FGColumnVector3 operator/(const double scalar) const;
00189
00195 FGColumnVector3 operator*(const FGColumnVector3& V) const {
00196 return FGColumnVector3( Entry(2) * V(3) - Entry(3) * V(2),
00197 Entry(3) * V(1) - Entry(1) * V(3),
00198 Entry(1) * V(2) - Entry(2) * V(1) );
00199 }
00200
00202 FGColumnVector3 operator+(const FGColumnVector3& B) const {
00203 return FGColumnVector3( Entry(1) + B(1), Entry(2) + B(2), Entry(3) + B(3) );
00204 }
00205
00207 FGColumnVector3 operator-(const FGColumnVector3& B) const {
00208 return FGColumnVector3( Entry(1) - B(1), Entry(2) - B(2), Entry(3) - B(3) );
00209 }
00210
00212 FGColumnVector3& operator-=(const FGColumnVector3 &B) {
00213 Entry(1) -= B(1);
00214 Entry(2) -= B(2);
00215 Entry(3) -= B(3);
00216 return *this;
00217 }
00218
00220 FGColumnVector3& operator+=(const FGColumnVector3 &B) {
00221 Entry(1) += B(1);
00222 Entry(2) += B(2);
00223 Entry(3) += B(3);
00224 return *this;
00225 }
00226
00228 FGColumnVector3& operator*=(const double scalar) {
00229 Entry(1) *= scalar;
00230 Entry(2) *= scalar;
00231 Entry(3) *= scalar;
00232 return *this;
00233 }
00234
00236 FGColumnVector3& operator/=(const double scalar);
00237
00238 void InitMatrix(void) { data[0] = data[1] = data[2] = 0.0; }
00239 void InitMatrix(double a) { data[0] = data[1] = data[2] = a; }
00240 void InitMatrix(double a, double b, double c) {
00241 data[0]=a; data[1]=b; data[2]=c;
00242 }
00243
00246 double Magnitude(void) const;
00247
00251 double Magnitude(int idx1, int idx2) const {
00252 return sqrt( Entry(idx1)*Entry(idx1) + Entry(idx2)*Entry(idx2) );
00253 }
00254
00258 FGColumnVector3& Normalize(void);
00259
00260
00261 struct AssignRef {
00262 AssignRef(FGColumnVector3& r, int i) : Ref(r), idx(i) {}
00263 AssignRef operator<<(const double ff) {
00264 Ref.Entry(idx) = ff;
00265 return AssignRef(Ref, idx+1);
00266 }
00267 FGColumnVector3& Ref;
00268 int idx;
00269 };
00270 AssignRef operator<<(const double ff) {
00271 Entry(1) = ff;
00272 return AssignRef(*this, 2);
00273 }
00274
00275 private:
00276 double data[3];
00277
00278 void Debug(int from);
00279 };
00280
00285 inline FGColumnVector3 operator*(double scalar, const FGColumnVector3& A) {
00286
00287 return A*scalar;
00288 }
00289
00294 ostream& operator<<(ostream& os, const FGColumnVector3& col);
00295
00296 }
00297
00298
00299 #endif