JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGMatrix33 Class Reference

Handles matrix math operations. More...

#include <FGMatrix33.h>

List of all members.

Public Types

enum  { eRows = 3, eColumns = 3 }

Public Member Functions

 FGMatrix33 (void)
 Default initializer.
 FGMatrix33 (const FGMatrix33 &M)
 Copy constructor.
 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.
 ~FGMatrix33 (void)
 Destructor.
unsigned int Cols (void) const
 Number of cloumns in the matrix.
double Determinant (void) const
 Determinant of the matrix.
std::string Dump (const std::string &delimeter) const
 Prints the contents of the matrix.
std::string Dump (const std::string &delimiter, const std::string &prefix) const
 Prints the contents of the matrix.
double Entry (unsigned int row, unsigned int col) const
 Read access the entries of the matrix.
double & Entry (unsigned int row, unsigned int col)
 Write access the entries of the matrix.
FGColumnVector3 GetEuler () const
 Returns the Euler angle column vector associated with this matrix.
FGQuaternion GetQuaternion (void) const
 Returns the quaternion associated with this direction cosine (rotation) matrix.
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.
void InitMatrix (void)
 Initialize the matrix.
FGMatrix33 Inverse (void) const
 Return the inverse of the matrix.
bool Invertible (void) const
 Return if the matrix is invertible.
double & operator() (unsigned int row, unsigned int col)
 Write access the entries of the matrix.
double operator() (unsigned int row, unsigned int col) const
 Read access the entries of the matrix.
FGColumnVector3 operator* (const FGColumnVector3 &v) const
 Matrix vector multiplication.
FGMatrix33 operator* (const FGMatrix33 &B) const
 Matrix product.
FGMatrix33 operator* (const double scalar) const
 Multiply the matrix with a scalar.
FGMatrix33operator*= (const FGMatrix33 &B)
 In place matrix multiplication.
FGMatrix33operator*= (const double scalar)
 In place matrix scale.
FGMatrix33 operator+ (const FGMatrix33 &B) const
 Matrix addition.
FGMatrix33operator+= (const FGMatrix33 &B)
 In place matrix addition.
FGMatrix33 operator- (const FGMatrix33 &B) const
 Matrix subtraction.
FGMatrix33operator-= (const FGMatrix33 &B)
 In place matrix subtraction.
FGMatrix33 operator/ (const double scalar) const
 Multiply the matrix with 1.0/scalar.
FGMatrix33operator/= (const double scalar)
 In place matrix scale.
FGMatrix33operator= (const FGMatrix33 &A)
 Assignment operator.
unsigned int Rows (void) const
 Number of rows in the matrix.
void T (void)
 Transposes this matrix.
FGMatrix33 Transposed (void) const
 Transposed matrix.

Detailed Description

Author:
Tony Peden, Jon Berndt, Mathias Froelich

Definition at line 92 of file FGMatrix33.h.


Constructor & Destructor Documentation

FGMatrix33 ( void  )

Create a zero matrix.

Definition at line 61 of file FGMatrix33.cpp.

Referenced by FGMatrix33::Transposed().

{
  data[0] = data[1] = data[2] = data[3] = data[4] = data[5] =
    data[6] = data[7] = data[8] = 0.0;
}

Here is the caller graph for this function:

FGMatrix33 ( const FGMatrix33 M) [inline]
Parameters:
MMatrix which is used for initialization.

Create copy of the matrix given in the argument.

Definition at line 113 of file FGMatrix33.h.

  {
    data[0] = M.data[0];
    data[1] = M.data[1];
    data[2] = M.data[2];
    data[3] = M.data[3];
    data[4] = M.data[4];
    data[5] = M.data[5];
    data[6] = M.data[6];
    data[7] = M.data[7];
    data[8] = M.data[8];
  }
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 
) [inline]
Parameters:
m11value of the 1,1 Matrix element.
m12value of the 1,2 Matrix element.
m13value of the 1,3 Matrix element.
m21value of the 2,1 Matrix element.
m22value of the 2,2 Matrix element.
m23value of the 2,3 Matrix element.
m31value of the 3,1 Matrix element.
m32value of the 3,2 Matrix element.
m33value of the 3,3 Matrix element.

Create a matrix from the doubles given in the arguments.

Definition at line 140 of file FGMatrix33.h.

  {
    data[0] = m11;
    data[1] = m21;
    data[2] = m31;
    data[3] = m12;
    data[4] = m22;
    data[5] = m32;
    data[6] = m13;
    data[7] = m23;
    data[8] = m33;
  }

