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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
26 # include <simgear/compiler.h>
29 # include STL_IOSTREAM
31 SG_USING_STD(ostream);
32 SG_USING_STD(istream);
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 #define ID_MATRIX "$Id$"
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 DECLARATION: MatrixException
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 class MatrixException /* : public exception */
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79 FGMatrix(unsigned int r, unsigned int c);
80 FGMatrix(const FGMatrix& A);
84 FGMatrix& operator=(const FGMatrix& A);
85 inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
87 FGColumnVector operator*(const FGColumnVector& Col);
89 unsigned int Rows(void) const;
90 unsigned int Cols(void) const;
93 void InitMatrix(void);
94 void InitMatrix(double value);
96 FGMatrix operator-(const FGMatrix& B);
97 FGMatrix operator+(const FGMatrix& B);
98 FGMatrix operator*(const FGMatrix& B);
99 FGMatrix operator/(const double scalar);
100 FGMatrix& operator<<(const float ff);
102 friend ostream& operator<<(ostream& os, const FGMatrix& M);
103 friend istream& operator>>(istream& is, FGMatrix& M);
105 void operator-=(const FGMatrix &B);
106 void operator+=(const FGMatrix &B);
107 void operator*=(const FGMatrix &B);
108 void operator*=(const double scalar);
109 void operator/=(const double scalar);
111 friend FGMatrix operator*(double scalar,FGMatrix& A);
113 void SetOParams(char delim,int width,int prec, int origin=0);
117 unsigned int rows,cols;
121 int width,prec,origin;
122 void TransposeSquare(void);
123 void TransposeNonSquare(void);
124 unsigned int rowCtr, colCtr;
128 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 DECLARATION: FGColumnVector
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
132 class FGColumnVector : public FGMatrix
135 FGColumnVector(void);
136 FGColumnVector(int m);
137 FGColumnVector(const FGColumnVector& b);
138 ~FGColumnVector(void);
140 FGColumnVector operator*(const double scalar);
141 FGColumnVector operator*(const FGColumnVector& V); // Cross product operator
142 FGColumnVector operator/(const double scalar);
143 FGColumnVector operator+(const FGColumnVector& B); // must not return reference
144 FGColumnVector operator-(const FGColumnVector& B);
145 float Magnitude(void);
146 FGColumnVector Normalize(void);
148 friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
149 friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
151 double& operator()(int m) const;
153 FGColumnVector multElementWise(const FGColumnVector& V);
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%