WFMath  1.0.2
Public Member Functions | Friends | List of all members
WFMath::RotMatrix< dim > Class Template Reference

A dim dimensional rotation matrix. Technically, a member of the group O(dim). More...

#include <rotmatrix.h>

Public Member Functions

RotMatrixidentity ()
 set the matrix to the identity matrix
 
CoordType elem (const int i, const int j) const
 get the (i, j) element of the matrix
 
bool setVals (const CoordType vals[dim][dim], CoordType precision=numeric_constants< CoordType >::epsilon())
 Set the values of the elements of the matrix. More...
 
bool setVals (const CoordType vals[dim *dim], CoordType precision=numeric_constants< CoordType >::epsilon())
 Set the values of the elements of the matrix. More...
 
Vector< dim > row (const int i) const
 Get a copy of the i'th row as a Vector.
 
Vector< dim > column (const int i) const
 Get a copy of the i'th column as a Vector.
 
CoordType trace () const
 Get the trace of the matrix.
 
CoordType determinant () const
 Get the determinant of the matrix. More...
 
RotMatrix inverse () const
 Get the inverse of the matrix. More...
 
bool parity () const
 Get the parity of the matrix. More...
 
RotMatrixrotation (const int i, const int j, CoordType theta)
 set the matrix to a rotation by the angle theta in the (i, j) plane
 
RotMatrixrotation (const Vector< dim > &v1, const Vector< dim > &v2, CoordType theta)
 set the matrix to a rotation by the angle theta in the v1, v2 plane More...
 
RotMatrixrotation (const Vector< dim > &from, const Vector< dim > &to)
 set the matrix to a rotation which will move "from" to lie parallel to "to" More...
 
RotMatrixmirror (const int i)
 set the matrix to a mirror perpendicular to the i'th axis
 
RotMatrixmirror (const Vector< dim > &v)
 set the matrix to a mirror perpendicular to the Vector v
 
RotMatrixmirror ()
 set the matrix to mirror all axes More...
 
RotMatrixrotate (const RotMatrix &m)
 rotate the matrix using another matrix
 
void normalize ()
 normalize to remove accumulated round-off error
 
unsigned age () const
 current round-off age
 
 RotMatrix (const Quaternion &q, const bool not_flip=true)
 3D only: Construct a RotMatrix from a Quaternion More...
 
RotMatrixrotation (CoordType theta)
 2D only: Construct a RotMatrix from an angle theta
 
RotMatrixrotationX (CoordType theta)
 3D only: set a RotMatrix to a rotation about the x axis by angle theta
 
RotMatrixrotationY (CoordType theta)
 3D only: set a RotMatrix to a rotation about the y axis by angle theta
 
RotMatrixrotationZ (CoordType theta)
 3D only: set a RotMatrix to a rotation about the z axis by angle theta
 
RotMatrixrotation (const Vector< dim > &axis, CoordType theta)
 3D only: set a RotMatrix to a rotation about the axis given by the Vector
 
RotMatrixrotation (const Vector< dim > &axis)
 3D only: set a RotMatrix to a rotation about the axis given by the Vector More...
 
RotMatrixfromQuaternion (const Quaternion &q, const bool not_flip=true)
 3D only: set a RotMatrix from a Quaternion More...
 
RotMatrixrotate (const Quaternion &)
 rotate the matrix using the quaternion
 
RotMatrixmirrorX ()
 set a RotMatrix to a mirror perpendicular to the x axis
 
RotMatrixmirrorY ()
 set a RotMatrix to a mirror perpendicular to the y axis
 
RotMatrixmirrorZ ()
 set a RotMatrix to a mirror perpendicular to the z axis
 

Friends

RotMatrix Prod (const RotMatrix &m1, const RotMatrix &m2)
 returns m1 * m2
 
RotMatrix ProdInv (const RotMatrix &m1, const RotMatrix &m2)
 returns m1 * m2^-1
 
RotMatrix InvProd (const RotMatrix &m1, const RotMatrix &m2)
 returns m1^-1 * m2
 
RotMatrix InvProdInv (const RotMatrix &m1, const RotMatrix &m2)
 returns m1^-1 * m2^-1
 
Vector< dim > Prod (const RotMatrix &m, const Vector< dim > &v)
 returns m * v
 
Vector< dim > InvProd (const RotMatrix &m, const Vector< dim > &v)
 returns m^-1 * v
 

Detailed Description

template<int dim = 3>
class WFMath::RotMatrix< dim >

