]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMatrix.h
5/26/2000 updated from Jon and Tony.
[flightgear.git] / src / FDM / JSBSim / FGMatrix.h
1 /*******************************************************************************
2
3 Header: FGMatrix.h
4 Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
5 Date started: Unknown
6
7 HISTORY
8 --------------------------------------------------------------------------------
9 ??/??/??   TP   Created
10 03/16/2000 JSB  Added exception throwing
11
12 ********************************************************************************
13 SENTRY
14 *******************************************************************************/
15
16 #ifndef FGMATRIX_H
17 #define FGMATRIX_H
18
19 /*******************************************************************************
20 INCLUDES
21 *******************************************************************************/
22
23 #include <stdlib.h>
24 #ifdef FGFS
25 #  include <simgear/compiler.h>
26 #  ifdef FG_HAVE_STD_INCLUDES
27 #    include <fstream>
28 #  else
29 #    include <fstream.h>
30 #  endif
31 #else
32 #  include <fstream>
33 #endif
34
35 #include <string>
36
37 /*******************************************************************************
38 FORWARD DECLARATIONS
39 *******************************************************************************/
40
41 class FGColumnVector;
42
43 /*******************************************************************************
44 DECLARATION: MatrixException
45 *******************************************************************************/
46
47 using std::string;
48 using std::ostream;
49 using std::istream;
50
51 class MatrixException /* :  public exception */  
52 {
53 public:
54   string Message;
55 };
56
57 /*******************************************************************************
58 DECLARATION: FGMatrix
59 *******************************************************************************/
60
61 class FGMatrix
62 {
63 protected:
64   double **data;
65
66 private:
67   unsigned int rows,cols;
68   char delim;
69   int width,prec,origin;
70   void TransposeSquare(void);
71   void TransposeNonSquare(void);
72   unsigned int rowCtr, colCtr;
73
74 public:
75   FGMatrix(unsigned int r, unsigned int c);
76   FGMatrix(const FGMatrix& A);
77   ~FGMatrix(void);
78
79   FGMatrix& operator=(const FGMatrix& A);
80   inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
81
82   FGColumnVector operator*(const FGColumnVector& Col);
83
84   unsigned int Rows(void) const;
85   unsigned int Cols(void) const;
86
87   void T(void);
88   void InitMatrix(void);
89   void InitMatrix(double value);
90
91   FGMatrix operator-(const FGMatrix& B);
92   FGMatrix operator+(const FGMatrix& B);
93   FGMatrix operator*(const FGMatrix& B);
94   FGMatrix operator/(const double scalar);
95   FGMatrix& operator<<(const float ff);
96
97   friend ostream& operator<<(ostream& os, const FGMatrix& M);
98   friend istream& operator>>(istream& is, FGMatrix& M);
99
100   void operator-=(const FGMatrix &B);
101   void operator+=(const FGMatrix &B);
102   void operator*=(const FGMatrix &B);
103   void operator*=(const double scalar);
104   void operator/=(const double scalar);
105
106   friend FGMatrix operator*(double scalar,FGMatrix& A);
107
108   void SetOParams(char delim,int width,int prec, int origin=0);
109 };
110
111 /*******************************************************************************
112 DECLARATION: FGColumnVector
113 *******************************************************************************/
114
115 class FGColumnVector : public FGMatrix
116 {
117 public:
118   FGColumnVector(void);
119   FGColumnVector(int m);
120   FGColumnVector(const FGColumnVector& b);
121   ~FGColumnVector();
122
123   FGColumnVector operator*(const double scalar);
124   FGColumnVector operator*(const FGColumnVector& V);   // Cross product operator
125   FGColumnVector operator/(const double scalar);
126   FGColumnVector operator+(const FGColumnVector& B);
127   FGColumnVector operator-(const FGColumnVector& B);
128   float Magnitude(void);
129   FGColumnVector Normalize(void);
130
131   friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
132   friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
133
134   double& operator()(int m) const;
135 };
136
137 /******************************************************************************/
138 #endif