1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
8 --------------------------------------------------------------------------------
10 03/16/2000 JSB Added exception throwing
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
19 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
25 # include <simgear/compiler.h>
26 # ifdef FG_HAVE_STD_INCLUDES
33 # include <iostream.h>
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_MATRIX "$Id$"
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 DECLARATION: MatrixException
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 class MatrixException /* : public exception */
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78 FGMatrix(unsigned int r, unsigned int c);
79 FGMatrix(const FGMatrix& A);
83 FGMatrix& operator=(const FGMatrix& A);
84 inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
86 FGColumnVector operator*(const FGColumnVector& Col);
88 unsigned int Rows(void) const;
89 unsigned int Cols(void) const;
92 void InitMatrix(void);
93 void InitMatrix(double value);
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);
101 friend ostream& operator<<(ostream& os, const FGMatrix& M);
102 friend istream& operator>>(istream& is, FGMatrix& M);
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);
110 friend FGMatrix operator*(double scalar,FGMatrix& A);
112 void SetOParams(char delim,int width,int prec, int origin=0);
116 unsigned int rows,cols;
120 int width,prec,origin;
121 void TransposeSquare(void);
122 void TransposeNonSquare(void);
123 unsigned int rowCtr, colCtr;
127 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 DECLARATION: FGColumnVector
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
131 class FGColumnVector : public FGMatrix
134 FGColumnVector(void);
135 FGColumnVector(int m);
136 FGColumnVector(const FGColumnVector& b);
137 ~FGColumnVector(void);
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);
147 friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
148 friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
150 double& operator()(int m) const;
152 FGColumnVector& multElementWise(const FGColumnVector& V);
158 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 DECLARATION: FGMatrix3x3
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
162 class FGMatrix3x3 : public FGMatrix
165 FGMatrix3x3(void) {FGMatrix(3,3);}
166 // ~FGMatrix3x3(void) {~FGMatrix();}
169 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 DECLARATION: FGColumnVector4
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
173 class FGColumnVector4 : public FGColumnVector
176 FGColumnVector4(void) {FGColumnVector(4);}
177 // ~FGColumnVector4(void) {~FGColumnVector();}
180 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 DECLARATION: FGColumnVector3
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
184 class FGColumnVector3 : public FGColumnVector
187 FGColumnVector3(void) {FGColumnVector(3);}
188 // ~FGColumnVector3(void) {~FGColumnVector();}
191 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%