A dim dimensional rotation matrix. Technically, a member of the group O(dim).

Elements of this class represent rotation matrices. The NxN dimensional rotation matrices form a group called O(N), the orthogonal matrices. They satisfy the following condition:

They are orthogonal. That is, their transpose is equal to their inverse. Hence, this class does not implement a transpose() method, only an inverse().

A general N dimensional matrix of this type has N(N-1)/2 degrees of freedom. This gives one rotation angle in 2D, the three Euler angles in 3D, etc.

This class implements the 'generic' subset of the interface in the fake class Shape.

Constructor & Destructor Documentation

◆ RotMatrix()

template<int dim = 3>
WFMath::RotMatrix< dim >::RotMatrix ( const Quaternion q,
const bool  not_flip = true 
)

3D only: Construct a RotMatrix from a Quaternion

since Quaternions can only specify parity-even rotations, you can pass the return value of Quaternion::fromRotMatrix() as not_flip to recover the full RotMatrix

Member Function Documentation

◆ determinant()

template<int dim = 3>
CoordType WFMath::RotMatrix< dim >::determinant ( ) const
inline

Get the determinant of the matrix.

Since the matrix is orthogonal, the determinant is always either 1 or -1.

◆ fromQuaternion()

template<int dim = 3>
RotMatrix& WFMath::RotMatrix< dim >::fromQuaternion ( const Quaternion q,
const bool  not_flip = true 
)

3D only: set a RotMatrix from a Quaternion

since Quaternions can only specify parity-even rotations, you can pass the return value of Quaternion::fromRotMatrix() as not_flip to recover the full RotMatrix

◆ inverse()

template<int dim>
RotMatrix< dim > WFMath::RotMatrix< dim >::inverse ( ) const
inline

Get the inverse of the matrix.

Since the matrix is orthogonal, the inverse is equal to the transpose.

◆ mirror()

template<int dim>
RotMatrix< dim > & WFMath::RotMatrix< dim >::mirror ( )
inline

set the matrix to mirror all axes

This is a good parity operator if dim is odd.

Referenced by WFMath::RotMatrix< dim >::mirrorX(), and WFMath::RotMatrix< dim >::mirrorY().

◆ parity()

template<int dim = 3>
bool WFMath::RotMatrix< dim >::parity ( ) const
inline

Get the parity of the matrix.

Returns true for odd parity, false for even.

◆ rotation() [1/3]

template<int dim>
RotMatrix< dim > & WFMath::RotMatrix< dim >::rotation ( const Vector< dim > &  v1,
const Vector< dim > &  v2,
CoordType  theta 
)

set the matrix to a rotation by the angle theta in the v1, v2 plane

Throws CollinearVectors if v1 and v2 are parallel

References WFMath::Vector< dim >::sqrMag().

◆ rotation() [2/3]

template<int dim>
RotMatrix< dim > & WFMath::RotMatrix< dim >::rotation ( const Vector< dim > &  from,
const Vector< dim > &  to 
)

set the matrix to a rotation which will move "from" to lie parallel to "to"

Throws CollinearVectors if v1 and v2 are antiparallel (parallel but pointing in opposite directions). If v1 and v2 point in the same direction, the matrix is set to the identity.

References WFMath::Vector< dim >::sqrMag().

◆ rotation() [3/3]

template<int dim = 3>
RotMatrix& WFMath::RotMatrix< dim >::rotation ( const Vector< dim > &  axis)

3D only: set a RotMatrix to a rotation about the axis given by the Vector

the rotation angle is taken from the Vector's magnitude

◆ setVals() [1/2]

template<int dim>
bool WFMath::RotMatrix< dim >::setVals ( const CoordType  vals[dim][dim],
CoordType  precision = numeric_constants<CoordType>::epsilon() 
)
inline

Set the values of the elements of the matrix.

Can't set one element at a time and keep it an O(N) matrix, but can try to set all values at once, and see if they match. This fails if the passed matrix is not orthogonal within the passed precision, and orthogonalizes the matrix to within precision WFMATH_EPSILON.

◆ setVals() [2/2]

template<int dim>
bool WFMath::RotMatrix< dim >::setVals ( const CoordType  vals[dim *dim],
CoordType  precision = numeric_constants<CoordType>::epsilon() 
)
inline

Set the values of the elements of the matrix.

Can't set one element at a time and keep it an O(N) matrix, but can try to set all values at once, and see if they match. This fails if the passed matrix is not orthogonal within the passed precision, and orthogonalizes the matrix to within precision WFMATH_EPSILON.


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