Files Class List
Matrix34< T > Class Template Reference

Detailed Description

template<typename T>
class cy::Matrix34< T >

3x4 matrix class.

Its data stores 12-value array of column-major matrix elements. I chose column-major format to be compatible with OpenGL You can use Matrix34 with Vec3<T> and Vec4<T> to transform 3D and 4D points.

#include <cyMatrix.h>

Public Member Functions

Constructors
 Matrix34 ()
 Default constructor.
 
template<typename TT >
 Matrix34 (Matrix34< TT > const &matrix)
 Copy constructor for different types.
 
 Matrix34 (T const *values)
 Initialize the matrix using an array of 9 values.
 
 Matrix34 (T v)
 Initialize the matrix as identity scaled by v.
 
 Matrix34 (Vec3< T > const &x, Vec3< T > const &y, Vec3< T > const &z, Vec3< T > const &pos)
 Initialize the matrix using x,y,z vectors and coordinate center.
 
 Matrix34 (Matrix3< T > const &m)
 Default constructor.
 
 Matrix34 (Matrix3< T > const &m, Vec3< T > const &pos)
 Default constructor.
 
 Matrix34 (Matrix2< T > const &m)
 Default constructor.
 
 Matrix34 (Matrix4< T > const &m)
 Default constructor.
 
 Matrix34 (T c00, T c01, T c02, T c03, T c10, T c11, T c12, T c13, T c20, T c21, T c22, T c23)
 Constructor using row-major order for initialization.
 
Set & Get Methods
void Zero ()
 Set all the values as zero.
 
bool IsZero () const
 Returns true if the matrix is exactly zero.
 
bool IsFinite () const
 Returns true if all components are finite real numbers.
 
void Get (T *values)
 Copies the matrix cell to the given values array of size 12.
 
void Set (T const *values)
 Set Matrix using an array of 12 values.
 
void Set (Vec3< T > const &x, Vec3< T > const &y, Vec3< T > const &z, Vec3< T > const &pos)
 Set matrix using x,y,z vectors and coordinate center.
 
void SetIdentity ()
 Converts the matrix to an identity matrix.
 
Affine transformations
void SetScale (T uniformScale)
 Sets a uniform scale matrix.
 
void SetScale (T scaleX, T scaleY, T scaleZ)
 Sets a scale matrix.
 
void SetScale (Vec3< T > const &scale)
 Sets a scale matrix.
 
void SetRotationX (T angle)
 Set as rotation matrix around x axis.
 
void SetRotationX (T sinAngle, T cosAngle)
 Set as rotation matrix around x axis by cos and sin of angle.
 
void SetRotationY (T angle)
 Set as rotation matrix around y axis.
 
void SetRotationY (T sinAngle, T cosAngle)
 Set as rotation matrix around y axis by cos and sin of angle.
 
void SetRotationZ (T angle)
 Set as rotation matrix around z axis.
 
void SetRotationZ (T sinAngle, T cosAngle)
 Set as rotation matrix around z axis by cos and sin of angle.
 
void SetRotationXYZ (T angleX, T angleY, T angleZ)
 Set as rotation matrix around x, y, and then z axes ( Rz * Ry * Rx )
 
void SetRotationZYX (T angleX, T angleY, T angleZ)
 Set as rotation matrix around z, y, and then x axes ( Rx * Ry * Rz )
 
void SetRotation (Vec3< T > const &axis, T angle)
 Set a rotation matrix about the given axis by angle.
 
void SetRotation (Vec3< T > const &axis, T sinAngle, T cosAngle)
 Set a rotation matrix about the given axis by cos and sin of angle.
 
void SetRotation (Vec3< T > const &from, Vec3< T > const &to)
 Set a rotation matrix that sets [from] unit vector to [to] unit vector.
 
void SetTranslation (Vec3< T > const &move)
 Sets a translation matrix with no rotation or scale.
 
void AddTranslation (Vec3< T > const &move)
 Adds a translation to the matrix.
 
void SetTranslationComponent (Vec3< T > const &move)
 Sets the translation component of the matrix.
 
void SetNoTranslation ()
 Sets the translation component of the matrix to zero.
 
void SetView (Vec3< T > const &pos, Vec3< T > const &target, Vec3< T > const &up)
 Set view matrix using position, target and approximate up vector.
 
void SetCartesianFrameXY (Vec3< T > const &x, Vec3< T > const &y_approx, Vec3< T > const &trans=Vec3< T >(T(0), T(0), T(0)))
 Sets a Cartesian coordinate frame using the given x direction, an approximate y direction, and a translation. x must be a unit vector.
 
void SetCartesianFrameXZ (Vec3< T > const &x, Vec3< T > const &z_approx, Vec3< T > const &trans=Vec3< T >(T(0), T(0), T(0)))
 Sets a Cartesian coordinate frame using the given x direction, an approximate z direction, and a translation. x must be a unit vector.
 
