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
00036 #ifndef FGMATRIX33_H
00037 #define FGMATRIX33_H
00038
00039
00040
00041
00042
00043 #include <cstdlib>
00044 #include <string>
00045 #include <fstream>
00046 #include <iostream>
00047 #include <cmath>
00048
00049 using std::ostream;
00050 using std::istream;
00051 using std::cerr;
00052 using std::cout;
00053 using std::endl;
00054 using std::string;
00055
00056 #include "FGColumnVector3.h"
00057 #include "FGJSBBase.h"
00058
00059
00060
00061
00062
00063 #define ID_MATRIX33 "$Id: FGMatrix33.h,v 1.5 2008/07/22 02:42:17 jberndt Exp $"
00064
00065
00066
00067
00068
00069 namespace JSBSim {
00070
00071 class FGColumnVector3;
00072
00073
00074
00075
00076
00080
00081
00082
00083
00084 class MatrixException : public FGJSBBase
00085 {
00086 public:
00087 string Message;
00088 };
00089
00090
00091
00092
00093
00098
00099
00100
00101
00102 class FGMatrix33 : public FGJSBBase
00103 {
00104 public:
00105
00106 enum {
00107 eRows = 3,
00108 eColumns = 3
00109 };
00110
00115 FGMatrix33(void);
00116
00123 FGMatrix33(const FGMatrix33& M) {
00124 Entry(1,1) = M.Entry(1,1);
00125 Entry(2,1) = M.Entry(2,1);
00126 Entry(3,1) = M.Entry(3,1);
00127 Entry(1,2) = M.Entry(1,2);
00128 Entry(2,2) = M.Entry(2,2);
00129 Entry(3,2) = M.Entry(3,2);
00130 Entry(1,3) = M.Entry(1,3);
00131 Entry(2,3) = M.Entry(2,3);
00132 Entry(3,3) = M.Entry(3,3);
00133
00134 Debug(0);
00135 }
00136
00151 FGMatrix33(double m11, double m12, double m13,
00152 double m21, double m22, double m23,
00153 double m31, double m32, double m33) {
00154 Entry(1,1) = m11;
00155 Entry(2,1) = m21;
00156 Entry(3,1) = m31;
00157 Entry(1,2) = m12;
00158 Entry(2,2) = m22;
00159 Entry(3,2) = m32;
00160 Entry(1,3) = m13;
00161 Entry(2,3) = m23;
00162 Entry(3,3) = m33;
00163
00164 Debug(0);
00165 }
00166
00169 ~FGMatrix33(void) { Debug(1); }
00170
00178 double operator()(unsigned int row, unsigned int col) const {
00179 return Entry(row, col);
00180 }
00181
00191 double& operator()(unsigned int row, unsigned int col) {
00192 return Entry(row, col);
00193 }
00194
00208 double Entry(unsigned int row, unsigned int col) const {
00209 return data[(col-1)*eRows+row-1];
00210 }
00211
00225 double& Entry(unsigned int row, unsigned int col) {
00226 return data[(col-1)*eRows+row-1];
00227 }
00228
00232 unsigned int Rows(void) const { return eRows; }
00233
00237 unsigned int Cols(void) const { return eColumns; }
00238
00244 FGMatrix33 Transposed(void) const {
00245 return FGMatrix33( Entry(1,1), Entry(2,1), Entry(3,1),
00246 Entry(1,2), Entry(2,2), Entry(3,2),
00247 Entry(1,3), Entry(2,3), Entry(3,3) );
00248 }
00249
00253 void T(void);
00254
00258 void InitMatrix(void);
00259
00263 void InitMatrix(double m11, double m12, double m13,
00264 double m21, double m22, double m23,
00265 double m31, double m32, double m33) {
00266 Entry(1,1) = m11;
00267 Entry(2,1) = m21;
00268 Entry(3,1) = m31;
00269 Entry(1,2) = m12;
00270 Entry(2,2) = m22;
00271 Entry(3,2) = m32;
00272 Entry(1,3) = m13;
00273 Entry(2,3) = m23;
00274 Entry(3,3) = m33;
00275 }
00276
00280 double Determinant(void) const;
00281
00289 bool Invertible(void) const { return 0.0 != Determinant(); }
00290
00297 FGMatrix33 Inverse(void) const;
00298
00305 FGMatrix33& operator=(const FGMatrix33& A) {
00306 data[0] = A.data[0];
00307 data[1] = A.data[1];
00308 data[2] = A.data[2];
00309 data[3] = A.data[3];
00310 data[4] = A.data[4];
00311 data[5] = A.data[5];
00312 data[6] = A.data[6];
00313 data[7] = A.data[7];
00314 data[8] = A.data[8];
00315 return *this;
00316 }
00317
00326 FGColumnVector3 operator*(const FGColumnVector3& v) const;
00327
00336 FGMatrix33 operator-(const FGMatrix33& B) const;
00337
00346 FGMatrix33 operator+(const FGMatrix33& B) const;
00347
00356 FGMatrix33 operator*(const FGMatrix33& B) const;
00357
00366 FGMatrix33 operator*(const double scalar) const;
00367
00376 FGMatrix33 operator/(const double scalar) const;
00377
00386 FGMatrix33& operator-=(const FGMatrix33 &B);
00387
00396 FGMatrix33& operator+=(const FGMatrix33 &B);
00397
00406 FGMatrix33& operator*=(const FGMatrix33 &B);
00407
00416 FGMatrix33& operator*=(const double scalar);
00417
00426 FGMatrix33& operator/=(const double scalar);
00427
00428 private:
00429 double data[eRows*eColumns];
00430
00431 void Debug(int from);
00432 };
00433
00441 inline FGMatrix33 operator*(double scalar, const FGMatrix33& A) {
00442
00443 return A*scalar;
00444 }
00445
00453 ostream& operator<<(ostream& os, const FGMatrix33& M);
00454
00462 istream& operator>>(istream& is, FGMatrix33& M);
00463
00464 }
00465
00466 #endif