Matrix3 Class Reference

#include <Matrix3.hh>

Inheritance diagram for Matrix3:

Inheritance graph
[legend]

Collaboration diagram for Matrix3:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 12 of file Matrix3.hh.


Public Member Functions

 Matrix3 ()
 Matrix3 (const Matrix< 3 > &m3)
 Matrix3 (const Vector3 &axis, const double angle)
 Matrix3 (const Vector3 &from, const Vector3 &to)
Matrix3setAsRotation (const Vector3 &from, const Vector3 &to)
Matrixset (const size_t i, const size_t j, const double value)
double get (const size_t i, const size_t j) const
Vector< N > getRow (const size_t row) const
Matrix< N > & setRow (const size_t row, const Vector< N > &r)
Vector< N > getColumn (const size_t col) const
Matrix< N > & setColumn (const size_t col, const Vector< N > &c)
Matrix< N > transpose () const
Matrix< N > inverse () const
 Calculate inverse.
double det () const
 Calculate determinant.
double trace () const
 Calculate trace.
Matrix< N > operator- () const
 Negate.
size_t size () const
 Get dimensionality.
bool isZero (double tolerance=1E-5) const
 Index-wise check for nullness, allowing for numerical precision.
bool isEqual (Matrix< N > other) const
 Check for index-wise equality, allowing for numerical precision.
bool isSymm () const
 Check for symmetry under transposition.
bool isDiag () const
 Check that all off-diagonal elements are zero, allowing for numerical precision.
bool operator== (const Matrix< N > &a) const
bool operator!= (const Matrix< N > &a) const
bool operator< (const Matrix< N > &a) const
bool operator<= (const Matrix< N > &a) const
bool operator> (const Matrix< N > &a) const
bool operator>= (const Matrix< N > &a) const
Matrix< N > & operator*= (const Matrix< N > &m)
Matrix< N > & operator*= (const double a)
Matrix< N > & operator/= (const double a)
Matrix< N > & operator+= (const Matrix< N > &m)
Matrix< N > & operator-= (const Matrix< N > &m)

Static Public Member Functions

static Matrix3 mkXRotation (const double angle)
static Matrix3 mkYRotation (const double angle)
static Matrix3 mkZRotation (const double angle)
static Matrix< N > mkZero ()
static Matrix< N > mkDiag (Vector< N > diag)
static Matrix< N > mkIdentity ()

Protected Types

typedef Eigen::Matrix< double, N > EMatrix

Protected Attributes

EMatrix _matrix

Member Typedef Documentation

typedef Eigen::Matrix<double,N> EMatrix [protected, inherited]

Definition at line 253 of file MatrixN.hh.


Constructor & Destructor Documentation

Matrix3 (  )  [inline]

Definition at line 14 of file Matrix3.hh.

Referenced by Matrix3::mkXRotation(), Matrix3::mkYRotation(), and Matrix3::mkZRotation().

00014 { }

Matrix3 ( const Matrix< 3 > &  m3  )  [inline]

Definition at line 16 of file Matrix3.hh.

00016 :  Matrix<3>::Matrix<3>(m3) { }

Matrix3 ( const Vector3 axis,
const double  angle 
) [inline]

Definition at line 18 of file Matrix3.hh.

References Matrix< 3 >::_matrix, Vector::_vec, and Vector3::unit().

00018                                                    {
00019     const Vector3 normaxis = axis.unit();
00020     _matrix.loadRotation3(angle, normaxis._vec);
00021   }

Matrix3 ( const Vector3 from,
const Vector3 to 
) [inline]

Definition at line 23 of file Matrix3.hh.

References Matrix3::setAsRotation().

00023                                                   {
00024     setAsRotation(from, to);
00025   }


Member Function Documentation

static Matrix3 mkXRotation ( const double  angle  )  [inline, static]

Definition at line 28 of file Matrix3.hh.

References Matrix3::Matrix3().

00028                                                  {
00029     return Matrix3(Vector3(1,0,0), angle);
00030   }

static Matrix3 mkYRotation ( const double  angle  )  [inline, static]

Definition at line 32 of file Matrix3.hh.

References Matrix3::Matrix3().

00032                                                  {
00033     return Matrix3(Vector3(0,1,0), angle);
00034   }

static Matrix3 mkZRotation ( const double  angle  )  [inline, static]

Definition at line 36 of file Matrix3.hh.

References Matrix3::Matrix3().

00036                                                  {
00037     return Matrix3(Vector3(0,0,1), angle);
00038   }

Matrix3& setAsRotation ( const Vector3 from,
const Vector3 to 
) [inline]

Definition at line 41 of file Matrix3.hh.

