1
0
Fork 0
flightgear/src/FDM/JSBSim/FGMatrix.h

151 lines
4.1 KiB
C
Raw Normal View History

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>
# ifdef FG_HAVE_STD_INCLUDES
# include <fstream>
2000-07-06 21:02:46 +00:00
# include <cmath>
2000-10-02 23:07:30 +00:00
# include <iostream>
2000-04-24 23:49:06 +00:00
# else
# include <fstream.h>
2000-07-06 21:02:46 +00:00
# include <math.h>
2000-10-02 23:07:30 +00:00
# include <iostream.h>
2000-04-24 23:49:06 +00:00
# endif
#else
# include <fstream>
2000-07-06 21:02:46 +00:00
# include <cmath>
2000-10-02 23:07:30 +00:00
# include <iostream>
2000-04-24 23:49:06 +00:00
#endif
1999-02-13 01:12:03 +00:00
#include <string>
#define ID_MATRIX "$Header"
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
*******************************************************************************/
using std::string;
using std::ostream;
using std::istream;
2000-10-02 23:07:30 +00:00
using std::cerr;
using std::endl;
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);
2000-05-27 05:48:14 +00:00
FGColumnVector operator*(const FGColumnVector& V); // Cross product operator
2000-04-24 23:49:06 +00:00
FGColumnVector operator/(const double scalar);
FGColumnVector operator+(const FGColumnVector& B);
FGColumnVector operator-(const FGColumnVector& B);
float Magnitude(void);
2000-04-24 23:49:06 +00:00
FGColumnVector Normalize(void);
friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
2000-04-24 23:49:06 +00:00
double& operator()(int m) const;
2000-07-06 21:02:46 +00:00
FGColumnVector multElementWise(const FGColumnVector& V);
1999-02-13 01:12:03 +00:00
};
/******************************************************************************/
#endif