]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMatrix.h
Latest round of JSBSim updates.
[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 #    include <cmath>
29 #    include <iostream>
30 #  else
31 #    include <fstream.h>
32 #    include <math.h>
33 #    include <iostream.h>
34 #  endif
35 #else
36 #  include <fstream>
37 #  include <cmath>
38 #  include <iostream>
39 #endif
40
41 #include <string>
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_MATRIX "$Id$"
48
49 using std::string;
50 using std::ostream;
51 using std::istream;
52 using std::cerr;
53 using std::endl;
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 FORWARD DECLARATIONS
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59 class FGColumnVector;
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 DECLARATION: MatrixException
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 class MatrixException /* :  public exception */
66 {
67 public:
68   string Message;
69 };
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 DECLARATION: FGMatrix
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 class FGMatrix
76 {
77 public:
78   FGMatrix(unsigned int r, unsigned int c);
79   FGMatrix(const FGMatrix& A);
80   FGMatrix(void) {};
81   ~FGMatrix(void);
82
83   FGMatrix& operator=(const FGMatrix& A);
84   inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
85
86   FGColumnVector operator*(const FGColumnVector& Col);
87
88   unsigned int Rows(void) const;
89   unsigned int Cols(void) const;
90
91   void T(void);
92   void InitMatrix(void);
93   void InitMatrix(double value);
94
95   FGMatrix operator-(const FGMatrix& B);
96   FGMatrix operator+(const FGMatrix& B);
97   FGMatrix operator*(const FGMatrix& B);
98   FGMatrix operator/(const double scalar);
99   FGMatrix& operator<<(const float ff);
100
101   friend ostream& operator<<(ostream& os, const FGMatrix& M);
102   friend istream& operator>>(istream& is, FGMatrix& M);
103
104   void operator-=(const FGMatrix &B);
105   void operator+=(const FGMatrix &B);
106   void operator*=(const FGMatrix &B);
107   void operator*=(const double scalar);
108   void operator/=(const double scalar);
109
110   friend FGMatrix operator*(double scalar,FGMatrix& A);
111
112   void SetOParams(char delim,int width,int prec, int origin=0);
113
114 protected:
115   double **data;
116   unsigned int rows,cols;
117
118 private:
119   char delim;
120   int width,prec,origin;
121   void TransposeSquare(void);
122   void TransposeNonSquare(void);
123   unsigned int rowCtr, colCtr;
124   void Debug(void);
125 };
126
127 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 DECLARATION: FGColumnVector
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
130
131 class FGColumnVector : public FGMatrix
132 {
133 public:
134   FGColumnVector(void);
135   FGColumnVector(int m);
136   FGColumnVector(const FGColumnVector& b);
137   ~FGColumnVector(void);
138
139   FGColumnVector operator*(const double scalar);
140   FGColumnVector& operator*(const FGColumnVector& V);   // Cross product operator
141   FGColumnVector operator/(const double scalar);
142   FGColumnVector operator+(const FGColumnVector& B); // must not return reference
143   FGColumnVector operator-(const FGColumnVector& B);
144   float Magnitude(void);
145   FGColumnVector Normalize(void);
146
147   friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
148   friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
149
150   double& operator()(int m) const;
151   
152   FGColumnVector& multElementWise(const FGColumnVector& V);
153
154 private:
155   void Debug(void);
156 };
157
158 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 DECLARATION: FGMatrix3x3
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
161
162 class FGMatrix3x3 : public FGMatrix
163 {
164 public:
165   FGMatrix3x3(void) {FGMatrix(3,3);}
166 //  ~FGMatrix3x3(void) {~FGMatrix();}
167 };
168
169 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 DECLARATION: FGColumnVector4
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
172
173 class FGColumnVector4 : public FGColumnVector
174 {
175 public:
176   FGColumnVector4(void) {FGColumnVector(4);}
177 //  ~FGColumnVector4(void) {~FGColumnVector();}
178 };
179
180 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 DECLARATION: FGColumnVector3
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
183
184 class FGColumnVector3 : public FGColumnVector
185 {
186 public:
187   FGColumnVector3(void) {FGColumnVector(3);}
188 //  ~FGColumnVector3(void) {~FGColumnVector();}
189 };
190
191 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 #endif