References Matrix< 3 >::_matrix, Vector::_vec, Rivet::angle(), Rivet::cross(), Rivet::isZero(), Rivet::theta(), and Vector3::unit().

Referenced by Matrix3::Matrix3().

00041                                                                  {
00042     const double theta = angle(from, to);
00043     if (Rivet::isZero(theta)) {
00044       _matrix.loadIdentity();
00045     } else {
00046       const Vector3 normaxis = cross(from, to).unit();
00047       _matrix.loadRotation3(theta, normaxis._vec);
00048     }
00049     return *this;
00050   }

static Matrix<N> mkZero (  )  [inline, static, inherited]

Definition at line 42 of file MatrixN.hh.

00042                               {
00043       Matrix<N> rtn;
00044       return rtn;
00045     }

static Matrix<N> mkDiag ( Vector< N >  diag  )  [inline, static, inherited]

Definition at line 47 of file MatrixN.hh.

00047                                             {
00048       Matrix<N> rtn;
00049       for (size_t i = 0; i < N; ++i) {
00050         rtn.set(i, i, diag[i]);
00051       }
00052       return rtn;
00053     }

static Matrix<N> mkIdentity (  )  [inline, static, inherited]

Definition at line 55 of file MatrixN.hh.

00055                                   {
00056       Matrix<N> rtn;
00057       for (size_t i = 0; i < N; ++i) {
00058         rtn.set(i, i, 1);
00059       }
00060       return rtn;
00061     }

Matrix& set ( const size_t  i,
const size_t  j,
const double  value 
) [inline, inherited]

Definition at line 74 of file MatrixN.hh.

00074                                                                     {
00075       if (i < N && j < N) {
00076         _matrix(i, j) = value;
00077       } else {
00078         throw std::runtime_error("Attempted set access outside matrix bounds.");
00079       }
00080       return *this;
00081     }

double get ( const size_t  i,
const size_t  j 
) const [inline, inherited]

Definition at line 83 of file MatrixN.hh.

00083                                                      {
00084       if (i < N && j < N) {
00085         return _matrix(i, j);
00086       } else {
00087         throw std::runtime_error("Attempted get access outside matrix bounds.");
00088       }
00089     }

Vector<N> getRow ( const size_t  row  )  const [inline, inherited]

Definition at line 91 of file MatrixN.hh.

00091                                              {
00092       Vector<N> rtn;
00093       for (size_t i = 0; i < N; ++i) {
00094         rtn.set(i, _matrix(row,i));
00095       }
00096       return rtn;
00097     }

Matrix<N>& setRow ( const size_t  row,
const Vector< N > &  r 
) [inline, inherited]

Definition at line 99 of file MatrixN.hh.

00099                                                             {
00100       for (size_t i = 0; i < N; ++i) {
00101         _matrix(row,i) = r.get(i);
00102       }
00103       return *this;
00104     }

Vector<N> getColumn ( const size_t  col  )  const [inline, inherited]

Definition at line 106 of file MatrixN.hh.

00106                                                 {
00107       const Eigen::Vector<double,N> eVec = _matrix.column(col);
00108       Vector<N> rtn;
00109       for (size_t i = 0; i < N; ++i) {
00110         rtn.set(i, _matrix(i,col));
00111       }
00112       return rtn;
00113     }

Matrix<N>& setColumn ( const size_t  col,
const Vector< N > &  c 
) [inline, inherited]

Definition at line 115 of file MatrixN.hh.

00115                                                                {
00116       for (size_t i = 0; i < N; ++i) {
00117         _matrix(i,col) = c.get(i);
00118       }
00119       return *this;
00120     }

Matrix<N> transpose (  )  const [inline, inherited]

Definition at line 122 of file MatrixN.hh.

00122                                 {
00123       Matrix<N> tmp = *this;
00124       tmp._matrix.replaceWithAdjoint();
00125       return tmp;
00126     }

Matrix<N> inverse (  )  const [inline, inherited]

Calculate inverse.

Definition at line 134 of file MatrixN.hh.

00134                               {
00135       Matrix<N> tmp;
00136       tmp._matrix = _matrix.inverse();
00137       return tmp;
00138     }

double det (  )  const [inline, inherited]

Calculate determinant.

Definition at line 141 of file MatrixN.hh.

00141                         {
00142       return _matrix.determinant();
00143     }

double trace (  )  const [inline, inherited]

Calculate trace.

Definition at line 146 of file MatrixN.hh.

00146                          {
00147       double tr = 0.0;
00148       for (size_t i = 0; i < N; ++i) {
00149         tr += _matrix(i,i);
00150       }
00151       return tr;
00152       // return _matrix.trace();
00153     }

