cryph utilities [subset]  2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
cryph::Matrix3x3 Class Reference

#include <Matrix3x3.h>

Public Member Functions

 Matrix3x3 ()
 
 Matrix3x3 (const Matrix3x3 &M)
 
 Matrix3x3 (double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33)
 
virtual ~Matrix3x3 ()
 
Matrix3x3 operator= (const Matrix3x3 &rhs)
 
Matrix3x3 operator*= (const Matrix3x3 &rhs)
 
Matrix3x3 operator*= (double f)
 
Matrix3x3 operator+= (const Matrix3x3 &rhs)
 
AffPoint operator* (const AffPoint &p) const
 
AffVector operator* (const AffVector &v) const
 
Matrix3x3 operator* (const Matrix3x3 &m2) const
 
Matrix3x3 operator+ (const Matrix3x3 &m2) const
 
Matrix3x3 operator- (const Matrix3x3 &m2) const
 
double determinant () const
 
double elementAt (int i, int j) const
 
float * extractColMajor (float m[9]) const
 
double * extractColMajor (double m[9]) const
 
float * extractRowMajor (float m[9]) const
 
double * extractRowMajor (double m[9]) const
 
int extractAxisAngle (AffVector &w, double &theta) const
 
void extractRows (AffVector &row1, AffVector &row2, AffVector &row3) const
 
bool inverse (Matrix3x3 &mInv) const
 
bool isOrthogonal () const
 
bool isRightHanded () const
 
double largestDiagonalElement (int &pos) const
 
void multiply (const double a[], double b[]) const
 
void setElementAt (int i, int j, double newValue)
 
double trace () const
 
void transpose ()
 

Static Public Member Functions

static Matrix3x3 xRotationDegrees (double angle)
 
static Matrix3x3 xRotationRadians (double angle)
 
static Matrix3x3 yRotationDegrees (double angle)
 
static Matrix3x3 yRotationRadians (double angle)
 
static Matrix3x3 zRotationDegrees (double angle)
 
static Matrix3x3 zRotationRadians (double angle)
 
static Matrix3x3 generalRotationRadians (const AffVector &rotationAxis, double angle)
 
static Matrix3x3 alignVectors (const AffVector &uFrom, const AffVector &uTo)
 
static Matrix3x3 alignVectors (const AffVector &uFrom, const AffVector &vFrom, const AffVector &uTo, const AffVector &vTo)
 
static Matrix3x3 scale (double sx, double sy, double sz)
 
static Matrix3x3 shear (const AffVector &n, const AffVector &u, double f)
 
static Matrix3x3 crossProductMatrix (const AffVector &u)
 
static Matrix3x3 mirrorMatrix (const AffVector &mirrorPlaneNormal)
 
static Matrix3x3 tensorProductMatrix (const AffVector &u, const AffVector &v)
 

Static Public Attributes

static const Matrix3x3 IdentityMatrix
 
static const Matrix3x3 ZeroMatrix
 
static const int ImMDeterminantNotZero = -20
 
static const int CannotDetermineUnitAxisVector = -19
 
static const int CosTermsNotEqual = -18
 
static const int SinTermsNotEqual = -17
 
static const int NotOrthogonal = -5
 
static const int NotRightHanded = -4
 
static const int Extracted_wTheta = 0
 

Protected Attributes

double mElem [3][3]
 

Friends

class Matrix4x4
 
Matrix3x3 operator* (double f, const Matrix3x3 &m)
 
std::ostream & operator<< (std::ostream &os, const Matrix3x3 &m)
 
std::istream & operator>> (std::istream &is, Matrix3x3 &m)
 

Detailed Description

This class is designed for the specification and manipulation of 3x3 matrices as a part of Affine transformations specified on 3D vectors As such, it provides facilities to create 3x3 matrices that rotate and mirror vectors, form tensor products of vectors, and provide other support required by Matrix4x4 in its role of representing transformations of 3D geometry. This interface is NOT intended to provide facilities for representing 2D transformations in homogeneous form.

Constructor & Destructor Documentation

cryph::Matrix3x3::Matrix3x3 ( )

Default constructor creates a 3x3 identity matrix

cryph::Matrix3x3::Matrix3x3 ( const Matrix3x3 M)

The copy constructor

Parameters
Mthe matrix whose elements are copied
cryph::Matrix3x3::Matrix3x3 ( double  m11,
double  m12,
double  m13,
double  m21,
double  m22,
double  m23,
double  m31,
double  m32,
double  m33 
)

Construct a 3x3 matrix directly from 9 values given in row-major order