Member Function Documentation

unsigned int Cols ( void  ) const [inline]
Returns:
the number of columns in the matrix.

Definition at line 236 of file FGMatrix33.h.

{ return eColumns; }
double Determinant ( void  ) const
Returns:
the determinant of the matrix.

Definition at line 219 of file FGMatrix33.cpp.

Referenced by FGMatrix33::Invertible().

                                         {
  return data[0]*data[4]*data[8] + data[3]*data[7]*data[2]
       + data[6]*data[1]*data[5] - data[6]*data[4]*data[2]
       - data[3]*data[1]*data[8] - data[7]*data[5]*data[0];
}

Here is the caller graph for this function:

string Dump ( const std::string &  delimeter) const
Parameters:
delimeterthe item separator (tab or comma)
Returns:
a string with the delimeter-separated contents of the matrix

Definition at line 69 of file FGMatrix33.cpp.

{
  ostringstream buffer;
  buffer << setw(12) << setprecision(10) << data[0] << delimiter;
  buffer << setw(12) << setprecision(10) << data[3] << delimiter;
  buffer << setw(12) << setprecision(10) << data[6] << delimiter;
  buffer << setw(12) << setprecision(10) << data[1] << delimiter;
  buffer << setw(12) << setprecision(10) << data[4] << delimiter;
  buffer << setw(12) << setprecision(10) << data[7] << delimiter;
  buffer << setw(12) << setprecision(10) << data[2] << delimiter;
  buffer << setw(12) << setprecision(10) << data[5] << delimiter;
  buffer << setw(12) << setprecision(10) << data[8];
  return buffer.str();
}
string Dump ( const std::string &  delimiter,
const std::string &  prefix 
) const
Parameters:
delimeterthe item separator (tab or comma, etc.)
prefixan additional prefix that is used to indent the 3X3 matrix printout
Returns:
a string with the delimeter-separated contents of the matrix

Definition at line 86 of file FGMatrix33.cpp.

{
  ostringstream buffer;

  buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[0] << delimiter;
  buffer << right << fixed << setw(9) << setprecision(6) << data[3] << delimiter;
  buffer << right << fixed << setw(9) << setprecision(6) << data[6] << endl;

  buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[1] << delimiter;
  buffer << right << fixed << setw(9) << setprecision(6) << data[4] << delimiter;
  buffer << right << fixed << setw(9) << setprecision(6) << data[7] << endl;

  buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[2] << delimiter;
  buffer << right << fixed << setw(9) << setprecision(6) << data[5] << delimiter;
  buffer << right << fixed << setw(9) << setprecision(6) << data[8];

  buffer << setw(0) << left;

  return buffer.str();
}
double Entry ( unsigned int  row,
unsigned int  col 
) const [inline]

This function is just a shortcut for the double& operator()(unsigned int row, unsigned int col) function. It is used internally to access the elements in a more convenient way.

Note that the indices given in the arguments are unchecked.

Parameters:
rowRow index.
colColumn index.
Returns:
the value of the matrix entry at the given row and column indices. Indices are counted starting with 1.

Definition at line 207 of file FGMatrix33.h.

                                                         {
    return data[(col-1)*eRows+row-1];
  }
double& Entry ( unsigned int  row,
unsigned int  col 
) [inline]

This function is just a shortcut for the double& operator()(unsigned int row, unsigned int col) function. It is used internally to access the elements in a more convenient way.

Note that the indices given in the arguments are unchecked.

Parameters:
rowRow index.
colColumn index.
Returns:
a reference to the matrix entry at the given row and column indices. Indices are counted starting with 1.

Definition at line 224 of file FGMatrix33.h.

                                                     {
     return data[(col-1)*eRows+row-1];
   }
void InitMatrix ( void  )

This function initializes a matrix to all 0.0.

Definition at line 257 of file FGMatrix33.cpp.

Referenced by FGBuoyantForces::FGBuoyantForces(), FGForce::FGForce(), FGPropulsion::FGPropulsion(), FGRotor::FGRotor(), FGThruster::FGThruster(), and FGMassBalance::Run().

{
  data[0] = data[1] = data[2] = data[3] = data[4] = data[5] =
    data[6] = data[7] = data[8] = 0.0;
}

Here is the caller graph for this function:

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 
) [inline]

This function initializes a matrix to user specified values.