void SetCartesianFrameYX (Vec3< T > const &y, Vec3< T > const &x_approx, Vec3< T > const &trans=Vec3< T >(T(0), T(0), T(0)))
 Sets a Cartesian coordinate frame using the given y direction, an approximate x direction, and a translation. y must be a unit vector.
 
void SetCartesianFrameYZ (Vec3< T > const &y, Vec3< T > const &z_approx, Vec3< T > const &trans=Vec3< T >(T(0), T(0), T(0)))
 Sets a Cartesian coordinate frame using the given y direction, an approximate z direction, and a translation. y must be a unit vector.
 
void SetCartesianFrameZX (Vec3< T > const &z, Vec3< T > const &x_approx, Vec3< T > const &trans=Vec3< T >(T(0), T(0), T(0)))
 Sets a Cartesian coordinate frame using the given z direction, an approximate x direction, and a translation. z must be a unit vector.
 
void SetCartesianFrameZY (Vec3< T > const &z, Vec3< T > const &y_approx, Vec3< T > const &trans=Vec3< T >(T(0), T(0), T(0)))
 Sets a Cartesian coordinate frame using the given z direction, an approximate y direction, and a translation. z must be a unit vector.
 
Set Row, Column, or Diagonal
void SetRow (int ri, T x, T y, T z, T w)
 Sets a row of the matrix.
 
void SetRow (int ri, Vec4< T > const &v)
 Sets a row of the matrix.
 
void SetColumn (int ci, T x, T y, T z)
 Sets a column of the matrix.
 
void SetColumn (int ci, Vec3< T > const &v)
 Sets a column of the matrix.
 
void SetDiagonal (T xx, T yy, T zz)
 Sets the diagonal values of the matrix.
 
void SetDiagonal (Vec3< T > const &p)
 Sets the diagonal values of the matrix.
 
void SetDiagonal (T const *values)
 Sets the diagonal values of the matrix.
 
Get Row, Column, or Diagonal
Vec3< T > * Columns ()
 Returns a row of the matrix.
 
Vec3< T > const * Columns () const
 Returns a row of the matrix.
 
Vec3< T > & Column (int ci)
 Returns a row of the matrix.
 
Vec3< T > const & Column (int ci) const
 Returns a row of the matrix.
 
Vec4< T > GetRow (int ri) const
 Returns a row of the matrix.
 
Vec3< T > GetDiagonal () const
 Returns the diagonal of the matrix.
 
Get Sub-matrix cell
Matrix3< T > GetSubMatrix3 () const
 Returns the 3x3 portion of the matrix.
 
Matrix2< T > GetSubMatrix2 () const
 Returns the 2x2 portion of the matrix.
 
Vec3< T > GetTranslation () const
 Returns the translation component of the matrix.
 
Matrix3< T > GetRotation () const
 Returns the rotation portion of the transformation.
 
Matrix3< T > GetScale () const
 Returns the scale portion of the transformation.
 
GetAvrgScale () const
 Returns the average scale factor of the 3 by 3 sub-matrix.
 
void GetComponents (Matrix3< T > &scale, Matrix3< T > &rotation, Vec3< T > &translation) const
 Returns separate transformation components.
 
Comparison Operators
bool operator== (Matrix34 const &right) const
 compare equal
 
bool operator!= (Matrix34 const &right) const
 compare not equal
 
Access Operators
T & operator() (int ri, int ci)
 subscript operator
 
T const & operator() (int ri, int ci) const
 constant subscript operator
 
T & operator[] (int i)
 subscript operator
 
T const & operator[] (int i) const
 constant subscript operator
 
Unary and Binary Operators
Matrix34 operator- () const
 negative matrix
 
Matrix34 operator* (T const value) const
 multiply matrix by a value
 
Matrix34 operator/ (T const value) const
 divide matrix by a value
 
Matrix34 operator+ (Matrix34 const &right) const
 add two Matrices
 
Matrix34 operator- (Matrix34 const &right) const
 subtract one Matrix4 from another
 
Matrix34 operator* (Matrix34 const &right) const
 < multiply a matrix with another
 
Matrix34 operator* (Matrix3< T > const &right) const
 < multiply a matrix with another
 
Vec3< T > operator* (Vec3< T > const &p) const
 negative matrix
 
Vec4< T > operator* (Vec4< T > const &p) const
 negative matrix
 
Matrix34 operator+ (T value) const
 add a value times identity matrix
 
Matrix34 operator- (T value) const
 subtract a value times identity matrix
 
3D Vector Transform Methods
Vec3< T > VectorTransform (Vec3< T > const &p) const
 Transforms the vector by multiplying it with the matrix, ignoring the translation component.
 
