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

193 lines
5.4 KiB
C
Raw Normal View History

2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-13 01:12:03 +00:00
SENTRY
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-13 01:12:03 +00:00
#ifndef FGMATRIX_H
#define FGMATRIX_H
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-13 01:12:03 +00:00
INCLUDES
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-13 01:12:03 +00:00
#include <stdlib.h>
2000-04-24 23:49:06 +00:00
#ifdef FGFS
# include <simgear/compiler.h>
2001-03-30 01:04:50 +00:00
# ifdef FG_HAVE_STD_INCLUDES
2000-04-24 23:49:06 +00:00
# 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>
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-13 01:12:03 +00:00
2001-03-30 01:04:50 +00:00
#define ID_MATRIX "$Id$"
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-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class FGColumnVector;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DECLARATION: MatrixException
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class MatrixException /* : public exception */
2000-04-24 23:49:06 +00:00
{
public:
string Message;
};
1999-02-13 01:12:03 +00:00
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-04-24 23:49:06 +00:00
DECLARATION: FGMatrix
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-13 01:12:03 +00:00
class FGMatrix
{
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);
2001-03-30 01:04:50 +00:00
FGMatrix(void) {};
1999-02-13 01:12:03 +00:00
~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);
2001-03-30 01:04:50 +00:00
protected:
double **data;
unsigned int rows,cols;
private:
char delim;
int width,prec,origin;
void TransposeSquare(void);
void TransposeNonSquare(void);
unsigned int rowCtr, colCtr;
void Debug(void);
1999-02-13 01:12:03 +00:00
};
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-04-24 23:49:06 +00:00
DECLARATION: FGColumnVector
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
2000-04-24 23:49:06 +00:00
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);
2001-03-30 01:04:50 +00:00
~FGColumnVector(void);
1999-02-13 01:12:03 +00:00
2000-04-24 23:49:06 +00:00
FGColumnVector operator*(const double scalar);
2001-03-30 01:04:50 +00:00
FGColumnVector& operator*(const FGColumnVector& V); // Cross product operator
2000-04-24 23:49:06 +00:00
FGColumnVector operator/(const double scalar);
2001-03-30 01:04:50 +00:00
FGColumnVector operator+(const FGColumnVector& B); // must not return reference
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
2001-03-30 01:04:50 +00:00
FGColumnVector& multElementWise(const FGColumnVector& V);
private:
void Debug(void);
};
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DECLARATION: FGMatrix3x3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class FGMatrix3x3 : public FGMatrix
{
public:
FGMatrix3x3(void) {FGMatrix(3,3);}
// ~FGMatrix3x3(void) {~FGMatrix();}
};
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DECLARATION: FGColumnVector4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class FGColumnVector4 : public FGColumnVector
{
public:
FGColumnVector4(void) {FGColumnVector(4);}
// ~FGColumnVector4(void) {~FGColumnVector();}
};
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DECLARATION: FGColumnVector3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class FGColumnVector3 : public FGColumnVector
{
public:
FGColumnVector3(void) {FGColumnVector(3);}
// ~FGColumnVector3(void) {~FGColumnVector();}
1999-02-13 01:12:03 +00:00
};
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-13 01:12:03 +00:00
#endif