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