Definition at line 262 of file FGMatrix33.h.

  {
    data[0] = m11;
    data[1] = m21;
    data[2] = m31;
    data[3] = m12;
    data[4] = m22;
    data[5] = m32;
    data[6] = m13;
    data[7] = m23;
    data[8] = m33;
  }
FGMatrix33 Inverse ( void  ) const

Computes and returns if the inverse of the matrix. It is computed by Cramers Rule. Also there are no checks performed if the matrix is invertible. If you are not sure that it really is check this with the Invertible() call before.

Definition at line 227 of file FGMatrix33.cpp.

                                         {
  // Compute the inverse of a general matrix using Cramers rule.
  // I guess googling for cramers rule gives tons of references
  // for this. :)

  if (Determinant() != 0.0) {
    double rdet = 1.0/Determinant();

    double i11 = rdet*(data[4]*data[8]-data[7]*data[5]);
    double i21 = rdet*(data[7]*data[2]-data[1]*data[8]);
    double i31 = rdet*(data[1]*data[5]-data[4]*data[2]);
    double i12 = rdet*(data[6]*data[5]-data[3]*data[8]);
    double i22 = rdet*(data[0]*data[8]-data[6]*data[2]);
    double i32 = rdet*(data[3]*data[2]-data[0]*data[5]);
    double i13 = rdet*(data[3]*data[7]-data[6]*data[4]);
    double i23 = rdet*(data[6]*data[1]-data[0]*data[7]);
    double i33 = rdet*(data[0]*data[4]-data[3]*data[1]);

    return FGMatrix33( i11, i12, i13,
                       i21, i22, i23,
                       i31, i32, i33 );
  } else {
    return FGMatrix33( 0, 0, 0,
                       0, 0, 0,
                       0, 0, 0 );
  }
}
bool Invertible ( void  ) const [inline]

Checks and returns if the matrix is nonsingular and thus invertible. This is done by simply computing the determinant and check if it is zero. Note that this test does not cover any instabilities caused by nearly singular matirces using finite arithmetics. It only checks exact singularity.

Definition at line 297 of file FGMatrix33.h.

References FGMatrix33::Determinant().

{ return 0.0 != Determinant(); }

Here is the call graph for this function:

double& operator() ( unsigned int  row,
unsigned int  col 
) [inline]

Note that the indices given in the arguments are unchecked.

Parameters:
rowRow index.
colColumn index.
Returns:
a reference to the matrix entry at the given row and column indices. Indices are counted starting with 1.

Definition at line 190 of file FGMatrix33.h.

                                                         {
    return data[(col-1)*eRows+row-1];
  }
double operator() ( unsigned int  row,
unsigned int  col 
) const [inline]
Parameters:
rowRow index.
colColumn index.
Returns:
the value of the matrix entry at the given row and column indices. Indices are counted starting with 1.

Definition at line 177 of file FGMatrix33.h.

                                                              {
    return data[(col-1)*eRows+row-1];
  }
FGColumnVector3 operator* ( const FGColumnVector3 v) const
Parameters:
vvector to multiply with.
Returns:
matric vector product.

Compute and return the product of the current matrix with the vector given in the argument.

Definition at line 489 of file FGMatrix33.cpp.

{
  double v1 = v(1);
  double v2 = v(2);
  double v3 = v(3);

  double tmp1 = v1*data[0];  //[(col-1)*eRows+row-1]
  double tmp2 = v1*data[1];
  double tmp3 = v1*data[2];

  tmp1 += v2*data[3];
  tmp2 += v2*data[4];
  tmp3 += v2*data[5];

  tmp1 += v3*data[6];
  tmp2 += v3*data[7];
  tmp3 += v3*data[8];

  return FGColumnVector3( tmp1, tmp2, tmp3 );
}
FGMatrix33 operator* ( const FGMatrix33 B) const
Parameters:
Bmatrix to add to.
Returns:
product of the matrices.

Compute and return the product of the current matrix and the matrix B given in the argument.

Definition at line 378 of file FGMatrix33.cpp.

