]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMatrix.h
Friday the 13th JSBSim update ... :-0 !!!
[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 #define ID_MATRIX "$Header"
44
45 /*******************************************************************************
46 FORWARD DECLARATIONS
47 *******************************************************************************/
48
49 class FGColumnVector;
50
51 /*******************************************************************************
52 DECLARATION: MatrixException
53 *******************************************************************************/
54
55 using std::string;
56 using std::ostream;
57 using std::istream;
58 using std::cerr;
59 using std::endl;
60
61 class MatrixException /* :  public exception */  
62 {
63 public:
64   string Message;
65 };
66
67 /*******************************************************************************
68 DECLARATION: FGMatrix
69 *******************************************************************************/
70
71 class FGMatrix
72 {
73 protected:
74   double **data;
75
76 private:
77   unsigned int rows,cols;
78   char delim;
79   int width,prec,origin;
80   void TransposeSquare(void);
81   void TransposeNonSquare(void);
82   unsigned int rowCtr, colCtr;
83
84 public:
85   FGMatrix(unsigned int r, unsigned int c);
86   FGMatrix(const FGMatrix& A);
87   ~FGMatrix(void);
88
89   FGMatrix& operator=(const FGMatrix& A);
90   inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
91
92   FGColumnVector operator*(const FGColumnVector& Col);
93
94   unsigned int Rows(void) const;
95   unsigned int Cols(void) const;
96
97   void T(void);
98   void InitMatrix(void);
99   void InitMatrix(double value);
100
101   FGMatrix operator-(const FGMatrix& B);
102   FGMatrix operator+(const FGMatrix& B);
103   FGMatrix operator*(const FGMatrix& B);
104   FGMatrix operator/(const double scalar);
105   FGMatrix& operator<<(const float ff);
106
107   friend ostream& operator<<(ostream& os, const FGMatrix& M);
108   friend istream& operator>>(istream& is, FGMatrix& M);
109
110   void operator-=(const FGMatrix &B);
111   void operator+=(const FGMatrix &B);
112   void operator*=(const FGMatrix &B);
113   void operator*=(const double scalar);
114   void operator/=(const double scalar);
115
116   friend FGMatrix operator*(double scalar,FGMatrix& A);
117
118   void SetOParams(char delim,int width,int prec, int origin=0);
119 };
120
121 /*******************************************************************************
122 DECLARATION: FGColumnVector
123 *******************************************************************************/
124
125 class FGColumnVector : public FGMatrix
126 {
127 public:
128   FGColumnVector(void);
129   FGColumnVector(int m);
130   FGColumnVector(const FGColumnVector& b);
131   ~FGColumnVector();
132
133   FGColumnVector operator*(const double scalar);
134   FGColumnVector operator*(const FGColumnVector& V);   // Cross product operator
135   FGColumnVector operator/(const double scalar);
136   FGColumnVector operator+(const FGColumnVector& B);
137   FGColumnVector operator-(const FGColumnVector& B);
138   float Magnitude(void);
139   FGColumnVector Normalize(void);
140
141   friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
142   friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
143
144   double& operator()(int m) const;
145   
146   FGColumnVector multElementWise(const FGColumnVector& V);
147 };
148
149 /******************************************************************************/
150 #endif