]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGMatrix.h
JSBSim tweaks.
[flightgear.git] / src / FDM / JSBSim / FGMatrix.h
index b3591b9462613108027d7e0d5d367994911dcc09..99673444ed604c2f8f37b2813fc04424bd460b03 100644 (file)
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 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
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #ifndef FGMATRIX_H
 #define FGMATRIX_H
 
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include <stdlib.h>
-#include <iostream.h>
-#include <fstream.h>
+#ifdef FGFS
+#  include <math.h>
+#  include <simgear/compiler.h>
+#  include STL_STRING
+#  include STL_FSTREAM
+#  include STL_IOSTREAM
+   SG_USING_STD(string);
+   SG_USING_STD(ostream);
+   SG_USING_STD(istream);
+   SG_USING_STD(cerr);
+   SG_USING_STD(cout);
+   SG_USING_STD(endl);
+#else
+#  include <fstream>
+#  include <cmath>
+#  include <iostream>
+#  include <string>
+   using std::string;
+   using std::ostream;
+   using std::istream;
+   using std::cerr;
+   using std::cout;
+   using std::endl;
+#endif
+
 
-/*******************************************************************************
-DEFINES
-*******************************************************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DEFINITIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+#define ID_MATRIX "$Id$"
 
-/*******************************************************************************
-CONSTANTS
-*******************************************************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+FORWARD DECLARATIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+class FGColumnVector;
 
-/*******************************************************************************
-TYPEDEFS
-*******************************************************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DECLARATION: MatrixException
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+class MatrixException /* :  public exception */
+{
+public:
+  string Message;
+};
 
-/*******************************************************************************
-GLOBALS
-*******************************************************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DECLARATION: FGMatrix
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 class FGMatrix
 {
-private:
-  double **data;
-  unsigned rows,cols;
-  bool keep;
-  char delim;
-  int width,prec,origin;
-  void TransposeSquare(void);
-  void TransposeNonSquare(void);
-
 public:
-  FGMatrix(unsigned rows, unsigned cols);
+  FGMatrix(unsigned int r, unsigned int c);
   FGMatrix(const FGMatrix& A);
+  FGMatrix(void) {};
   ~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];}
 
-  unsigned FGMatrix::Rows(void) const;
-  unsigned FGMatrix::Cols(void) const;
+  FGColumnVector operator*(const FGColumnVector& Col);
 
-  void FGMatrix::T(void);
+  unsigned int Rows(void) const;
+  unsigned int Cols(void) const;
+
+  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);
+
+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);
 };
 
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DECLARATION: FGColumnVector
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
 class FGColumnVector : public FGMatrix
 {
 public:
   FGColumnVector(void);
   FGColumnVector(int m);
-  FGColumnVector(FGColumnVector& b);
-  ~FGColumnVector();
+  FGColumnVector(const FGColumnVector& b);
+  ~FGColumnVector(void);
+
+  FGColumnVector operator*(const double scalar);
+  FGColumnVector operator*(const FGColumnVector& V);   // Cross product operator
+  FGColumnVector operator/(const double scalar);
+  FGColumnVector operator+(const FGColumnVector& B); // must not return reference
+  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);
+  double& operator()(int m) const;
+
+  FGColumnVector multElementWise(const FGColumnVector& V);
+
+private:
+  void Debug(void);
 };
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 #endif