wfmath 1.0.3
A math library for the Worldforge system.
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

 RotMatrix (const RotMatrix &m)=default
 
RotMatrixoperator= (const RotMatrix &m)=default
 
bool isEqualTo (const RotMatrix &m, CoordType epsilon=numeric_constants< CoordType >::epsilon()) const
 
bool operator== (const RotMatrix &m) const
 
bool operator!= (const RotMatrix &m) const
 
bool isValid () const
 
RotMatrixidentity ()
 set the matrix to the identity matrix More...
 
CoordType elem (const int i, const int j) const
 get the (i, j) element 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...
 
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 (int i) const
 Get a copy of the i'th row as a Vector. More...
 
Vector< dim > column (int i) const
 Get a copy of the i'th column as a Vector. More...
 
CoordType trace () const
 Get the trace of the matrix. More...
 
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 (int i, int j, CoordType theta)
 set the matrix to a rotation by the angle theta in the (i, j) plane More...
 
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 (int i)
 set the matrix to a mirror perpendicular to the i'th axis More...
 
RotMatrixmirror (const Vector< dim > &v)
 set the matrix to a mirror perpendicular to the Vector v More...
 
RotMatrixmirror ()
 set the matrix to mirror all axes More...
 
RotMatrixrotate (const RotMatrix &m)
 rotate the matrix using another matrix More...
 
void normalize ()
 normalize to remove accumulated round-off error More...
 
unsigned age () const
 current round-off age More...
 
 RotMatrix (const Quaternion &q, 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 More...
 
RotMatrixrotationX (CoordType theta)
 3D only: set a RotMatrix to a rotation about the x axis by angle theta More...
 
RotMatrixrotationY (CoordType theta)
 3D only: set a RotMatrix to a rotation about the y axis by angle theta More...
 
RotMatrixrotationZ (CoordType theta)
 3D only: set a RotMatrix to a rotation about the z axis by angle theta More...
 
RotMatrixrotation (const Vector< dim > &axis, CoordType theta)
 3D only: set a RotMatrix to a rotation about the axis given by the Vector More...
 
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, bool not_flip=true)
 3D only: set a RotMatrix from a Quaternion More...
 
RotMatrixrotate (const Quaternion &)
 rotate the matrix using the quaternion More...
 
RotMatrixmirrorX ()
 set a RotMatrix to a mirror perpendicular to the x axis More...
 
RotMatrixmirrorY ()
 set a RotMatrix to a mirror perpendicular to the y axis More...
 
RotMatrixmirrorZ ()
 set a RotMatrix to a mirror perpendicular to the z axis More...
 
RotMatrix< 3 > & fromQuaternion (const Quaternion &q, const bool not_flip)
 
RotMatrix< 3 > & rotate (const Quaternion &q)
 
RotMatrix< 3 > & rotation (const Vector< 3 > &axis, CoordType theta)
 
RotMatrix< 3 > & rotation (const Vector< 3 > &axis)
 
 RotMatrix (const Quaternion &q, const bool not_flip)
 
RotMatrix< 3 > & mirrorZ ()
 
RotMatrix< 3 > & rotation (const Vector< 3 > &axis, CoordType theta)
 
RotMatrix< 3 > & rotation (const Vector< 3 > &axis)
 
RotMatrix< 3 > & fromQuaternion (const Quaternion &q, const bool not_flip)
 
RotMatrix< 3 > & rotate (const Quaternion &)
 

Friends

std::ostream & operator (std::ostream &os, const RotMatrix &m)
 
std::istream & operator>> (std::istream &is, RotMatrix &m)
 
RotMatrix Prod (const RotMatrix &m1, const RotMatrix &m2)
 returns m1 * m2 More...
 
RotMatrix ProdInv (const RotMatrix &m1, const RotMatrix &m2)
 returns m1 * m2^-1 More...
 
RotMatrix InvProd (const RotMatrix &m1, const RotMatrix &m2)
 returns m1^-1 * m2 More...
 
RotMatrix InvProdInv (const RotMatrix &m1, const RotMatrix &m2)
 returns m1^-1 * m2^-1 More...
 
Vector< dim > Prod (const RotMatrix &m, const Vector< dim > &v)
 returns m * v More...
 
Vector< dim > InvProd (const RotMatrix &m, const Vector< dim > &v)
 returns m^-1 * v More...
 

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.

Definition at line 87 of file rotmatrix.h.

Constructor & Destructor Documentation

◆ RotMatrix() [1/3]

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

Definition at line 90 of file rotmatrix.h.

