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 #define ID_MATRIX "$Header"
45 /*******************************************************************************
47 *******************************************************************************/
51 /*******************************************************************************
52 DECLARATION: MatrixException
53 *******************************************************************************/
61 class MatrixException /* : public exception */
67 /*******************************************************************************
69 *******************************************************************************/
77 unsigned int rows,cols;
79 int width,prec,origin;
80 void TransposeSquare(void);
81 void TransposeNonSquare(void);
82 unsigned int rowCtr, colCtr;
85 FGMatrix(unsigned int r, unsigned int c);
86 FGMatrix(const FGMatrix& A);
89 FGMatrix& operator=(const FGMatrix& A);
90 inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
92 FGColumnVector operator*(const FGColumnVector& Col);
94 unsigned int Rows(void) const;
95 unsigned int Cols(void) const;
98 void InitMatrix(void);
99 void InitMatrix(double value);
101 FGMatrix operator-(const FGMatrix& B);
102 FGMatrix operator+(const FGMatrix& B);
103 FGMatrix operator*(const FGMatrix& B);
104 FGMatrix operator/(const double scalar);
105 FGMatrix& operator<<(const float ff);
107 friend ostream& operator<<(ostream& os, const FGMatrix& M);
108 friend istream& operator>>(istream& is, FGMatrix& M);
110 void operator-=(const FGMatrix &B);
111 void operator+=(const FGMatrix &B);
112 void operator*=(const FGMatrix &B);
113 void operator*=(const double scalar);
114 void operator/=(const double scalar);
116 friend FGMatrix operator*(double scalar,FGMatrix& A);
118 void SetOParams(char delim,int width,int prec, int origin=0);
121 /*******************************************************************************
122 DECLARATION: FGColumnVector
123 *******************************************************************************/
125 class FGColumnVector : public FGMatrix
128 FGColumnVector(void);
129 FGColumnVector(int m);
130 FGColumnVector(const FGColumnVector& b);
133 FGColumnVector operator*(const double scalar);
134 FGColumnVector operator*(const FGColumnVector& V); // Cross product operator
135 FGColumnVector operator/(const double scalar);
136 FGColumnVector operator+(const FGColumnVector& B);
137 FGColumnVector operator-(const FGColumnVector& B);
138 float Magnitude(void);
139 FGColumnVector Normalize(void);
141 friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
142 friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
144 double& operator()(int m) const;
146 FGColumnVector multElementWise(const FGColumnVector& V);
149 /******************************************************************************/