/*******************************************************************************
Header: FGMatrix.h
-Author: Tony Peden [formatted here by Jon Berndt]
+Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
Date started: Unknown
HISTORY
--------------------------------------------------------------------------------
??/??/?? TP Created
+03/16/2000 JSB Added exception throwing
-/*******************************************************************************
+********************************************************************************
SENTRY
*******************************************************************************/
*******************************************************************************/
#include <stdlib.h>
-#include <iostream.h>
-#include <fstream.h>
-
-/*******************************************************************************
-DEFINES
-*******************************************************************************/
+#ifdef FGFS
+# include <simgear/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <fstream>
+# include <cmath>
+# else
+# include <fstream.h>
+# include <math.h>
+# endif
+#else
+# include <fstream>
+# include <cmath>
+#endif
+#include <string>
/*******************************************************************************
-CONSTANTS
+FORWARD DECLARATIONS
*******************************************************************************/
+class FGColumnVector;
/*******************************************************************************
-TYPEDEFS
+DECLARATION: MatrixException
*******************************************************************************/
+using std::string;
+using std::ostream;
+using std::istream;
+
+class MatrixException /* : public exception */
+{
+public:
+ string Message;
+};
/*******************************************************************************
-GLOBALS
+DECLARATION: FGMatrix
*******************************************************************************/
class FGMatrix
{
-private:
+protected:
double **data;
- unsigned rows,cols;
- bool keep;
+
+private:
+ unsigned int rows,cols;
char delim;
int width,prec,origin;
void TransposeSquare(void);
void TransposeNonSquare(void);
+ unsigned int rowCtr, colCtr;
public:
- FGMatrix(unsigned rows, unsigned cols);
+ FGMatrix(unsigned int r, unsigned int c);
FGMatrix(const FGMatrix& A);
~FGMatrix(void);
- FGMatrix& FGMatrix::operator=(const FGMatrix& A);
- double& FGMatrix::operator()(unsigned row, unsigned col);
+ FGMatrix& operator=(const FGMatrix& A);
+ inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
+
+ FGColumnVector operator*(const FGColumnVector& Col);
- unsigned FGMatrix::Rows(void) const;
- unsigned FGMatrix::Cols(void) const;
+ unsigned int Rows(void) const;
+ unsigned int Cols(void) const;
- void FGMatrix::T(void);
+ void T(void);
void InitMatrix(void);
void InitMatrix(double value);
- friend FGMatrix operator-(FGMatrix& A, FGMatrix& B);
- friend FGMatrix operator+(FGMatrix& A, FGMatrix& B);
- friend FGMatrix operator*(double scalar,FGMatrix& A);
- friend FGMatrix operator*(FGMatrix& Left, FGMatrix& Right);
- friend FGMatrix operator/(FGMatrix& A, double scalar);
+ FGMatrix operator-(const FGMatrix& B);
+ FGMatrix operator+(const FGMatrix& B);
+ FGMatrix operator*(const FGMatrix& B);
+ FGMatrix operator/(const double scalar);
+ FGMatrix& operator<<(const float ff);
- friend void operator-=(FGMatrix &A,FGMatrix &B);
- friend void operator+=(FGMatrix &A,FGMatrix &B);
- friend void operator*=(FGMatrix &A,FGMatrix &B);
- friend void operator*=(FGMatrix &A,double scalar);
- friend void operator/=(FGMatrix &A,double scalar);
+ friend ostream& operator<<(ostream& os, const FGMatrix& M);
+ friend istream& operator>>(istream& is, FGMatrix& M);
+
+ void operator-=(const FGMatrix &B);
+ void operator+=(const FGMatrix &B);
+ void operator*=(const FGMatrix &B);
+ void operator*=(const double scalar);
+ void operator/=(const double scalar);
+
+ friend FGMatrix operator*(double scalar,FGMatrix& A);
void SetOParams(char delim,int width,int prec, int origin=0);
};
+/*******************************************************************************
+DECLARATION: FGColumnVector
+*******************************************************************************/
+
class FGColumnVector : public FGMatrix
{
public:
FGColumnVector(void);
FGColumnVector(int m);
- FGColumnVector(FGColumnVector& b);
+ FGColumnVector(const FGColumnVector& b);
~FGColumnVector();
- double& operator()(int m);
+ FGColumnVector operator*(const double scalar);
+ FGColumnVector operator*(const FGColumnVector& V); // Cross product operator
+ FGColumnVector operator/(const double scalar);
+ FGColumnVector operator+(const FGColumnVector& B);
+ FGColumnVector operator-(const FGColumnVector& B);
+ float Magnitude(void);
+ FGColumnVector Normalize(void);
+
+ friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
+ friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
+
+ double& operator()(int m) const;
+
+ FGColumnVector multElementWise(const FGColumnVector& V);
};
/******************************************************************************/