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

163 lines
4.5 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 <math.h>
2000-04-24 23:49:06 +00:00
# include <simgear/compiler.h>
2001-04-02 03:12:38 +00:00
# include STL_STRING
# include STL_FSTREAM
# include STL_IOSTREAM
2001-04-02 03:12:38 +00:00
SG_USING_STD(string);
# if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
SG_USING_STD(ostream);
SG_USING_STD(istream);
SG_USING_STD(cerr);
SG_USING_STD(cout);
SG_USING_STD(endl);
# endif
2000-04-24 23:49:06 +00:00
#else
# include <fstream>
2000-07-06 21:02:46 +00:00
# include <cmath>
2000-10-02 23:07:30 +00:00
# include <iostream>
2001-04-02 03:12:38 +00:00
# include <string>
using std::string;
using std::ostream;
using std::istream;
using std::cerr;
using std::cout;
2001-04-02 03:12:38 +00:00
using std::endl;
2000-04-24 23:49:06 +00:00
#endif
1999-02-13 01:12:03 +00:00
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
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);
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;
2001-04-02 03:12:38 +00:00
FGColumnVector multElementWise(const FGColumnVector& V);
2001-03-30 01:04:50 +00:00
private:
void Debug(void);
};
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-13 01:12:03 +00:00
#endif