Algebra3D
Algebra for 3D transformations
 All Classes Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
algebra3d::Matrix3< fpType > Class Template Reference

A class to store 3x3 rotation matrices. More...

#include <Matrix3.h>

Public Member Functions

 Matrix3 (bool identity=false)
 
 Matrix3 (const fpType(&data)[3][3])
 
 Matrix3 (const fpType *data)
 
 Matrix3 (const Vector3< fpType > &col1, const Vector3< fpType > &col2, const Vector3< fpType > &col3)
 
 Matrix3 (fpType m11, fpType m12, fpType m13, fpType m21, fpType m22, fpType m23, fpType m31, fpType m32, fpType m33)
 
 Matrix3 (const Matrix3< fpType > &mat)
 
 Matrix3 (const Vector3< fpType > &cvec)
 
 Matrix3 (Vector3< fpType > axis, fpType angle)
 
 Matrix3 (const Quaternion< fpType > &quat)
 
virtual ~Matrix3 ()
 
virtual void set (const fpType data[3][3])
 
virtual void set (const Vector3< fpType > &col1, const Vector3< fpType > &col2, const Vector3< fpType > &col3)
 
virtual void get (fpType storage[3][3]) const
 
virtual void get (fpType *const col1, fpType *const col2, fpType *const col3) const
 
virtual void setColumn (int index, const Vector3< fpType > &col)
 
virtual void getColumn (int index, fpType *const &col)
 
virtual Vector3< fpType > getColumn (int index)
 
fpType getTrace () const
 
virtual void transpose ()
 
virtual Matrix3 getTranspose () const
 
Vector3< fpType > getAxis () const
 
fpType getAngle () const
 
virtual void invert ()
 
virtual Matrix3 getInverse () const
 
virtual fpType det ()
 
virtual bool isOrthogonal ()
 
virtual void operator= (const Matrix3 &mat)
 
virtual const fpType(& operator[] (int i1) const)[3]
 
virtual fpType(& operator[] (int i1))[3]
 
virtual bool compare (const Matrix3< fpType > &mat, const fpType &precision=PRECISION) const
 
virtual bool operator== (const Matrix3 &mat) const
 
virtual bool operator!= (const Matrix3 &mat) const
 
virtual void operator+= (const Matrix3 &mat)
 
virtual Matrix3 operator+ (const Matrix3 &mat) const
 
virtual Matrix3 operator- () const
 
virtual void operator-= (const Matrix3 &mat)
 
virtual Matrix3 operator- (const Matrix3 &mat) const
 
virtual void operator*= (const Matrix3 &mat)
 
virtual Matrix3 operator* (const Matrix3 &mat) const
 
virtual Vector3< fpType > operator* (const Vector3< fpType > &vec) const
 
virtual void operator*= (const fpType &scale)
 
virtual Matrix3 operator* (const fpType &scale) const
 
virtual void operator/= (const fpType &scale)
 
virtual Matrix3 operator/ (const fpType &scale) const
 

Protected Member Functions

virtual void initialize (bool identity=false)
 

Protected Attributes

fpType data [3][3]
 

Static Protected Attributes

static const int ADJUGATE_INDICES [3][3][4][2]
 

Friends

template<class fpT >
std::istream & operator>> (std::istream &stream, Matrix3< fpT > &mat)
 

Detailed Description

template<class fpType>
class algebra3d::Matrix3< fpType >

A class to store 3x3 rotation matrices.

Column first storage convention is used here. It is not limited to SO(3) matrices.

Author
Jarek Glowacki

Constructor & Destructor Documentation

template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( bool  identity = false)

Creates an instance of a matrix. The parameter defines if identity (true) or zero matrix (false) is requested.

Parameters
[in]identityidentity true or zero matrix false is requested; false by default.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( const fpType(&)  data[3][3])

Creates an instance using the provided data. Data is stored by columns (Matrix::data[2][0] is third column first row)

Parameters
[in]dataReference to the data to set the matrix to.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( const fpType *  data)

Creates an instance using the provided data. First 9 positions. are read: first 3 - first column, second 3 - second column, third 3 - third column.

Parameters
[in]dataReference to the data to set the matrix to.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( const Vector3< fpType > &  col1,
const Vector3< fpType > &  col2,
const Vector3< fpType > &  col3 
)

Creates an instance using the provided vectors as columns. Data is stored by columns, so Matrix::data[0] becomes the fist vector, Matrix::data[1] the second and so on.

Parameters
[in]col1The first column of the matrix.
[in]col2The second column of the matrix.
[in]col3The third column of the matrix.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( fpType  m11,
fpType  m12,
fpType  m13,
fpType  m21,
fpType  m22,
fpType  m23,
fpType  m31,
fpType  m32,
fpType  m33 
)

Creates an instance using the provided values.

