cryph utilities [subset]
2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
|
#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) |
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.
cryph::Matrix3x3::Matrix3x3 | ( | ) |
Default constructor creates a 3x3 identity matrix
cryph::Matrix3x3::Matrix3x3 | ( | const Matrix3x3 & | M | ) |
The copy constructor
M | the 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
mrc | The element for row r, column c |
|
virtual |
The destructor
Factory method to create a 3x3 matrix that can be used to rotate one 3D vector onto another 3D vector.
uFrom | the 3D vector to be aligned with uTo |
uTo | the 3D vector onto which we want the created matrix to rotate uFrom |
|
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.
uFrom | the 3D vector to be aligned with uTo |
vFrom | the 3D vector to be aligned with vTo |
uTo | the 3D vector onto which we want the created matrix to rotate uFrom |
vTo | the 3D vector onto which we want the created matrix to rotate vFrom, subject to the constraint explained above. |
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.
u | the desired vector |
double cryph::Matrix3x3::determinant | ( | ) | const |
Return the determinantof "this" 3x3 matrix
double cryph::Matrix3x3::elementAt | ( | int | i, |
int | j | ||
) | const |
Return "this" matrix element at row i and column j.
i | the desired row |
j | the desired column |
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.
w | on exit, this vector will have the rotation axis |
theta | on exit, this will hold the rotation angle in radians |
float * cryph::Matrix3x3::extractColMajor | ( | float | m[9] | ) | const |
Extract the components of the matrix into the given single-precision array in column-major order.
m | [OUTPUT ONLY] an array of float of length 9 |
double * cryph::Matrix3x3::extractColMajor | ( | double | m[9] | ) | const |
Extract the components of the matrix into the given double-precision array in column-major order.
m | [OUTPUT ONLY] an array of double of length 9 |
float * cryph::Matrix3x3::extractRowMajor | ( | float | m[9] | ) | const |
Extract the components of the matrix into the given single-precision array in row-major order.
m | [OUTPUT ONLY] an array of float of length 9 |
double * cryph::Matrix3x3::extractRowMajor | ( | double | m[9] | ) | const |
Extract the components of the matrix into the given double-precision array in row-major order.
m | [OUTPUT ONLY] an array of double of length 9 |
Extract the rows of "this" matrix, writing them into the given output parameters
row1 | on exit, this will hold the first row of "this" matrix |
row2 | on exit, this will hold the second row of "this" matrix |
row3 | on exit, this will hold the third row of "this" matrix |
|
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.
rotationAxis | a 3D vector about which the rotation is to be performed |
angle | the desired rotation angle in radians |
bool cryph::Matrix3x3::inverse | ( | Matrix3x3 & | mInv | ) | const |
Compute and return the inverse of "this" matrix.
mInv | the matrix into which the inverse will be written |
bool cryph::Matrix3x3::isOrthogonal | ( | ) | const |
Report whether "this" matrix is orthogonal. A matrix is orthogonal if its inverse is the same as its transpose.
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.
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.
pos | on exit, the row that contains the largest diagonal element |
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.
mirrorPlaneNormal | the normal vector to the desired mirror plane |
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.
a | an array of length 3 to be multiplied |
b | an array of length 3 that recieves the product "this" * a. |
Multiply the point p on the left by "this" matrix.
p | the point to be multiplied |
Multiply the vector v on the left by "this" matrix.
v | the vector to be multiplied |
Multiply the matrix m2 on the left by "this" matrix.
m2 | the matrix to be multiplied |
Assign to "this" matrix the product of "this" matrix and rhs
rhs | the matrix to be concatenated onto the right-hand side of "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.
f | the scale factor |
Add the matrix m2 to "this" matrix.
m2 | the matrix to be added |
Assign to "this" matrix the sum of "this" matrix and rhs
rhs | the matrix to be added to "this" matrix |
Subtract the matrix m2 from "this" matrix.
m2 | the matrix to be subtracted |
The assignment operator
rhs | the 3x3 matrix to be assigned to "this" matrix |
|
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.
sx | the desired scale factor in the x direction |
sy | the desired scale factor in the y direction |
sz | the desired scale factor in the z direction |
void cryph::Matrix3x3::setElementAt | ( | int | i, |
int | j, | ||
double | newValue | ||
) |
Set this[i][j] = newValue.
i | the row containing the element to be set |
j | the column containing the element to be set |
newValue | the value to be copied into row i and column j |
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.
n | the vector perpendicular to the shear plane |
u | a vector in the shear plane that specifies the shear direction (only the component of u perpendicular to n will be used when creating uHat) |
f | a constant adjusting the amount of shear per length of v in the direction of nHat. |
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]
u | the first vector |
v | the second vector |
double cryph::Matrix3x3::trace | ( | ) | const |
Compute and return the trace of "this" matrix. The trace is the sum of the diagonal elements.
void cryph::Matrix3x3::transpose | ( | ) |
Transpose "this" matrix in place. On exit, "this" matrix will have been transposed.
|
static |
Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the x-axis.
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the x-axis.
angle | the desired rotation angle in radians |
|
static |
Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the y-axis.
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the y-axis.
angle | the desired rotation angle in radians |
|
static |
Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the z-axis.
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 3x3 matrix that can be used to rotate a vector by a given angle about the z-axis.
angle | the desired rotation angle in radians |
Return a matrix that is the product f*m where f is a scale factor used to multiply each element of the matrix, m.
f | the scale factor |
m | the matrix to be scaled (m is unchanged) |
|
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.
os | the stream to which the matrix is written |
m | the matrix to be written |
|
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.
is | the stream from which the matrix is read |
m | the matrix into which the values read are placed |
|
static |
the 3x3 identity matrix
|
static |
the 3x3 zero matrix