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