Parameters
[in]m11The element to becomeMatrix::data[0][0].
[in]m12The element to becomeMatrix::data[1][0].
[in]m13The element to becomeMatrix::data[2][0].
[in]m21The element to becomeMatrix::data[0][1].
[in]m22The element to becomeMatrix::data[1][1].
[in]m23The element to becomeMatrix::data[2][1].
[in]m31The element to becomeMatrix::data[0][2].
[in]m32The element to becomeMatrix::data[1][2].
[in]m33The element to becomeMatrix::data[2][2].
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( const Matrix3< fpType > &  mat)

Copies elements of the provided matrix into this one.

Parameters
[in]matThe matrix to copy.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( const Vector3< fpType > &  cvec)

Creates a rotation matrix for the provided Cayley vector.

Parameters
[in]cvecThe Cayley vector describing the rotation.
Note
Passes though a Quaternion for efficiency.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( Vector3< fpType >  axis,
fpType  angle 
)

Creates a rotation matrix for the provided axis (not necessarily unit length) and angle (in radians).

Parameters
[in]axisThe rotation axis (of any length).
[in]angleThe rotation angle in radians.
template<class fpType>
algebra3d::Matrix3< fpType >::Matrix3 ( const Quaternion< fpType > &  quat)

Creates a rotation matrix for the provided quaternion.

Parameters
[in]quatThe rotation axis (of any length).
template<class fpType>
virtual algebra3d::Matrix3< fpType >::~Matrix3 ( )
virtual

Does nothing. Virtual classes require virtual destructors.

Member Function Documentation

template<class fpType>
virtual bool algebra3d::Matrix3< fpType >::compare ( const Matrix3< fpType > &  mat,
const fpType &  precision = PRECISION 
) const
virtual

Checks if all elements of the provided matrix are the same as in this one up to the provided precision. The comparison is simply checking if the difference between numbers is smaller or equal the precision.

Parameters
[in]matThe matrix to compare this with.
[in]precisionThe precision to use; by default the global PRECISION is used.
Returns
true if all entries are equal up to the precision, false otherwise.
template<class fpType>
virtual fpType algebra3d::Matrix3< fpType >::det ( )
virtual

Returns the determinant of this matrix.

Returns
The determinant of this matrix.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::get ( fpType  storage[3][3]) const
virtual

Copies the matrix data to the provided array.

Parameters
[out]storageThe array to copy the data to.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::get ( fpType *const  col1,
fpType *const  col2,
fpType *const  col3 
) const
virtual

Copies the matrix data to the provided arrays. Each array is assumed to be at least of size [3].

Parameters
[out]col1Storage for the first column of the matrix.
[out]col2Storage for the second column of the matrix.
[out]col3Storage for the third column of the matrix.
template<class fpType>
fpType algebra3d::Matrix3< fpType >::getAngle ( ) const

Returns the angle of the rotation this matrix represents. If the matrix is not orthogonal this may result in an error.

Returns
The angle of the rotation this matrix represents.
template<class fpType>
Vector3<fpType> algebra3d::Matrix3< fpType >::getAxis ( ) const

Returns the unit axis vector of the rotation this matrix represents. For identity and zero vector is returned. For rotation by PI infinity vector. If the matrix is not orthogonal this may result in an error.

Returns
The axis of the rotation this matrix represents. For identity and zero vector is returned. For rotation by PI - infinity vector.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::getColumn ( int  index,
fpType *const &  col 
)
virtual

Copies data of the column with the provided index to the provided array.

Parameters
[in]indexIndex of the column to copy.
[out]colThe storage place to copy to.
template<class fpType>
virtual Vector3<fpType> algebra3d::Matrix3< fpType >::getColumn ( int  index)
virtual

Returns the requested column as a vector.

Parameters
[in]indexIndex of the column to copy.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::getInverse ( ) const
virtual

Returns the inverse of this matrix. If the determinant is close to 0 zero matrix is returned.

Returns
The inverse of this matrix.
template<class fpType>
fpType algebra3d::Matrix3< fpType >::getTrace ( ) const

Returns the trace of the matrix.

Returns
The trace of the matrix.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::getTranspose ( ) const
virtual

Returns the transpose of this matrix.

Returns
The transpose of this matrix.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::initialize ( bool  identity = false)
protectedvirtual

Initializes the instance of a matrix. Used by constructors. The parameter defines if identity (true) or zero matrix (false) is requested.

Parameters
[in]identityidentity true or zero matrix false is requested; false by default.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::invert ( )
virtual

Inverts this matrix. If the determinant is close to 0.0 the matrix is set to 0.

template<class fpType>
virtual bool algebra3d::Matrix3< fpType >::isOrthogonal ( )
virtual

Returns true if the matrix is orthogonal, false otherwise.

Returns
true if the matrix is orthogonal, false otherwise.
template<class fpType>
virtual bool algebra3d::Matrix3< fpType >::operator!= ( const Matrix3< fpType > &  mat) const
virtual

Checks if any element of this matrix differs from respective element of the parameter.

