1999-02-13 01:12:03 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
Header: FGMatrix.h
|
2000-04-24 23:49:06 +00:00
|
|
|
Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
|
1999-02-13 01:12:03 +00:00
|
|
|
Date started: Unknown
|
|
|
|
|
|
|
|
HISTORY
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
??/??/?? TP Created
|
2000-04-24 23:49:06 +00:00
|
|
|
03/16/2000 JSB Added exception throwing
|
1999-02-13 01:12:03 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
********************************************************************************
|
1999-02-13 01:12:03 +00:00
|
|
|
SENTRY
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef FGMATRIX_H
|
|
|
|
#define FGMATRIX_H
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
INCLUDES
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-04-24 23:49:06 +00:00
|
|
|
#ifdef FGFS
|
|
|
|
# include <simgear/compiler.h>
|
|
|
|
# include STL_STRING
|
|
|
|
# ifdef FG_HAVE_STD_INCLUDES
|
|
|
|
# include <fstream>
|
|
|
|
# else
|
|
|
|
# include <fstream.h>
|
|
|
|
# endif
|
|
|
|
FG_USING_STD(string);
|
|
|
|
#else
|
|
|
|
# include <string>
|
|
|
|
# include <fstream>
|
|
|
|
#endif
|
1999-02-13 01:12:03 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
2000-04-24 23:49:06 +00:00
|
|
|
FORWARD DECLARATIONS
|
1999-02-13 01:12:03 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
class FGColumnVector;
|
1999-02-13 01:12:03 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
2000-04-24 23:49:06 +00:00
|
|
|
DECLARATION: MatrixException
|
1999-02-13 01:12:03 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
using namespace std;
|
1999-02-13 01:12:03 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
class MatrixException /* : public exception */
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
string Message;
|
|
|
|
};
|
1999-02-13 01:12:03 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
2000-04-24 23:49:06 +00:00
|
|
|
DECLARATION: FGMatrix
|
1999-02-13 01:12:03 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
class FGMatrix
|
|
|
|
{
|
2000-04-24 23:49:06 +00:00
|
|
|
protected:
|
1999-02-13 01:12:03 +00:00
|
|
|
double **data;
|
2000-04-24 23:49:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int rows,cols;
|
1999-02-13 01:12:03 +00:00
|
|
|
char delim;
|
|
|
|
int width,prec,origin;
|
|
|
|
void TransposeSquare(void);
|
|
|
|
void TransposeNonSquare(void);
|
2000-04-24 23:49:06 +00:00
|
|
|
unsigned int rowCtr, colCtr;
|
1999-02-13 01:12:03 +00:00
|
|
|
|
|
|
|
public:
|
2000-04-24 23:49:06 +00:00
|
|
|
FGMatrix(unsigned int r, unsigned int c);
|
1999-02-13 01:12:03 +00:00
|
|
|
FGMatrix(const FGMatrix& A);
|
|
|
|
~FGMatrix(void);
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
FGMatrix& operator=(const FGMatrix& A);
|
|
|
|
inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
|
1999-02-13 01:12:03 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
FGColumnVector operator*(const FGColumnVector& Col);
|
1999-02-13 01:12:03 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
unsigned int Rows(void) const;
|
|
|
|
unsigned int Cols(void) const;
|
|
|
|
|
|
|
|
void T(void);
|
1999-02-13 01:12:03 +00:00
|
|
|
void InitMatrix(void);
|
|
|
|
void InitMatrix(double value);
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
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 ostream& operator<<(ostream& os, const FGMatrix& M);
|
|
|
|
friend istream& operator>>(istream& is, FGMatrix& M);
|
1999-02-13 01:12:03 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
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);
|
1999-02-13 01:12:03 +00:00
|
|
|
|
|
|
|
void SetOParams(char delim,int width,int prec, int origin=0);
|
|
|
|
};
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
DECLARATION: FGColumnVector
|
|
|
|
*******************************************************************************/
|
|
|
|
|
1999-02-13 01:12:03 +00:00
|
|
|
class FGColumnVector : public FGMatrix
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FGColumnVector(void);
|
|
|
|
FGColumnVector(int m);
|
2000-04-24 23:49:06 +00:00
|
|
|
FGColumnVector(const FGColumnVector& b);
|
1999-02-13 01:12:03 +00:00
|
|
|
~FGColumnVector();
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
FGColumnVector operator*(const double scalar);
|
|
|
|
FGColumnVector operator/(const double scalar);
|
|
|
|
FGColumnVector operator+(const FGColumnVector& B);
|
|
|
|
float Magnitude(void);
|
|
|
|
FGColumnVector Normalize(void);
|
|
|
|
|
|
|
|
friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
|
|
|
|
|
|
|
|
double& operator()(int m) const;
|
1999-02-13 01:12:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
#endif
|