Assignment Operators
Matrix34 const & operator+= (Matrix34 const &right)
 add two Matrices modify this
 
Matrix34 const & operator-= (Matrix34 const &right)
 subtract one Matrix4 from another matrix and modify this matrix
 
Matrix34 const & operator*= (Matrix34 const &right)
 multiply a matrix with another matrix and modify this matrix
 
Matrix34 const & operator*= (Matrix3< T > const &right)
 multiply a matrix with another matrix and modify this matrix
 
Matrix34 const & operator*= (T const value)
 multiply a matrix with a value modify this matrix
 
Matrix34 const & operator/= (T const value)
 divide the matrix by a value modify the this matrix
 
Matrix34 const & operator+= (T const value)
 add a value times identity matrix
 
Matrix34 const & operator-= (T const value)
 subtract a value times identity matrix
 
Other Methods
void Transpose ()
 Transpose this matrix.
 
Matrix4< T > GetTranspose () const
 Returns the transpose of this matrix.
 
Vec4< T > TransposeMult (Vec3< T > const &p) const
 Multiply the give vector with the transpose of the matrix.
 
Vec4< T > TransposeMult (Vec4< T > const &p) const
 Multiply the give vector with the transpose of the matrix.
 
GetDeterminant () const
 < Get the determinant of this matrix
 
void Invert ()
 Invert this matrix.
 
Matrix34 GetInverse () const
 < Get the inverse of this matrix
 
void Normalize ()
 Removes the scale component of the matrix by normalizing the first three columns. The resulting matrix can contain shear, if it originally contained non-uniform scale and rotation.
 
void OrthogonalizeX ()
 Orthogonalizes the matrix and removes the scale component, preserving the x direction.
 
void OrthogonalizeY ()
 Orthogonalizes the matrix and removes the scale component, preserving the y direction.
 
void OrthogonalizeZ ()
 Orthogonalizes the matrix and removes the scale component, preserving the z direction.
 
bool IsIdentity (T tollerance=T(0.0001)) const
 Returns if the matrix is identity within the given error tollerance.
 
bool IsSymmetric (T tollerance=T(0.0001)) const
 Returns if the matrix is symmetric within the given error tollerance.
 
bool IsDiagonal (T tollerance=T(0.0001)) const
 Returns if the matrix is diagonal.
 

Static Public Member Functions

Static Methods
static Matrix34 Identity ()
 Returns an identity matrix.
 
static Matrix34 View (Vec3< T > const &pos, Vec3< T > const &target, Vec3< T > const &up)
 Returns a view matrix using position, target and approximate up vector.
 
static Matrix34 RotationX (T angle)
 Returns a rotation matrix around x axis by angle in radians.
 
static Matrix34 RotationY (T angle)
 Returns a rotation matrix around y axis by angle in radians.
 
static Matrix34 RotationZ (T angle)
 Returns a rotation matrix around z axis by angle in radians.
 
static Matrix34 RotationXYZ (T angleX, T angleY, T angleZ)
 Returns a rotation matrix around x, y, and then z axes by angle in radians (Rz * Ry * Rx)
 
static Matrix34 RotationZYX (T angleX, T angleY, T angleZ)
 Returns a rotation matrix around z, y, and then x axes by angle in radians (Rx * Ry * Rz)
 
static Matrix34 Rotation (Vec3< T > const &axis, T angle)
 Returns a rotation matrix about the given axis by angle in radians.
 
static Matrix34 Rotation (Vec3< T > const &axis, T cosAngle, T sinAngle)
 Returns a rotation matrix about the given axis by cos and sin of the rotation angle.
 
static Matrix34 Rotation (Vec3< T > const &from, Vec3< T > const &to)
 Returns a rotation matrix that sets [from] unit vector to [to] unit vector.
 
static Matrix34 Scale (T uniformScale)
 Returns a uniform scale matrix.
 
static Matrix34 Scale (T scaleX, T scaleY, T scaleZ)
 Returns a scale matrix.
 
static Matrix34 Scale (Vec3< T > const &scale)
 Returns a scale matrix.
 
static Matrix34 Translation (Vec3< T > const &move)
 Returns a translation matrix with no rotation or scale.
 

Public Attributes

cell [12]
 Elements of the matrix are column-major:
| 0 3 6 9 |
| 1 4 7 10 |
| 2 5 8 11 |
.
 

Friends

Matrix34 operator* (T value, Matrix34 const &right)
 multiply matrix by a value
 
Matrix34 operator+ (T value, Matrix34 const &right)
 add a value times identity matrix to a matrix
 
Matrix34 operator- (T value, Matrix34 const &right)
 subtract a matrix from a value times identity matrix
 
Matrix34 Inverse (Matrix34 const &m)
 return the inverse of the matrix