Parameters
[in]matThe matrix to compare this with.
Returns
false if all entries are equal, true otherwise.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::operator* ( const Matrix3< fpType > &  mat) const
virtual

Post-multiplies a copy of this matrix by the provided one and returns the result.

Parameters
[in]matThe matrix to post-multiply this by.
Returns
The result of the post-multiplication.
template<class fpType>
virtual Vector3<fpType> algebra3d::Matrix3< fpType >::operator* ( const Vector3< fpType > &  vec) const
virtual

Returns the product of this matrix and the provided vector. (m * v - vector treated as 3x1).

Parameters
[in]vecThe vector to pre-multiply by this matrix.
Returns
The result of the post-multiplication.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::operator* ( const fpType &  scale) const
virtual

Scales a copy of this matrix by the provided number and returns it.

Parameters
[in]scaleThe scaling factor.
Returns
The scaled matrix.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::operator*= ( const Matrix3< fpType > &  mat)
virtual

Post-multiplies this matrix by the provided one.

Parameters
[in]matThe matrix to post-multiply this by.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::operator*= ( const fpType &  scale)
virtual

Scales a this matrix by the provided number.

Parameters
[in]scaleThe scaling factor.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::operator+ ( const Matrix3< fpType > &  mat) const
virtual

Returns the sum of this matrix and the provided one.

Parameters
[in]matThe other argument of the sum.
Returns
The sum of this matrix and the provided one.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::operator+= ( const Matrix3< fpType > &  mat)
virtual

Adds the provided matrix to this one.

Parameters
[in]matThe matrix to add.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::operator- ( ) const
virtual

Returns a copy of this matrix multiplied by -1.

Returns
A copy of this matrix multiplied by -1.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::operator- ( const Matrix3< fpType > &  mat) const
virtual

Returns the result of subtracting the provided matrix from this one.

Parameters
[in]matThe matrix to subtract.
Returns
The result of subtracting the provided matrix from this one.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::operator-= ( const Matrix3< fpType > &  mat)
virtual

Subtracts the provided matrix from this one.

Parameters
[in]matThe matrix to subtract.
template<class fpType>
virtual Matrix3 algebra3d::Matrix3< fpType >::operator/ ( const fpType &  scale) const
virtual

Scales a copy of this matrix by the inverse of the provided number and returns it.

Parameters
[in]scaleThe inverse scaling factor.
Returns
The scaled matrix.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::operator/= ( const fpType &  scale)
virtual

Scales a this matrix by the inverse of the provided number.

Parameters
[in]scaleThe inverse scaling factor.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::operator= ( const Matrix3< fpType > &  mat)
virtual

Copies elements of the provided matrix into this one.

Parameters
[in]matThe matrix to copy.
template<class fpType>
virtual bool algebra3d::Matrix3< fpType >::operator== ( const Matrix3< fpType > &  mat) const
virtual

Comparing operator. Checks if all elements of the provided matrix are the same as this.

Parameters
[in]matThe matrix to compare this with.
Returns
true if all entries are equal, false otherwise.
template<class fpType>
virtual const fpType(& algebra3d::Matrix3< fpType >::operator[] ( int  i1) )[3] const
virtual

Returns a reference to the column with the provided index. If the index is incorrect the closest correct one is used is returned. Version for constant instances.

Parameters
[in]i1Index of the column of the element to return.
Returns
Reference to the selected column or NULL for incorrect index.
template<class fpType>
virtual fpType(& algebra3d::Matrix3< fpType >::operator[] ( int  i1) )[3]
virtual

Returns a reference to the column with the provided index. If the index is incorrect NULL is returned.

Parameters
[in]i1Index of the column of the element to return.
Returns
Reference to the selected column or NULL for incorrect index.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::set ( const fpType  data[3][3])
virtual

Sets the matrix data to the values in the provided array.

Parameters
[in]dataThe array with values to set.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::set ( const Vector3< fpType > &  col1,
const Vector3< fpType > &  col2,
const Vector3< fpType > &  col3 
)
virtual

Sets the matrix data to the data provided as column vectors.

Parameters
[in]col1The first column of the matrix.
[in]col2The second column of the matrix.
[in]col3The third column of the matrix.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::setColumn ( int  index,
const Vector3< fpType > &  col 
)
virtual

Sets the column with the provided index to the provided vector.

Parameters
[in]indexIndex of the column to set.
[in]colThe column data.
template<class fpType>
virtual void algebra3d::Matrix3< fpType >::transpose ( )
virtual

Transposes this matrix.

Member Data Documentation

template<class fpType>
const int algebra3d::Matrix3< fpType >::ADJUGATE_INDICES[3][3][4][2]
staticprotected

Indices for computing adjugate matrix. The indices are:

  • column of the final matrix
  • row of the final matrix
  • element of the 2 by 2 det (first the ones that come positive, than the ones that come negative)
  • a pair of column, row indices
template<class fpType>
fpType algebra3d::Matrix3< fpType >::data[3][3]
protected

The matrix data.


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