wfmath
1.0.3
A math library for the Worldforge system.
|
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 | |
RotMatrix & | operator= (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 |
RotMatrix & | identity () |
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... | |
RotMatrix & | rotation (int i, int j, CoordType theta) |
set the matrix to a rotation by the angle theta in the (i, j) plane More... | |
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 More... | |
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" More... | |
RotMatrix & | mirror (int i) |
set the matrix to a mirror perpendicular to the i'th axis More... | |
RotMatrix & | mirror (const Vector< dim > &v) |
set the matrix to a mirror perpendicular to the Vector v More... | |
RotMatrix & | mirror () |
set the matrix to mirror all axes More... | |
RotMatrix & | rotate (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... | |
RotMatrix & | rotation (CoordType theta) |
2D only: Construct a RotMatrix from an angle theta More... | |
RotMatrix & | rotationX (CoordType theta) |
3D only: set a RotMatrix to a rotation about the x axis by angle theta More... | |
RotMatrix & | rotationY (CoordType theta) |
3D only: set a RotMatrix to a rotation about the y axis by angle theta More... | |
RotMatrix & | rotationZ (CoordType theta) |
3D only: set a RotMatrix to a rotation about the z axis by angle theta More... | |
RotMatrix & | rotation (const Vector< dim > &axis, CoordType theta) |
3D only: set a RotMatrix to a rotation about the axis given by the Vector More... | |
RotMatrix & | rotation (const Vector< dim > &axis) |
3D only: set a RotMatrix to a rotation about the axis given by the Vector More... | |
RotMatrix & | fromQuaternion (const Quaternion &q, bool not_flip=true) |
3D only: set a RotMatrix from a Quaternion More... | |
RotMatrix & | rotate (const Quaternion &) |
rotate the matrix using the quaternion More... | |
RotMatrix & | mirrorX () |
set a RotMatrix to a mirror perpendicular to the x axis More... | |
RotMatrix & | mirrorY () |
set a RotMatrix to a mirror perpendicular to the y axis More... | |
RotMatrix & | mirrorZ () |
set a RotMatrix to a mirror perpendicular to the z axis More... | |
template<> | |
RotMatrix< 3 > & | fromQuaternion (const Quaternion &q, const bool not_flip) |
template<> | |
RotMatrix< 3 > & | rotate (const Quaternion &q) |
template<> | |
RotMatrix< 3 > & | rotation (const Vector< 3 > &axis, CoordType theta) |
template<> | |
RotMatrix< 3 > & | rotation (const Vector< 3 > &axis) |
template<> | |
RotMatrix (const Quaternion &q, const bool not_flip) | |
template<> | |
RotMatrix< 3 > & | mirrorZ () |
template<> | |
RotMatrix< 3 > & | rotation (const Vector< 3 > &axis, CoordType theta) |
template<> | |
RotMatrix< 3 > & | rotation (const Vector< 3 > &axis) |
template<> | |
RotMatrix< 3 > & | fromQuaternion (const Quaternion &q, const bool not_flip) |
template<> | |
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... | |
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.
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
|
inline |
current round-off age
Definition at line 201 of file rotmatrix.h.
Referenced by WFMath::Quaternion::fromRotMatrix().
|
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().
Referenced by WFMath::RotMatrix< dim >::elem().
|
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.
References WFMath::RotMatrix< dim >::inverse().
|
inline |
get the (i, j) element of the matrix
Definition at line 112 of file rotmatrix.h.
References WFMath::RotMatrix< dim >::column(), WFMath::RotMatrix< dim >::row(), WFMath::RotMatrix< dim >::setVals(), and WFMath::RotMatrix< dim >::trace().
Referenced by WFMath::Quaternion::fromRotMatrix().
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
Referenced by WFMath::RotMatrix< dim >::rotation(), and WFMath::RotMatrix< dim >::rotationZ().
|
inline |
set the matrix to the identity matrix
Definition at line 318 of file rotmatrix_funcs.h.
Referenced by WFMath::RotMatrix< dim >::mirror().
|
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.
Referenced by WFMath::RotMatrix< dim >::determinant().
|
inline |
set the matrix to a mirror perpendicular to the i'th axis
Definition at line 269 of file rotmatrix.h.
References WFMath::RotMatrix< dim >::identity().
|
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().
|
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(), WFMath::RotMatrix< dim >::mirrorY(), and WFMath::RotMatrix< dim >::parity().
|
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().
|
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(), WFMath::RotMatrix< dim >::mirrorZ(), and WFMath::RotMatrix< dim >::normalize().
RotMatrix& WFMath::RotMatrix< dim >::mirrorZ | ( | ) |
set a RotMatrix to a mirror perpendicular to the z axis
Referenced by WFMath::RotMatrix< dim >::mirrorY().
|
inline |
normalize to remove accumulated round-off error
Definition at line 538 of file rotmatrix_funcs.h.
Referenced by WFMath::RotMatrix< dim >::mirrorY(), and WFMath::RotMatrix< dim >::rotate().
|
inline |
Get the parity of the matrix.
Returns true for odd parity, false for even.
Definition at line 154 of file rotmatrix.h.
References WFMath::RotMatrix< dim >::mirror(), and WFMath::RotMatrix< dim >::rotation().
Referenced by WFMath::Quaternion::fromRotMatrix().
|
inline |
rotate the matrix using another matrix
Definition at line 196 of file rotmatrix.h.
References WFMath::RotMatrix< dim >::normalize(), and WFMath::RotMatrix< dim >::Prod.
Referenced by WFMath::RotMatrix< dim >::rotation(), and WFMath::RotMatrix< dim >::rotationZ().
RotMatrix& WFMath::RotMatrix< dim >::rotate | ( | const Quaternion & | ) |
rotate the matrix using the quaternion
RotMatrix< dim > & WFMath::RotMatrix< dim >::rotation | ( | int | i, |
int | j, | ||
CoordType | theta | ||
) |
set the matrix to a rotation by the angle theta in the (i, j) plane
Definition at line 343 of file rotmatrix_funcs.h.
Referenced by WFMath::RotMatrix< dim >::parity(), WFMath::Vector< 3 >::rotate(), WFMath::RotMatrix< dim >::rotation(), WFMath::RotMatrix< dim >::rotationX(), WFMath::RotMatrix< dim >::rotationY(), and WFMath::RotMatrix< dim >::rotationZ().
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().
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::RotMatrix< dim >::fromQuaternion(), WFMath::RotMatrix< dim >::rotate(), WFMath::RotMatrix< dim >::rotation(), and WFMath::Vector< dim >::sqrMag().
|
inline |
2D only: Construct a RotMatrix from an angle theta
Definition at line 215 of file rotmatrix.h.
References WFMath::RotMatrix< dim >::rotation().
RotMatrix& WFMath::RotMatrix< dim >::rotation | ( | const Vector< dim > & | axis, |
CoordType | theta | ||
) |
RotMatrix& WFMath::RotMatrix< dim >::rotation | ( | const Vector< dim > & | axis | ) |
|
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().
|
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().
|
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 >::fromQuaternion(), WFMath::RotMatrix< dim >::rotate(), and WFMath::RotMatrix< dim >::rotation().
|
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().
Referenced by WFMath::RotMatrix< dim >::elem().
|
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.
Referenced by WFMath::RotMatrix< dim >::elem().
|
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.
|
inline |
Get the trace of the matrix.
Definition at line 332 of file rotmatrix_funcs.h.
Referenced by WFMath::RotMatrix< dim >::elem(), and WFMath::Quaternion::fromRotMatrix().
|
friend |
returns m1^-1 * m2
Definition at line 116 of file rotmatrix_funcs.h.
|
friend |
returns m^-1 * v
Definition at line 177 of file rotmatrix_funcs.h.
|
friend |
returns m1^-1 * m2^-1
Definition at line 138 of file rotmatrix_funcs.h.
|
friend |
returns m1 * m2
Definition at line 72 of file rotmatrix_funcs.h.
Referenced by WFMath::RotMatrix< dim >::rotate().
|
friend |
returns m * v
Definition at line 160 of file rotmatrix_funcs.h.
|
friend |
returns m1 * m2^-1
Definition at line 94 of file rotmatrix_funcs.h.