{
  FGMatrix33 Product;

  Product.data[0] = data[0]*M.data[0] + data[3]*M.data[1] + data[6]*M.data[2];
  Product.data[3] = data[0]*M.data[3] + data[3]*M.data[4] + data[6]*M.data[5];
  Product.data[6] = data[0]*M.data[6] + data[3]*M.data[7] + data[6]*M.data[8];
  Product.data[1] = data[1]*M.data[0] + data[4]*M.data[1] + data[7]*M.data[2];
  Product.data[4] = data[1]*M.data[3] + data[4]*M.data[4] + data[7]*M.data[5];
  Product.data[7] = data[1]*M.data[6] + data[4]*M.data[7] + data[7]*M.data[8];
  Product.data[2] = data[2]*M.data[0] + data[5]*M.data[1] + data[8]*M.data[2];
  Product.data[5] = data[2]*M.data[3] + data[5]*M.data[4] + data[8]*M.data[5];
  Product.data[8] = data[2]*M.data[6] + data[5]*M.data[7] + data[8]*M.data[8];

  return Product;
}
FGMatrix33 operator* ( const double  scalar) const
Parameters:
scalarscalar factor to multiply with.
Returns:
scaled matrix.

Compute and return the product of the current matrix with the scalar value scalar given in the argument.

Definition at line 331 of file FGMatrix33.cpp.

{
  return FGMatrix33( scalar * data[0],
                     scalar * data[3],
                     scalar * data[6],
                     scalar * data[1],
                     scalar * data[4],
                     scalar * data[7],
                     scalar * data[2],
                     scalar * data[5],
                     scalar * data[8] );
}
FGMatrix33 & operator*= ( const FGMatrix33 B)
Parameters:
Bmatrix to multiply with.
Returns:
reference to the current matrix.

Compute the product of the current matrix and the matrix B given in the argument.

Definition at line 397 of file FGMatrix33.cpp.

{
  // FIXME: Make compiler friendlier
  double a,b,c;

  a = data[0]; b=data[3]; c=data[6];
  data[0] = a*M.data[0] + b*M.data[1] + c*M.data[2];
  data[3] = a*M.data[3] + b*M.data[4] + c*M.data[5];
  data[6] = a*M.data[6] + b*M.data[7] + c*M.data[8];

  a = data[1]; b=data[4]; c=data[7];
  data[1] = a*M.data[0] + b*M.data[1] + c*M.data[2];
  data[4] = a*M.data[3] + b*M.data[4] + c*M.data[5];
  data[7] = a*M.data[6] + b*M.data[7] + c*M.data[8];

  a = data[2]; b=data[5]; c=data[8];
  data[2] = a*M.data[0] + b*M.data[1] + c*M.data[2];
  data[5] = a*M.data[3] + b*M.data[4] + c*M.data[5];
  data[8] = a*M.data[6] + b*M.data[7] + c*M.data[8];

  return *this;
}
FGMatrix33 & operator*= ( const double  scalar)
Parameters:
scalarscalar value to multiply with.
Returns:
reference to the current matrix.

Compute the product of the current matrix and the scalar value scalar given in the argument.

Definition at line 361 of file FGMatrix33.cpp.

{
  data[0] *= scalar;
  data[3] *= scalar;
  data[6] *= scalar;
  data[1] *= scalar;
  data[4] *= scalar;
  data[7] *= scalar;
  data[2] *= scalar;
  data[5] *= scalar;
  data[8] *= scalar;

  return *this;
}
FGMatrix33 operator+ ( const FGMatrix33 B) const
Parameters:
Bmatrix to add to.
Returns:
sum of the matrices.

Compute and return the sum of the current matrix and the matrix B given in the argument.

Definition at line 299 of file FGMatrix33.cpp.

{
  return FGMatrix33( data[0] + M.data[0],
                     data[3] + M.data[3],
                     data[6] + M.data[6],
                     data[1] + M.data[1],
                     data[4] + M.data[4],
                     data[7] + M.data[7],
                     data[2] + M.data[2],
                     data[5] + M.data[5],
                     data[8] + M.data[8] );
}
FGMatrix33 & operator+= ( const FGMatrix33 B)
Parameters:
Bmatrix to add.
Returns:
reference to the current matrix.

Compute the sum of the current matrix and the matrix B given in the argument.

Definition at line 314 of file FGMatrix33.cpp.

{
  data[0] += M.data[0];
  data[3] += M.data[3];
  data[6] += M.data[6];
  data[1] += M.data[1];
  data[4] += M.data[4];
  data[7] += M.data[7];
  data[2] += M.data[2];
  data[5] += M.data[5];
  data[8] += M.data[8];

  return *this;
}
FGMatrix33 operator- ( const FGMatrix33 B) const
Parameters:
Bmatrix to add to.
Returns:
difference of the matrices.

Compute and return the sum of the current matrix and the matrix B given in the argument.

Definition at line 267 of file FGMatrix33.cpp.