Parameters
mrcThe element for row r, column c
cryph::Matrix3x3::~Matrix3x3 ( )
virtual

The destructor

Member Function Documentation

Matrix3x3 cryph::Matrix3x3::alignVectors ( const AffVector uFrom,
const AffVector uTo 
)
static

Factory method to create a 3x3 matrix that can be used to rotate one 3D vector onto another 3D vector.

Parameters
uFromthe 3D vector to be aligned with uTo
uTothe 3D vector onto which we want the created matrix to rotate uFrom
Returns
the 3x3 matrix encoding the rotation
See also
extractAxisAngle
Matrix3x3 cryph::Matrix3x3::alignVectors ( const AffVector uFrom,
const AffVector vFrom,
const AffVector uTo,
const AffVector vTo 
)
static

Factory method to create a 3x3 matrix that can be used to rotate a pair of 3D vectors onto another pair of 3D vectors. Since a rigid rotation to perform this cannot always be created, the matrix created will align uFrom with uTo, and it will encode one additional rotation that will rotate vFrom into the plane of (uTo, vTo) such that the dot product of vTo with the transformed vFrom is non-negative.

Parameters
uFromthe 3D vector to be aligned with uTo
vFromthe 3D vector to be aligned with vTo
uTothe 3D vector onto which we want the created matrix to rotate uFrom
vTothe 3D vector onto which we want the created matrix to rotate vFrom, subject to the constraint explained above.
Returns
the 3x3 matrix encoding the rotation
Matrix3x3 cryph::Matrix3x3::crossProductMatrix ( const AffVector u)
static

Factory method to create a 3x3 matrix that can be used to encode a cross product with the given vector. That is, if U is the 3x3 matrix returned by this method, then for an arbitrary vector v: U*v = u x v.

Parameters
uthe desired vector
Returns
the 3x3 matrix encoding the cross product
double cryph::Matrix3x3::determinant ( ) const

Return the determinantof "this" 3x3 matrix

Returns
the determinant
double cryph::Matrix3x3::elementAt ( int  i,
int  j 
) const

Return "this" matrix element at row i and column j.

Parameters
ithe desired row
jthe desired column
Returns
the matrix element at row i and column j
int cryph::Matrix3x3::extractAxisAngle ( AffVector w,
double &  theta 
) const

If "this" matrix is orthogonal and right-handed, then this method will determine the rotation axis and angle which, if passed to generalRotationRadians, would exactly reproduce "this" matrix.

Parameters
won exit, this vector will have the rotation axis
thetaon exit, this will hold the rotation angle in radians
Returns
an integer code indicating whether the extraction succeeded:
  • Matrix3x3::NotOrthogonal - if "this" matrix is not orthogonal
  • Matrix3x3::NotRightHanded - if "this" matrix is not right-handed
  • Matrix3x3::Extracted_wTheta - if w and theta were successfully computed
See also
isOrthogonal
isRightHanded
generalRotationRadians
float * cryph::Matrix3x3::extractColMajor ( float  m[9]) const

Extract the components of the matrix into the given single-precision array in column-major order.

Parameters
m[OUTPUT ONLY] an array of float of length 9
Returns
the base address of "m" so that the method call can be used as a parameter to an OpenGL function expecting an array of float.
double * cryph::Matrix3x3::extractColMajor ( double  m[9]) const

Extract the components of the matrix into the given double-precision array in column-major order.

Parameters
m[OUTPUT ONLY] an array of double of length 9
Returns
the base address of "m" so that the method call can be used as a parameter to an OpenGL function expecting an array of double.
float * cryph::Matrix3x3::extractRowMajor ( float  m[9]) const

Extract the components of the matrix into the given single-precision array in row-major order.

Parameters
m[OUTPUT ONLY] an array of float of length 9
Returns
the base address of "m" so that the method call can be used as a parameter to an OpenGL function expecting an array of float.
double * cryph::Matrix3x3::extractRowMajor ( double  m[9]) const

Extract the components of the matrix into the given double-precision array in row-major order.

Parameters
m[OUTPUT ONLY] an array of double of length 9
Returns
the base address of "m" so that the method call can be used as a parameter to an OpenGL function expecting an array of double.
void cryph::Matrix3x3::extractRows ( AffVector row1,
AffVector row2,
AffVector row3 
) const

Extract the rows of "this" matrix, writing them into the given output parameters

