# WFMath_RotMatrix (3) - Linux Manuals

## NAME

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

## SYNOPSIS

#include <rotmatrix.h>

### Public Member Functions

RotMatrix & identity ()
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], double precision=WFMATH_EPSILON)
Set the values of the elements of the matrix.
bool setVals (const CoordType vals[dim *dim], double precision=WFMATH_EPSILON)
Set the values of the elements of the matrix.
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.
RotMatrix inverse () const
Get the inverse of the matrix.
bool parity () const
Get the parity of the matrix.
RotMatrix & rotation (const int i, const int j, CoordType theta)
set the matrix to a rotation by the angle theta in the (i, j) plane
RotMatrix & 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
RotMatrix & rotation (const Vector< dim > &from, const Vector< dim > &to)
set the matrix to a rotation which will move 'from' to lie parallel to 'to'
RotMatrix & mirror (const int i)
set the matrix to a mirror perpendicular to the i'th axis
RotMatrix & mirror (const Vector< dim > &v)
set the matrix to a mirror perpendicular to the Vector v
RotMatrix & mirror ()
set the matrix to mirror all axes
RotMatrix & rotate (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
RotMatrix< 2 > & rotation (CoordType theta)
2D only: Construct a RotMatrix from an angle theta
RotMatrix< 3 > & rotationX (CoordType theta)
3D only: set a RotMatrix to a rotation about the x axis by angle theta
RotMatrix< 3 > & rotationY (CoordType theta)
3D only: set a RotMatrix to a rotation about the y axis by angle theta
RotMatrix< 3 > & rotationZ (CoordType theta)
3D only: set a RotMatrix to a rotation about the z axis by angle theta
RotMatrix< 3 > & rotation (const Vector< 3 > &axis, CoordType theta)
3D only: set a RotMatrix to a rotation about the axis given by the Vector
RotMatrix< 3 > & rotation (const Vector< 3 > &axis)
3D only: set a RotMatrix to a rotation about the axis given by the Vector
RotMatrix< 3 > & fromQuaternion (const Quaternion &q, const bool not_flip=true)
3D only: set a RotMatrix from a Quaternion
RotMatrix< 3 > & rotate (const Quaternion &)
rotate the matrix using the quaternion
RotMatrix & mirrorX ()
set a RotMatrix to a mirror perpendicular to the x axis
RotMatrix & mirrorY ()
set a RotMatrix to a mirror perpendicular to the y axis
RotMatrix & mirrorZ ()
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<const int dim> 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

### template<const int dim> WFMath::RotMatrix< dim >::RotMatrix (const Quaternion & q, const bool not_flip = true) [inline]

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

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

## Member Function Documentation

### template<const int dim> CoordTypeWFMath::RotMatrix< dim >::determinant () const [inline]

Get the determinant of the matrix.

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

### template<const int dim> RotMatrix<3>& 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

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

### template<const 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.

### template<const 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(), WFMath::RotMatrix< dim >::mirrorY(), and WFMath::RotMatrix< dim >::mirrorZ().

### template<const int dim> bool WFMath::RotMatrix< dim >::parity () const [inline]

Get the parity of the matrix.

Returns true for odd parity, false for even.

### template<const int dim> RotMatrix<3>& WFMath::RotMatrix< dim >::rotation (const Vector< 3 > & 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

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

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().

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

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::RotMatrix< dim >::identity(), and WFMath::Vector< dim >::sqrMag().

### template<const int dim> bool WFMath::RotMatrix< dim >::setVals (const CoordType vals[dim *dim], double precision = WFMATH_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.

### template<const int dim> bool WFMath::RotMatrix< dim >::setVals (const CoordType vals[dim][dim], double precision = WFMATH_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.

## Author

Generated automatically by Doxygen for WFMath from the source code.