Matrix<N> operator- (  )  const [inline, inherited]

Negate.

Definition at line 156 of file MatrixN.hh.

00156                                 {
00157       Matrix<N> rtn;
00158       rtn._matrix = -_matrix;
00159       return rtn;
00160     }

size_t size (  )  const [inline, inherited]

Get dimensionality.

Definition at line 163 of file MatrixN.hh.

00163                         {
00164       return N;
00165     }

bool isZero ( double  tolerance = 1E-5  )  const [inline, inherited]

Index-wise check for nullness, allowing for numerical precision.

Definition at line 168 of file MatrixN.hh.

00168                                              {
00169       for (size_t i=0; i < N; ++i) {
00170         for (size_t j=0; j < N; ++j) {
00171           if (! Rivet::isZero(_matrix(i,j), tolerance) ) return false;
00172         }
00173       }
00174       return true;
00175     }

bool isEqual ( Matrix< N >  other  )  const [inline, inherited]

Check for index-wise equality, allowing for numerical precision.

Definition at line 178 of file MatrixN.hh.

00178                                         {
00179       for (size_t i=0; i < N; ++i) {
00180         for (size_t j=i; j < N; ++j) {
00181           if (! Rivet::isZero(_matrix(i,j) - other._matrix(i,j)) ) return false;
00182         }
00183       }
00184       return true;
00185     }

bool isSymm (  )  const [inline, inherited]

Check for symmetry under transposition.

Definition at line 188 of file MatrixN.hh.

00188                         {
00189       return isEqual(this->transpose());
00190     }

bool isDiag (  )  const [inline, inherited]

Check that all off-diagonal elements are zero, allowing for numerical precision.

Definition at line 193 of file MatrixN.hh.

00193                         {
00194       for (size_t i=0; i < N; ++i) {
00195         for (size_t j=0; j < N; ++j) {
00196           if (i == j) continue;
00197           if (! Rivet::isZero(_matrix(i,j)) ) return false;
00198         }
00199       }
00200       return true;
00201     }

bool operator== ( const Matrix< N > &  a  )  const [inline, inherited]

Definition at line 203 of file MatrixN.hh.

00203                                               {
00204       return _matrix == a._matrix;
00205     }

bool operator!= ( const Matrix< N > &  a  )  const [inline, inherited]

Definition at line 207 of file MatrixN.hh.

00207                                               {
00208       return _matrix != a._matrix;
00209     }

bool operator< ( const Matrix< N > &  a  )  const [inline, inherited]

Definition at line 211 of file MatrixN.hh.

00211                                              {
00212       return _matrix < a._matrix;
00213     }

bool operator<= ( const Matrix< N > &  a  )  const [inline, inherited]

Definition at line 215 of file MatrixN.hh.

00215                                               {
00216       return _matrix <= a._matrix;
00217     }

bool operator> ( const Matrix< N > &  a  )  const [inline, inherited]

Definition at line 219 of file MatrixN.hh.

00219                                              {
00220       return _matrix > a._matrix;
00221     }

bool operator>= ( const Matrix< N > &  a  )  const [inline, inherited]

Definition at line 223 of file MatrixN.hh.

00223                                               {
00224       return _matrix >= a._matrix;
00225     }

Matrix<N>& operator*= ( const Matrix< N > &  m  )  [inline, inherited]

Definition at line 227 of file MatrixN.hh.

00227                                               {
00228       _matrix = _matrix * m._matrix;
00229       return *this;
00230     }

Matrix<N>& operator*= ( const double  a  )  [inline, inherited]

Definition at line 232 of file MatrixN.hh.

00232                                           {
00233       _matrix *= a;
00234       return *this;
00235     }

Matrix<N>& operator/= ( const double  a  )  [inline, inherited]

Definition at line 237 of file MatrixN.hh.

00237                                           {
00238       _matrix /= a;
00239       return *this;
00240     }

Matrix<N>& operator+= ( const Matrix< N > &  m  )  [inline, inherited]

Definition at line 242 of file MatrixN.hh.

00242                                               {
00243       _matrix += m._matrix;
00244       return *this;
00245     }

Matrix<N>& operator-= ( const Matrix< N > &  m  )  [inline, inherited]

Definition at line 247 of file MatrixN.hh.

00247                                               {
00248       _matrix -= m._matrix;
00249       return *this;
00250     }


Member Data Documentation

EMatrix _matrix [protected, inherited]

Definition at line 254 of file MatrixN.hh.

Referenced by Matrix3::Matrix3(), and Matrix3::setAsRotation().


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