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 # if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
32 SG_USING_STD(ostream);
33 SG_USING_STD(istream);
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 #define ID_MATRIX "$Id$"
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 DECLARATION: MatrixException
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 class MatrixException /* : public exception */
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81 FGMatrix(unsigned int r, unsigned int c);
82 FGMatrix(const FGMatrix& A);
86 FGMatrix& operator=(const FGMatrix& A);
87 inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
89 FGColumnVector operator*(const FGColumnVector& Col);
91 unsigned int Rows(void) const;
92 unsigned int Cols(void) const;
95 void InitMatrix(void);
96 void InitMatrix(double value);
98 FGMatrix operator-(const FGMatrix& B);
99 FGMatrix operator+(const FGMatrix& B);
100 FGMatrix operator*(const FGMatrix& B);
101 FGMatrix operator/(const double scalar);
102 FGMatrix& operator<<(const float ff);
104 friend ostream& operator<<(ostream& os, const FGMatrix& M);
105 friend istream& operator>>(istream& is, FGMatrix& M);
107 void operator-=(const FGMatrix &B);
108 void operator+=(const FGMatrix &B);
109 void operator*=(const FGMatrix &B);
110 void operator*=(const double scalar);
111 void operator/=(const double scalar);
113 friend FGMatrix operator*(double scalar,FGMatrix& A);
115 void SetOParams(char delim,int width,int prec, int origin=0);
119 unsigned int rows,cols;
123 int width,prec,origin;
124 void TransposeSquare(void);
125 void TransposeNonSquare(void);
126 unsigned int rowCtr, colCtr;
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 DECLARATION: FGColumnVector
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
134 class FGColumnVector : public FGMatrix
137 FGColumnVector(void);
138 FGColumnVector(int m);
139 FGColumnVector(const FGColumnVector& b);
140 ~FGColumnVector(void);
142 FGColumnVector operator*(const double scalar);
143 FGColumnVector operator*(const FGColumnVector& V); // Cross product operator
144 FGColumnVector operator/(const double scalar);
145 FGColumnVector operator+(const FGColumnVector& B); // must not return reference
146 FGColumnVector operator-(const FGColumnVector& B);
147 float Magnitude(void);
148 FGColumnVector Normalize(void);
150 friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
151 friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
153 double& operator()(int m) const;
155 FGColumnVector multElementWise(const FGColumnVector& V);
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%