{
  return FGMatrix33( data[0] - M.data[0],
                     data[3] - M.data[3],
                     data[6] - M.data[6],
                     data[1] - M.data[1],
                     data[4] - M.data[4],
                     data[7] - M.data[7],
                     data[2] - M.data[2],
                     data[5] - M.data[5],
                     data[8] - M.data[8] );
}
FGMatrix33 & operator-= ( const FGMatrix33 B)
Parameters:
Bmatrix to subtract.
Returns:
reference to the current matrix.

Compute the diffence from the current matrix and the matrix B given in the argument.

Definition at line 282 of file FGMatrix33.cpp.

{
  data[0] -= M.data[0];
  data[1] -= M.data[1];
  data[2] -= M.data[2];
  data[3] -= M.data[3];
  data[4] -= M.data[4];
  data[5] -= M.data[5];
  data[6] -= M.data[6];
  data[7] -= M.data[7];
  data[8] -= M.data[8];

  return *this;
}
FGMatrix33 operator/ ( const double  scalar) const
Parameters:
scalarscalar factor to divide through.
Returns:
scaled matrix.

Compute and return the product of the current matrix with the scalar value 1.0/scalar, where scalar is given in the argument.

Definition at line 422 of file FGMatrix33.cpp.

{
  FGMatrix33 Quot;

  if ( scalar != 0 ) {
    double tmp = 1.0/scalar;
    Quot.data[0] = data[0] * tmp;
    Quot.data[3] = data[3] * tmp;
    Quot.data[6] = data[6] * tmp;
    Quot.data[1] = data[1] * tmp;
    Quot.data[4] = data[4] * tmp;
    Quot.data[7] = data[7] * tmp;
    Quot.data[2] = data[2] * tmp;
    Quot.data[5] = data[5] * tmp;
    Quot.data[8] = data[8] * tmp;
  } else {
    MatrixException mE;
    mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/(const double scalar)";
    throw mE;
  }
  return Quot;
}
FGMatrix33 & operator/= ( const double  scalar)
Parameters:
scalarscalar value to divide through.
Returns:
reference to the current matrix.

Compute the product of the current matrix and the scalar value 1.0/scalar, where scalar is given in the argument.

Definition at line 447 of file FGMatrix33.cpp.

{
  if ( scalar != 0 ) {
    double tmp = 1.0/scalar;
    data[0] *= tmp;
    data[3] *= tmp;
    data[6] *= tmp;
    data[1] *= tmp;
    data[4] *= tmp;
    data[7] *= tmp;
    data[2] *= tmp;
    data[5] *= tmp;
    data[8] *= tmp;
  } else {
    MatrixException mE;
    mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/=(const double scalar)";
    throw mE;
  }
  return *this;
}
FGMatrix33& operator= ( const FGMatrix33 A) [inline]
Parameters:
Asource matrix.

Copy the content of the matrix given in the argument into *this.

Definition at line 313 of file FGMatrix33.h.

  {
    data[0] = A.data[0];
    data[1] = A.data[1];
    data[2] = A.data[2];
    data[3] = A.data[3];
    data[4] = A.data[4];
    data[5] = A.data[5];
    data[6] = A.data[6];
    data[7] = A.data[7];
    data[8] = A.data[8];
    return *this;
  }
unsigned int Rows ( void  ) const [inline]
Returns:
the number of rows in the matrix.

Definition at line 231 of file FGMatrix33.h.

{ return eRows; }
void T ( void  )

This function only transposes this matrix. Nothing is returned.

Definition at line 470 of file FGMatrix33.cpp.

{
  double tmp;

  tmp = data[3];
  data[3] = data[1];
  data[1] = tmp;

  tmp = data[6];
  data[6] = data[2];
  data[2] = tmp;

  tmp = data[7];
  data[7] = data[5];
  data[5] = tmp;
}
FGMatrix33 Transposed ( void  ) const [inline]

This function only returns the transpose of this matrix. This matrix itself remains unchanged.

Returns:
the transposed matrix.

Definition at line 243 of file FGMatrix33.h.

References FGMatrix33::FGMatrix33().

Referenced by FGPropeller::Calculate(), FGRotor::FGRotor(), FGLGear::GetBodyForces(), FGInitialCondition::ResetIC(), FGPropagate::Run(), and FGInitialCondition::SetBetaRadIC().

                                    {
    return FGMatrix33( data[0], data[1], data[2],
                       data[3], data[4], data[5],
                       data[6], data[7], data[8] );
  }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: