Ravelin
Public Member Functions | Static Public Member Functions | List of all members
MATRIX2 Class Reference

A general 2x2 matrix. More...

#include <Matrix2.h>

Public Member Functions

 MATRIX2 (const REAL *array)
 Constructs a matrix from an array. More...
 
 MATRIX2 (REAL m00, REAL m01, REAL m10, REAL m11)
 Constructs a matrix from 4 values. More...
 
 MATRIX2 (const MATRIX2 &source)
 
 MATRIX2 (const MATRIXN &m)
 
 MATRIX2 (const SHAREDMATRIXN &m)
 
 MATRIX2 (const CONST_SHAREDMATRIXN &m)
 
unsigned size () const
 
unsigned rows () const
 
unsigned columns () const
 
bool is_symmetric (REAL tolerance) const
 Checks whether this matrix is symmetric.
 
bool orthonormalize ()
 Makes the matrix orthonormal using Gram-Schmidt orthogonalization.
 
bool is_orthonormal () const
 Determines whether this is an orthonormal matrix.
 
REAL det () const
 Calculates the determinant for a 2x2 matrix.
 
MATRIX2invert ()
 Inverts this matrix.
 
MATRIX2 inverse () const
 
void set_rot_Z (REAL angle)
 Sets this matrix to the rotation matrix of the specified angle around the Z axis.
 
void transpose ()
 Sets this matrix to its transpose.
 
ORIGIN2 get_row (unsigned i) const
 Gets the specified row of the matrix. More...
 
ORIGIN2 get_column (unsigned i) const
 Gets the specified column of the matrix. More...
 
void set_identity ()
 Sets this matrix to identity.
 
void set_zero ()
 Sets this matrix to zero.
 
ORIGIN2 mult (const ORIGIN2 &v) const
 Multiplies this matrix by a vector and returns the result in a new vector.
 
ORIGIN2 transpose_mult (const ORIGIN2 &v) const
 Multiplies the transpose of this matrix by a vector and returns the result in a new vector.
 
MATRIX2 mult (const MATRIX2 &m) const
 Multiplies this matrix by another 2x2 matrix.
 
MATRIX2 transpose_mult (const MATRIX2 &m) const
 Multiplies the transpose of this matrix by a matrix and returns the result in a new matrix.
 
MATRIX2 transpose_mult_transpose (const MATRIX2 &m) const
 Multiplies the transpose of this matrix by the transpose of a matrix and returns the result in a new matrix.
 
MATRIX2 mult_transpose (const MATRIX2 &m) const
 Multiplies this matrix by the transpose of a matrix and returns the result in a new matrix.
 
MATRIX2operator= (const MATRIX2 &source)
 Copies a matrix to this one.
 
MATRIX2operator= (const MATRIXN &source)
 Copies a matrix to this one.
 
MATRIX2operator= (const SHAREDMATRIXN &source)
 Copies a matrix to this one.
 
MATRIX2operator= (const CONST_SHAREDMATRIXN &source)
 Copies a matrix to this one.
 
MATRIX2operator+= (const MATRIX2 &m)
 Adds m to this in place.
 
MATRIX2operator-= (const MATRIX2 &m)
 Subtracts m from this in place.
 
MATRIX2operator*= (const MATRIX2 &m)
 
MATRIX2operator*= (REAL scalar)
 Multiplies this matrix by a scalar in place.
 
MATRIX2operator/= (REAL scalar)
 
ORIGIN2 operator* (const ORIGIN2 &o) const
 
MATRIX2 operator+ (const MATRIX2 &m) const
 
MATRIX2 operator- (const MATRIX2 &m) const
 
MATRIX2 operator* (const MATRIX2 &m) const
 
MATRIX2 operator* (REAL scalar) const
 
MATRIX2 operator/ (REAL scalar) const
 
MATRIX2 operator- () const
 Returns the negation of this matrix.
 
unsigned leading_dim () const
 
unsigned inc () const
 
const REAL & xx () const
 
const REAL & yx () const
 
const REAL & xy () const
 
const REAL & yy () const
 
REAL & xx ()
 
REAL & yx ()
 
REAL & xy ()
 
REAL & yy ()
 
REAL & operator() (unsigned i, unsigned j)
 
const REAL & operator() (unsigned i, unsigned j) const
 
MATRIX2resize (unsigned rows, unsigned columns, bool preserve=false)
 
const REAL * data (unsigned i) const
 
REAL * data (unsigned i)
 
const REAL * data () const
 Gets a constant pointer to the beginning of the matrix array.
 
REAL * data ()
 Gets a pointer to the beginning of the matrix array.
 
CONST_COLUMN_ITERATOR block_column_iterator_begin (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end) const
 This file consists of general routines for constant matrices. More...
 
CONST_COLUMN_ITERATOR block_column_iterator_end (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end) const
 Gets a column iterator to a block.
 
CONST_ROW_ITERATOR block_row_iterator_begin (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end) const
 Gets a row iterator to a block.
 
CONST_ROW_ITERATOR block_row_iterator_end (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end) const
 Gets a row iterator to a block.
 
template<class V >
V & get_row (unsigned row, V &v) const
 
template<class V >
V & get_column (unsigned column, V &v) const
 
template<class T , class U >
U & transpose_mult_transpose (const T &x, U &y, REAL alpha=(REAL) 1.0, REAL beta=(REAL) 0.0) const
 Does the operation y = beta*y + alpha*this'*x'.
 
template<class T , class U >
U & mult_transpose (const T &x, U &y, REAL alpha=(REAL) 1.0, REAL beta=(REAL) 0.0) const
 Does the operation y = beta*y + alpha*this*x'.
 
template<class T , class U >
U & transpose_mult (const T &x, U &y, REAL alpha=(REAL) 1.0, REAL beta=(REAL) 0.0) const
 Does the operation y = beta*y + alpha*this'*x.
 
template<class T , class U >
U & mult (const T &x, U &y, REAL alpha=(REAL) 1.0, REAL beta=(REAL) 0.0) const
 Does the operation y = beta*y + alpha*this*x.
 
template<class M >
M & get_sub_mat (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end, M &m, Transposition trans=eNoTranspose) const
 Gets the specified sub matrix. More...
 
template<class ForwardIterator , class M >
M & select_columns (ForwardIterator col_start, ForwardIterator col_end, M &m) const
 Gets a submatrix of columns (not necessarily a block) More...
 
template<class M >
M & select_columns (std::vector< bool > &col_select, M &m) const
 Gets a submatrix of columns (not necessarily a block) More...
 
template<class ForwardIterator , class M >
M & select_rows (ForwardIterator row_start, ForwardIterator row_end, M &m) const
 Gets a submatrix of rows (not necessarily a block) More...
 
template<class M >
M & select_rows (std::vector< bool > &row_select, M &m) const
 Gets a submatrix of rows (not necessarily a block) More...
 
template<class ForwardIterator1 , class ForwardIterator2 , class X >
X & select (ForwardIterator1 row_start, ForwardIterator1 row_end, ForwardIterator2 col_start, ForwardIterator2 col_end, X &m) const
 Gets a submatrix (not necessarily a block) More...
 
template<class X >
X & select (const std::vector< bool > &rows, const std::vector< bool > &cols, X &m) const
 Gets a submatrix (not necessarily a block)
 
template<class M >
M & select_square (const std::vector< bool > &indices, M &result) const
 Gets a square submatrix (not necessarily a block)
 
template<class ForwardIterator , class M >
M & select_square (ForwardIterator start, ForwardIterator end, M &m) const
 
CONST_COLUMN_ITERATOR column_iterator_begin () const
 Get an iterator to the beginning.
 
CONST_COLUMN_ITERATOR column_iterator_end () const
 Get an iterator to the end.
 
CONST_ROW_ITERATOR row_iterator_begin () const
 Get an iterator to the beginning.
 
CONST_ROW_ITERATOR row_iterator_end () const
 Get an iterator to the end.
 
COLUMN_ITERATOR block_column_iterator_begin (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end)
 Gets a column iterator to a block.
 
COLUMN_ITERATOR block_column_iterator_end (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end)
 Gets a column iterator to a block.
 
ROW_ITERATOR block_row_iterator_begin (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end)
 Gets a row iterator to a block.
 
ROW_ITERATOR block_row_iterator_end (unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end)
 Gets a row iterator to a block.
 
template<class V >
MATRIXX & set_row (unsigned row, const V &v)
 
template<class V >
MATRIXX & set_column (unsigned column, const V &v)
 
template<class M >
MATRIXX & set_sub_mat (unsigned row_start, unsigned col_start, const M &m, Transposition trans=eNoTranspose)
 Sets the specified sub matrix. More...
 
ROW_ITERATOR row_iterator_begin ()
 Get an iterator to the beginning (iterates column by column)
 
ROW_ITERATOR row_iterator_end ()
 Get an iterator to the end.
 
COLUMN_ITERATOR column_iterator_begin ()
 Get an iterator to the beginning (iterates column by column)
 
COLUMN_ITERATOR column_iterator_end ()
 Get an iterator to the end.
 
template<>
ORIGIN2get_column (unsigned i, ORIGIN2 &result) const
 Gets the specified column of the matrix.
 
template<>
ORIGIN2get_row (unsigned i, ORIGIN2 &result) const
 Gets the specified row of the matrix. More...
 
template<>
MATRIX2set_column (unsigned i, const ORIGIN2 &o)
 Sets the specified column of the matrix. More...
 
template<>
MATRIX2set_row (unsigned i, const ORIGIN2 &o)
 Sets the specified row of the matrix. More...
 

Static Public Member Functions

static MATRIX2 invert (const MATRIX2 &m)
 Determines the inverse of the given matrix.
 
static MATRIX2 rot_Z (REAL angle)
 Returns the rotation matrix of the specified angle around the Z axis.
 
static MATRIX2 transpose (const MATRIX2 &m)
 Determines the transpose of this matrix.
 
static bool valid_rotation (const MATRIX2 &R)
 
static MATRIX2 identity ()
 
static MATRIX2 zero ()
 
template<class V , class U , class W >
static W & diag_mult (const V &d, const U &v, W &result)
 Determines the transpose of a matrix and stores the result in a given matrix. More...
 

Detailed Description

A general 2x2 matrix.

Constructor & Destructor Documentation

MATRIX2::MATRIX2 ( const REAL *  array)

Constructs a matrix from an array.

Parameters
arrayan array of 4 REAL values in column-major format
MATRIX2::MATRIX2 ( REAL  m00,
REAL  m01,
REAL  m10,
REAL  m11 
)

Constructs a matrix from 4 values.

The resulting matrix will appear as follows:
m00 m01
m10 m11

Member Function Documentation

CONST_COLUMN_ITERATOR MATRIX2::block_column_iterator_begin ( unsigned  row_start,
unsigned  row_end,
unsigned  col_start,
unsigned  col_end 
) const
inline

This file consists of general routines for constant matrices.

Gets a column iterator to a block

template<class V , class U , class W >
static W& MATRIX2::diag_mult ( const V &  d,
const U &  v,
W &  result 
)
inlinestatic

Determines the transpose of a matrix and stores the result in a given matrix.

Multiplies the diagonal matrix formed from d by the vector v

ORIGIN2 MATRIX2::get_column ( unsigned  i) const

Gets the specified column of the matrix.

Parameters
ithe 0-index of the column

Referenced by get_column().

template<>
ORIGIN2& MATRIX2::get_row ( unsigned  i,
ORIGIN2 result 
) const

Gets the specified row of the matrix.

Parameters
ithe 0-index of the row

References get_row().

ORIGIN2 MATRIX2::get_row ( unsigned  i) const

Gets the specified row of the matrix.

Parameters
ithe 0-index of the row

Referenced by get_row().

template<class M >
M& MATRIX2::get_sub_mat ( unsigned  row_start,
unsigned  row_end,
unsigned  col_start,
unsigned  col_end,
M &  m,
Transposition  trans = eNoTranspose 
) const
inline

Gets the specified sub matrix.

Parameters
row_startthe row to start (inclusive)
row_endthe row to end (exclusive)
col_startthe column to start (inclusive)
col_endthe column to end (exclusive)
transposedetermines whether to store the transpose of the submatrix into m
Returns
a (row_end - row_start) x (col_end - col_start) sized matrix
template<class ForwardIterator1 , class ForwardIterator2 , class X >
X& MATRIX2::select ( ForwardIterator1  row_start,
ForwardIterator1  row_end,
ForwardIterator2  col_start,
ForwardIterator2  col_end,
X &  m 
) const
inline

Gets a submatrix (not necessarily a block)

Parameters
row_startan iterator pointing to the beginning of a container of row indices (container need not be sorted)
row_endan iterator pointing to the end of a container of row indices (container need not be sorted)
col_startan iterator pointing to the beginning of a container of column indices (container need not be sorted)
col_endan iterator pointing to the end of a container of column indices (container need not be sorted)
Mcontains the submatrix on return
template<class ForwardIterator , class M >
M& MATRIX2::select_columns ( ForwardIterator  col_start,
ForwardIterator  col_end,
M &  m 
) const
inline

Gets a submatrix of columns (not necessarily a block)

Parameters
col_startan iterator pointing to the beginning of a container of column indices (container need not be sorted)
col_endan iterator pointing to the end of a container of column indices (container need not be sorted)
Mcontains the submatrix on return
template<class M >
M& MATRIX2::select_columns ( std::vector< bool > &  col_select,
M &  m 
) const
inline

Gets a submatrix of columns (not necessarily a block)

Parameters
col_selecta vector of bools; if the entry is true in the vector, the column is selected
Mcontains the submatrix on return
template<class ForwardIterator , class M >
M& MATRIX2::select_rows ( ForwardIterator  row_start,
ForwardIterator  row_end,
M &  m 
) const
inline

Gets a submatrix of rows (not necessarily a block)

Parameters
row_startan iterator pointing to the beginning of a container of row indices (container need not be sorted)
row_endan iterator pointing to the end of a container of row indices (container need not be sorted)
Mcontains the submatrix on return
template<class M >
M& MATRIX2::select_rows ( std::vector< bool > &  row_select,
M &  m 
) const
inline

Gets a submatrix of rows (not necessarily a block)

Parameters
row_selecta vector of bools; if the entry is true in the vector, the row is selected
Mcontains the submatrix on return
template<class ForwardIterator , class M >
M& MATRIX2::select_square ( ForwardIterator  start,
ForwardIterator  end,
M &  m 
) const
inline
Parameters
startan iterator pointing to the beginning of a container of row/column indices (container need not be sorted)
endan iterator pointing to the end of a container of row/column indices (container need not be sorted)
Mcontains the submatrix on return
template<>
MATRIX2& MATRIX2::set_column ( unsigned  i,
const ORIGIN2 o 
)

Sets the specified column of the matrix.

Parameters
ithe 0-index of the column
oa 2D vector
template<>
MATRIX2& MATRIX2::set_row ( unsigned  i,
const ORIGIN2 o 
)

Sets the specified row of the matrix.

Parameters
ithe 0-index of the row
oa 2D vector
Note
the number of columns of this must be three!
template<class M >
MATRIXX& MATRIX2::set_sub_mat ( unsigned  row_start,
unsigned  col_start,
const M &  m,
Transposition  trans = eNoTranspose 
)
inline

Sets the specified sub matrix.

Parameters
row_startthe row to start (inclusive)
col_startthe column to start (inclusive)
mthe source matrix
transposedetermines whether the m is to be transposed
Note
fails assertion if m is too large to insert into this

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