Parameters
row1on exit, this will hold the first row of "this" matrix
row2on exit, this will hold the second row of "this" matrix
row3on exit, this will hold the third row of "this" matrix
Matrix3x3 cryph::Matrix3x3::generalRotationRadians ( const AffVector rotationAxis,
double  angle 
)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the given axis vector.

Parameters
rotationAxisa 3D vector about which the rotation is to be performed
anglethe desired rotation angle in radians
Returns
the 3x3 matrix encoding the rotation
bool cryph::Matrix3x3::inverse ( Matrix3x3 mInv) const

Compute and return the inverse of "this" matrix.

Parameters
mInvthe matrix into which the inverse will be written
Returns
true if the inverse was successfully computed
bool cryph::Matrix3x3::isOrthogonal ( ) const

Report whether "this" matrix is orthogonal. A matrix is orthogonal if its inverse is the same as its transpose.

Returns
true if the matrix is orthogonal
See also
extractAxisAngle
bool cryph::Matrix3x3::isRightHanded ( ) const

Report whether "this" matrix is right-handed. A matrix is right-handed if the dot product of (row1 x row2) with row3 is positive.

Returns
true if the matrix is right-handed
See also
extractAxisAngle
double cryph::Matrix3x3::largestDiagonalElement ( int &  pos) const

Determine the diagonal element with the largest value. Return the position in "pos" and the value itself as the method return.

Parameters
poson exit, the row that contains the largest diagonal element
Returns
the value of the element with the largest value.
Matrix3x3 cryph::Matrix3x3::mirrorMatrix ( const AffVector mirrorPlaneNormal)
static

Factory method to create a 3x3 matrix that can be used to mirror a vector about the plane whose normal is specified by the given vector.

Parameters
mirrorPlaneNormalthe normal vector to the desired mirror plane
Returns
the 3x3 matrix encoding the mirror
void cryph::Matrix3x3::multiply ( const double  a[],
double  b[] 
) const

Multiply "a" on the left by "this" matrix, placing the result in "b": b = "this" * a.

Parameters
aan array of length 3 to be multiplied
ban array of length 3 that recieves the product "this" * a.
AffPoint cryph::Matrix3x3::operator* ( const AffPoint p) const

Multiply the point p on the left by "this" matrix.

Parameters
pthe point to be multiplied
Returns
the transformed point
AffVector cryph::Matrix3x3::operator* ( const AffVector v) const

Multiply the vector v on the left by "this" matrix.

Parameters
vthe vector to be multiplied
Returns
the transformed vector
Matrix3x3 cryph::Matrix3x3::operator* ( const Matrix3x3 m2) const

Multiply the matrix m2 on the left by "this" matrix.

Parameters
m2the matrix to be multiplied
Returns
the 3x3 matrix that is the product: "this" * m2
Matrix3x3 cryph::Matrix3x3::operator*= ( const Matrix3x3 rhs)

Assign to "this" matrix the product of "this" matrix and rhs

Parameters
rhsthe matrix to be concatenated onto the right-hand side of "this" matrix
Returns
the updated "this" matrix
Matrix3x3 cryph::Matrix3x3::operator*= ( double  f)

Assign to "this" matrix the product of "this" matrix with the given scalar. That is, each element of "this" matrix is multiplied by f.

Parameters
fthe scale factor
Returns
the updated "this" matrix
Matrix3x3 cryph::Matrix3x3::operator+ ( const Matrix3x3 m2) const

Add the matrix m2 to "this" matrix.

Parameters
m2the matrix to be added
Returns
the 3x3 matrix that is the sum: "this" + m2
Matrix3x3 cryph::Matrix3x3::operator+= ( const Matrix3x3 rhs)

Assign to "this" matrix the sum of "this" matrix and rhs

Parameters
rhsthe matrix to be added to "this" matrix
Returns
the updated "this" matrix
Matrix3x3 cryph::Matrix3x3::operator- ( const Matrix3x3 m2) const

Subtract the matrix m2 from "this" matrix.

Parameters
m2the matrix to be subtracted
Returns
the 3x3 matrix that is the difference: "this" - m2
Matrix3x3 cryph::Matrix3x3::operator= ( const Matrix3x3 rhs)

The assignment operator

Parameters
rhsthe 3x3 matrix to be assigned to "this" matrix
Returns
the assigned matrix
Matrix3x3 cryph::Matrix3x3::scale ( double  sx,
double  sy,
double  sz 
)
static

Factory method to create a 3x3 matrix that can be used to scale a vector by the given scale factors along the x-, y-, and z-axes.

