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>
28 SG_USING_STD(ostream);
29 SG_USING_STD(istream);
32 # ifdef FG_HAVE_STD_INCLUDES
39 # include <iostream.h>
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 #define ID_MATRIX "$Id$"
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 DECLARATION: MatrixException
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 class MatrixException /* : public exception */
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83 FGMatrix(unsigned int r, unsigned int c);
84 FGMatrix(const FGMatrix& A);
88 FGMatrix& operator=(const FGMatrix& A);
89 inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
91 FGColumnVector operator*(const FGColumnVector& Col);
93 unsigned int Rows(void) const;
94 unsigned int Cols(void) const;
97 void InitMatrix(void);
98 void InitMatrix(double value);
100 FGMatrix operator-(const FGMatrix& B);
101 FGMatrix operator+(const FGMatrix& B);
102 FGMatrix operator*(const FGMatrix& B);
103 FGMatrix operator/(const double scalar);
104 FGMatrix& operator<<(const float ff);
106 friend ostream& operator<<(ostream& os, const FGMatrix& M);
107 friend istream& operator>>(istream& is, FGMatrix& M);
109 void operator-=(const FGMatrix &B);
110 void operator+=(const FGMatrix &B);
111 void operator*=(const FGMatrix &B);
112 void operator*=(const double scalar);
113 void operator/=(const double scalar);
115 friend FGMatrix operator*(double scalar,FGMatrix& A);
117 void SetOParams(char delim,int width,int prec, int origin=0);
121 unsigned int rows,cols;
125 int width,prec,origin;
126 void TransposeSquare(void);
127 void TransposeNonSquare(void);
128 unsigned int rowCtr, colCtr;
132 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 DECLARATION: FGColumnVector
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
136 class FGColumnVector : public FGMatrix
139 FGColumnVector(void);
140 FGColumnVector(int m);
141 FGColumnVector(const FGColumnVector& b);
142 ~FGColumnVector(void);
144 FGColumnVector operator*(const double scalar);
145 FGColumnVector operator*(const FGColumnVector& V); // Cross product operator
146 FGColumnVector operator/(const double scalar);
147 FGColumnVector operator+(const FGColumnVector& B); // must not return reference
148 FGColumnVector operator-(const FGColumnVector& B);
149 float Magnitude(void);
150 FGColumnVector Normalize(void);
152 friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
153 friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
155 double& operator()(int m) const;
157 FGColumnVector multElementWise(const FGColumnVector& V);
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%