JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGMatrix33.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3 Header: FGMatrix33.h
4 Author: Tony Peden, Jon Berndt, Mathias Frolich
5 Date started: Unknown
6 
7  ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25 
26 HISTORY
27 --------------------------------------------------------------------------------
28 ??/??/?? TP Created
29 03/16/2000 JSB Added exception throwing
30 03/06/2004 MF Rework of the code to make it a bit compiler friendlier
31 
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 SENTRY
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
35 
36 #ifndef FGMATRIX33_H
37 #define FGMATRIX33_H
38 
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 INCLUDES
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 
43 #include <string>
44 #include <iosfwd>
45 
46 #include "FGColumnVector3.h"
47 
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 
52 #define ID_MATRIX33 "$Id: FGMatrix33.h,v 1.17 2012/11/22 22:04:06 bcoconni Exp $"
53 
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 
58 namespace JSBSim {
59 
60 class FGColumnVector3;
61 class FGQuaternion;
62 
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 DECLARATION: MatrixException
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73 
74 class MatrixException //: public FGJSBBase
75 {
76 public:
77  std::string Message;
78 };
79 
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 CLASS DOCUMENTATION
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83 
88 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 DECLARATION: FGMatrix33
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
91 
93 {
94 public:
95 
96  enum {
97  eRows = 3,
98  eColumns = 3
99  };
100 
105  FGMatrix33(void);
106 
114  {
115  data[0] = M.data[0];
116  data[1] = M.data[1];
117  data[2] = M.data[2];
118  data[3] = M.data[3];
119  data[4] = M.data[4];
120  data[5] = M.data[5];
121  data[6] = M.data[6];
122  data[7] = M.data[7];
123  data[8] = M.data[8];
124  }
125 
140  FGMatrix33(const double m11, const double m12, const double m13,
141  const double m21, const double m22, const double m23,
142  const double m31, const double m32, const double m33)
143  {
144  data[0] = m11;
145  data[1] = m21;
146  data[2] = m31;
147  data[3] = m12;
148  data[4] = m22;
149  data[5] = m32;
150  data[6] = m13;
151  data[7] = m23;
152  data[8] = m33;
153  }
154 
157  ~FGMatrix33(void) {}
158 
162  std::string Dump(const std::string& delimeter) const;
163 
168  std::string Dump(const std::string& delimiter, const std::string& prefix) const;
169 
177  double operator()(unsigned int row, unsigned int col) const {
178  return data[(col-1)*eRows+row-1];
179  }
180 
190  double& operator()(unsigned int row, unsigned int col) {
191  return data[(col-1)*eRows+row-1];
192  }
193 
207  double Entry(unsigned int row, unsigned int col) const {
208  return data[(col-1)*eRows+row-1];
209  }
210 
224  double& Entry(unsigned int row, unsigned int col) {
225  return data[(col-1)*eRows+row-1];
226  }
227 
231  unsigned int Rows(void) const { return eRows; }
232 
236  unsigned int Cols(void) const { return eColumns; }
237 
243  FGMatrix33 Transposed(void) const {
244  return FGMatrix33( data[0], data[1], data[2],
245  data[3], data[4], data[5],
246  data[6], data[7], data[8] );
247  }
248 
252  void T(void);
253 
257  void InitMatrix(void);
258 
262  void InitMatrix(const double m11, const double m12, const double m13,
263  const double m21, const double m22, const double m23,
264  const double m31, const double m32, const double m33)
265  {
266  data[0] = m11;
267  data[1] = m21;
268  data[2] = m31;
269  data[3] = m12;
270  data[4] = m22;
271  data[5] = m32;
272  data[6] = m13;
273  data[7] = m23;
274  data[8] = m33;
275  }
276 
279  FGQuaternion GetQuaternion(void) const;
280 
283  FGColumnVector3 GetEuler() const;
284 
288  double Determinant(void) const;
289 
297  bool Invertible(void) const { return 0.0 != Determinant(); }
298 
305  FGMatrix33 Inverse(void) const;
306 
314  {
315  data[0] = A.data[0];
316  data[1] = A.data[1];
317  data[2] = A.data[2];
318  data[3] = A.data[3];
319  data[4] = A.data[4];
320  data[5] = A.data[5];
321  data[6] = A.data[6];
322  data[7] = A.data[7];
323  data[8] = A.data[8];
324  return *this;
325  }
326 
335  FGColumnVector3 operator*(const FGColumnVector3& v) const;
336 
345  FGMatrix33 operator-(const FGMatrix33& B) const;
346 
355  FGMatrix33 operator+(const FGMatrix33& B) const;
356 
365  FGMatrix33 operator*(const FGMatrix33& B) const;
366 
375  FGMatrix33 operator*(const double scalar) const;
376 
385  FGMatrix33 operator/(const double scalar) const;
386 
395  FGMatrix33& operator-=(const FGMatrix33 &B);
396 
405  FGMatrix33& operator+=(const FGMatrix33 &B);
406 
415  FGMatrix33& operator*=(const FGMatrix33 &B);
416 
425  FGMatrix33& operator*=(const double scalar);
426 
435  FGMatrix33& operator/=(const double scalar);
436 
437 private:
438  double data[eRows*eColumns];
439 };
440 
448 inline FGMatrix33 operator*(double scalar, const FGMatrix33& A) {
449  // use already defined operation.
450  return A*scalar;
451 }
452 
460 std::ostream& operator<<(std::ostream& os, const FGMatrix33& M);
461 
469 std::istream& operator>>(std::istream& is, FGMatrix33& M);
470 
471 } // namespace JSBSim
472 #endif
Models the Quaternion representation of rotations.
Definition: FGQuaternion.h:92
~FGMatrix33(void)
Destructor.
Definition: FGMatrix33.h:157
unsigned int Cols(void) const
Number of cloumns in the matrix.
Definition: FGMatrix33.h:236
double & Entry(unsigned int row, unsigned int col)
Write access the entries of the matrix.
Definition: FGMatrix33.h:224
FGMatrix33(const double m11, const double m12, const double m13, const double m21, const double m22, const double m23, const double m31, const double m32, const double m33)
Initialization by given values.
Definition: FGMatrix33.h:140
double & operator()(unsigned int row, unsigned int col)
Write access the entries of the matrix.
Definition: FGMatrix33.h:190
void InitMatrix(const double m11, const double m12, const double m13, const double m21, const double m22, const double m23, const double m31, const double m32, const double m33)
Initialize the matrix.
Definition: FGMatrix33.h:262
FGMatrix33 & operator=(const FGMatrix33 &A)
Assignment operator.
Definition: FGMatrix33.h:313
bool Invertible(void) const
Return if the matrix is invertible.
Definition: FGMatrix33.h:297
double Entry(unsigned int row, unsigned int col) const
Read access the entries of the matrix.
Definition: FGMatrix33.h:207
This class implements a 3 element column vector.
FGMatrix33(const FGMatrix33 &M)
Copy constructor.
Definition: FGMatrix33.h:113
unsigned int Rows(void) const
Number of rows in the matrix.
Definition: FGMatrix33.h:231
Handles matrix math operations.
Definition: FGMatrix33.h:92
FGMatrix33 Transposed(void) const
Transposed matrix.
Definition: FGMatrix33.h:243
Exception convenience class.
Definition: FGMatrix33.h:74
double operator()(unsigned int row, unsigned int col) const
Read access the entries of the matrix.
Definition: FGMatrix33.h:177