Parameters
sxthe desired scale factor in the x direction
sythe desired scale factor in the y direction
szthe desired scale factor in the z direction
Returns
the 3x3 matrix encoding the scale
void cryph::Matrix3x3::setElementAt ( int  i,
int  j,
double  newValue 
)

Set this[i][j] = newValue.

Parameters
ithe row containing the element to be set
jthe column containing the element to be set
newValuethe value to be copied into row i and column j
Matrix3x3 cryph::Matrix3x3::shear ( const AffVector n,
const AffVector u,
double  f 
)
static

Factory method to create a 3x3 matrix that can be used to shear a vector. The matrix created will shear an arbitrary vector, v, by adding to v: f*v.dot(nHat)uHat where nHat is a unit vector perpendicular to the shear plane; uHat is a unit vector in the direction of the component of the given u vector perpendicular to the given normal vector, n; and f is a constant.

Parameters
nthe vector perpendicular to the shear plane
ua vector in the shear plane that specifies the shear direction (only the component of u perpendicular to n will be used when creating uHat)
fa constant adjusting the amount of shear per length of v in the direction of nHat.
Returns
the 3x3 matrix encoding the shear
Matrix3x3 cryph::Matrix3x3::tensorProductMatrix ( const AffVector u,
const AffVector v 
)
static

Factory method to create a 3x3 matrix that is the tensor product of the two given vectors. That is, matrix[i][j] will be u[i]*v[j]

Parameters
uthe first vector
vthe second vector
Returns
the matrix that holds the tensor product of u and v.
double cryph::Matrix3x3::trace ( ) const

Compute and return the trace of "this" matrix. The trace is the sum of the diagonal elements.

Returns
the trace = this[0][0]+this[1][1]+this[2][2]
void cryph::Matrix3x3::transpose ( )

Transpose "this" matrix in place. On exit, "this" matrix will have been transposed.

Matrix3x3 cryph::Matrix3x3::xRotationDegrees ( double  angle)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the x-axis.

Parameters
anglethe desired rotation angle in degrees
Returns
the 3x3 matrix encoding the rotation
Matrix3x3 cryph::Matrix3x3::xRotationRadians ( double  angle)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the x-axis.

Parameters
anglethe desired rotation angle in radians
Returns
the 3x3 matrix encoding the rotation
Matrix3x3 cryph::Matrix3x3::yRotationDegrees ( double  angle)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the y-axis.

Parameters
anglethe desired rotation angle in degrees
Returns
the 3x3 matrix encoding the rotation
Matrix3x3 cryph::Matrix3x3::yRotationRadians ( double  angle)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the y-axis.

Parameters
anglethe desired rotation angle in radians
Returns
the 3x3 matrix encoding the rotation
Matrix3x3 cryph::Matrix3x3::zRotationDegrees ( double  angle)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the z-axis.

Parameters
anglethe desired rotation angle in degrees
Returns
the 3x3 matrix encoding the rotation
Matrix3x3 cryph::Matrix3x3::zRotationRadians ( double  angle)
static

Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the z-axis.

Parameters
anglethe desired rotation angle in radians
Returns
the 3x3 matrix encoding the rotation

Friends And Related Function Documentation

Matrix3x3 operator* ( double  f,
const Matrix3x3 m 
)
friend

Return a matrix that is the product f*m where f is a scale factor used to multiply each element of the matrix, m.

Parameters
fthe scale factor
mthe matrix to be scaled (m is unchanged)
Returns
the product f*m
std::ostream& operator<< ( std::ostream &  os,
const Matrix3x3 m 
)
friend

Output the matrix m to the given output stream. Elements are output in row-major order, all on one line, with a single space between each element.

Parameters
osthe stream to which the matrix is written
mthe matrix to be written
Returns
the updated output stream
std::istream& operator>> ( std::istream &  is,
Matrix3x3 m 
)
friend

Read 9 elements into the matrix m from the given input stream. Elements are read in row-major order and assumed to be whitespace-delimited.

Parameters
isthe stream from which the matrix is read
mthe matrix into which the values read are placed
Returns
the updated input stream

Member Data Documentation

const Matrix3x3 cryph::Matrix3x3::IdentityMatrix
static
Initial value:
=
1.0 , 0.0 , 0.0 ,
0.0 , 1.0 , 0.0 ,
0.0 , 0.0 , 1.0
)

the 3x3 identity matrix

const Matrix3x3 cryph::Matrix3x3::ZeroMatrix
static
Initial value:
=
0.0 , 0.0 , 0.0 ,
0.0 , 0.0 , 0.0 ,
0.0 , 0.0 , 0.0
)

the 3x3 zero matrix


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