◆ RotMatrix() [2/3]

template<int dim = 3>
WFMath::RotMatrix< dim >::RotMatrix ( const Quaternion q,
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

◆ RotMatrix() [3/3]

WFMath::RotMatrix< 3 >::RotMatrix ( const Quaternion q,
const bool  not_flip 
)

Definition at line 369 of file rotmatrix.cpp.

Member Function Documentation

◆ age()

template<int dim = 3>
unsigned WFMath::RotMatrix< dim >::age ( ) const
inline

current round-off age

Definition at line 201 of file rotmatrix.h.

Referenced by WFMath::Quaternion::fromRotMatrix().

◆ column()

template<int dim>
Vector< dim > WFMath::RotMatrix< dim >::column ( int  i) const
inline

Get a copy of the i'th column as a Vector.

Definition at line 289 of file rotmatrix_funcs.h.

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

◆ 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.

Definition at line 144 of file rotmatrix.h.

◆ elem()

template<int dim = 3>
CoordType WFMath::RotMatrix< dim >::elem ( const int  i,
const int  j 
) const
inline

get the (i, j) element of the matrix

Definition at line 112 of file rotmatrix.h.

Referenced by WFMath::Quaternion::fromRotMatrix().

◆ fromQuaternion() [1/2]

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::fromQuaternion ( const Quaternion q,
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

◆ fromQuaternion() [2/2]

RotMatrix< 3 > & WFMath::RotMatrix< 3 >::fromQuaternion ( const Quaternion q,
const bool  not_flip 
)

Definition at line 39 of file rotmatrix.cpp.

◆ identity()

template<int dim>
RotMatrix< dim > & WFMath::RotMatrix< dim >::identity
inline

set the matrix to the identity matrix

Definition at line 318 of file rotmatrix_funcs.h.

Referenced by WFMath::RotBox< dim >::fromAtlas().

◆ inverse()

template<int dim>
RotMatrix< dim > WFMath::RotMatrix< dim >::inverse
inline

Get the inverse of the matrix.

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

Definition at line 302 of file rotmatrix_funcs.h.

◆ isEqualTo()

template<int dim>
bool WFMath::RotMatrix< dim >::isEqualTo ( const RotMatrix< dim > &  m,
CoordType  epsilon = numeric_constants<CoordType>::epsilon() 
) const
inline

Definition at line 42 of file rotmatrix_funcs.h.

◆ isValid()

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

Definition at line 106 of file rotmatrix.h.

◆ mirror() [1/3]

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.

Definition at line 521 of file rotmatrix_funcs.h.

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

◆ mirror() [2/3]

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

set the matrix to a mirror perpendicular to the Vector v

Definition at line 492 of file rotmatrix_funcs.h.

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

◆ mirror() [3/3]

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

set the matrix to a mirror perpendicular to the i'th axis

Definition at line 269 of file rotmatrix.h.

◆ mirrorX()

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::mirrorX ( )
inline

set a RotMatrix to a mirror perpendicular to the x axis

Definition at line 245 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::mirror().

◆ mirrorY()

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::mirrorY ( )
inline

set a RotMatrix to a mirror perpendicular to the y axis

Definition at line 247 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::mirror().

◆ mirrorZ() [1/2]

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::mirrorZ ( )

set a RotMatrix to a mirror perpendicular to the z axis

◆ mirrorZ() [2/2]

RotMatrix< 3 > & WFMath::RotMatrix< 3 >::mirrorZ ( )
inline

Definition at line 263 of file rotmatrix.h.

◆ normalize()

template<int dim>
void WFMath::RotMatrix< dim >::normalize
inline

normalize to remove accumulated round-off error

Definition at line 538 of file rotmatrix_funcs.h.

◆ operator!=()

template<int dim = 3>
bool WFMath::RotMatrix< dim >::operator!= ( const RotMatrix< dim > &  m) const
inline

Definition at line 104 of file rotmatrix.h.

◆ operator==()

template<int dim = 3>
bool WFMath::RotMatrix< dim >::operator== ( const RotMatrix< dim > &  m) const
inline

Definition at line 103 of file rotmatrix.h.

◆ 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.

Definition at line 154 of file rotmatrix.h.

Referenced by WFMath::Quaternion::fromRotMatrix().

◆ rotate() [1/3]

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::rotate ( const Quaternion )

rotate the matrix using the quaternion

◆ rotate() [2/3]

RotMatrix< 3 > & WFMath::RotMatrix< 3 >::rotate ( const Quaternion q)

Definition at line 76 of file rotmatrix.cpp.

◆ rotate() [3/3]

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::rotate ( const RotMatrix< dim > &  m)
inline

rotate the matrix using another matrix

Definition at line 196 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::Prod.

◆ rotation() [1/8]

RotMatrix< 3 > & WFMath::RotMatrix< 3 >::rotation ( const Vector< 3 > &  axis)

Definition at line 128 of file rotmatrix.cpp.

◆ rotation() [2/8]

RotMatrix< 3 > & WFMath::RotMatrix< 3 >::rotation ( const Vector< 3 > &  axis,
CoordType  theta 
)

Definition at line 99 of file rotmatrix.cpp.

◆ rotation() [3/8]

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

◆ rotation() [4/8]

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

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

◆ rotation() [5/8]

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.

Definition at line 422 of file rotmatrix_funcs.h.

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

◆ rotation() [6/8]

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

Definition at line 377 of file rotmatrix_funcs.h.

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

◆ rotation() [7/8]

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::rotation ( CoordType  theta)
inline

2D only: Construct a RotMatrix from an angle theta

Definition at line 215 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::rotation().

◆ rotation() [8/8]

template<int dim>
RotMatrix< dim > & WFMath::RotMatrix< dim >::rotation ( int  i,
int  j,
CoordType  theta 
)

◆ rotationX()

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::rotationX ( CoordType  theta)
inline

3D only: set a RotMatrix to a rotation about the x axis by angle theta

Definition at line 219 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::rotation().

◆ rotationY()

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::rotationY ( CoordType  theta)
inline

3D only: set a RotMatrix to a rotation about the y axis by angle theta

Definition at line 221 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::rotation().

◆ rotationZ()

template<int dim = 3>
RotMatrix & WFMath::RotMatrix< dim >::rotationZ ( CoordType  theta)
inline

3D only: set a RotMatrix to a rotation about the z axis by angle theta

Definition at line 223 of file rotmatrix.h.

References WFMath::RotMatrix< dim >::rotation().

◆ row()

template<int dim>
Vector< dim > WFMath::RotMatrix< dim >::row ( int  i) const
inline

Get a copy of the i'th row as a Vector.

Definition at line 276 of file rotmatrix_funcs.h.

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

◆ 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.

Definition at line 237 of file rotmatrix_funcs.h.

◆ 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.

Definition at line 224 of file rotmatrix_funcs.h.

◆ trace()

template<int dim>
CoordType WFMath::RotMatrix< dim >::trace
inline

Get the trace of the matrix.

Definition at line 332 of file rotmatrix_funcs.h.

Referenced by WFMath::Quaternion::fromRotMatrix().

Friends And Related Function Documentation

◆ InvProd [1/2]

template<int dim = 3>
Vector< dim > InvProd ( const RotMatrix< dim > &  m,
const Vector< dim > &  v 
)
friend

returns m^-1 * v

Definition at line 177 of file rotmatrix_funcs.h.

◆ InvProd [2/2]

template<int dim = 3>
RotMatrix InvProd ( const RotMatrix< dim > &  m1,
const RotMatrix< dim > &  m2 
)
friend

returns m1^-1 * m2

Definition at line 116 of file rotmatrix_funcs.h.

◆ InvProdInv

template<int dim = 3>
RotMatrix InvProdInv ( const RotMatrix< dim > &  m1,
const RotMatrix< dim > &  m2 
)
friend

returns m1^-1 * m2^-1

Definition at line 138 of file rotmatrix_funcs.h.

◆ operator>>

template<int dim = 3>
std::istream & operator>> ( std::istream &  is,
RotMatrix< dim > &  m 
)
friend

Definition at line 149 of file stream.h.

◆ Prod [1/2]

template<int dim = 3>
Vector< dim > Prod ( const RotMatrix< dim > &  m,
const Vector< dim > &  v 
)
friend

returns m * v

Definition at line 160 of file rotmatrix_funcs.h.

◆ Prod [2/2]

template<int dim = 3>
RotMatrix Prod ( const RotMatrix< dim > &  m1,
const RotMatrix< dim > &  m2 
)
friend

returns m1 * m2

Definition at line 72 of file rotmatrix_funcs.h.

Referenced by WFMath::RotMatrix< dim >::rotate().

◆ ProdInv

template<int dim = 3>
RotMatrix ProdInv ( const RotMatrix< dim > &  m1,
const RotMatrix< dim > &  m2 
)
friend

returns m1 * m2^-1

Definition at line 94 of file rotmatrix_funcs.h.


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