cryph utilities [subset]
2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
|
Public Member Functions | |
Matrix4x4 () | |
Matrix4x4 (const Matrix4x4 &m) | |
Matrix4x4 (double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44) | |
Matrix4x4 (const Matrix3x3 &M) | |
Matrix4x4 (const Matrix3x3 &M, const AffVector &t) | |
Matrix4x4 (const Matrix3x3 &M, const AffPoint &FixedPoint) | |
Matrix4x4 (const Matrix3x3 &M, const AffPoint &PreImage, const AffPoint &PostImage) | |
virtual | ~Matrix4x4 () |
Matrix4x4 | operator= (const Matrix4x4 &rhs) |
Matrix4x4 | operator*= (const Matrix4x4 &rhs) |
Matrix4x4 | operator*= (double f) |
Matrix4x4 | operator+= (const Matrix4x4 &rhs) |
AffPoint | operator* (const AffPoint &p) const |
ProjPoint | operator* (const ProjPoint &p) const |
AffVector | operator* (const AffVector &v) const |
Matrix4x4 | operator* (const Matrix4x4 &m2) const |
Matrix4x4 | operator+ (const Matrix4x4 &m2) const |
Matrix4x4 | operator- (const Matrix4x4 &m2) const |
double | determinant () const |
double | elementAt (int r, int c) const |
float * | extractColMajor (float m[16]) const |
double * | extractColMajor (double m[16]) const |
float * | extractRowMajor (float m[16]) const |
double * | extractRowMajor (double m[16]) const |
void | extractAffineMt (Matrix3x3 &M, AffVector &t) const |
int | extractAxisAngle (AffPoint &B, AffVector &w, double &theta, AffVector &postTranslation) const |
bool | inverse (Matrix4x4 &mInv) const |
int | isAffineTransformation () const |
void | multiply (const double a[], double b[], int nElements=4) const |
void | multiply (const float a[], float b[], int nElements=4) const |
void | setElementAt (int r, int c, double newValue) |
Matrix3x3 | subMatrix (int skipRow, int skipCol) const |
Static Public Member Functions | |
static Matrix4x4 | fromColMajor (const float *m) |
static Matrix4x4 | fromColMajor (const double *m) |
static Matrix4x4 | fromRowMajor (const float *m) |
static Matrix4x4 | fromRowMajor (const double *m) |
static Matrix4x4 | generalRotationDegrees (const AffPoint &B, const AffVector &axis, double angle) |
static Matrix4x4 | generalRotationRadians (const AffPoint &B, const AffVector &axis, double angle) |
static Matrix4x4 | mirror (const AffPoint &B, const AffVector &n) |
static Matrix4x4 | xRotationDegrees (double angle) |
static Matrix4x4 | yRotationDegrees (double angle) |
static Matrix4x4 | zRotationDegrees (double angle) |
static Matrix4x4 | xRotationRadians (double angle) |
static Matrix4x4 | yRotationRadians (double angle) |
static Matrix4x4 | zRotationRadians (double angle) |
static Matrix4x4 | translation (const AffVector &trans) |
static Matrix4x4 | translation (double dx, double dy, double dz) |
static Matrix4x4 | scale (double sx, double sy, double sz) |
static Matrix4x4 | lookAt (const cryph::AffPoint &eye, const cryph::AffPoint ¢er, const cryph::AffVector &up) |
static Matrix4x4 | orthogonal (double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) |
static Matrix4x4 | oblique (double zpp, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, const cryph::AffVector &projDir) |
static Matrix4x4 | perspective (double zpp, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double h=0.0) |
static bool | getECvw (const cryph::AffPoint &eye, const cryph::AffPoint ¢er, const cryph::AffVector &up, cryph::AffVector &v, cryph::AffVector &w) |
Static Public Attributes | |
static const Matrix4x4 | IdentityMatrix |
static const Matrix4x4 | ZeroMatrix |
static const int | InternalBasePointComputationError = -30 |
static const int | NotAffine = -10 |
static const int | Extracted_BwTheta = 1 |
Protected Attributes | |
double | mElem [4][4] |
Friends | |
Matrix4x4 | operator* (double f, const Matrix4x4 &m) |
std::ostream & | operator<< (std::ostream &os, const Matrix4x4 &m) |
std::istream & | operator>> (std::istream &is, Matrix4x4 &m) |
cryph::Matrix4x4::Matrix4x4 | ( | ) |
Default constructor creates a 4x4 identity matrix
cryph::Matrix4x4::Matrix4x4 | ( | const Matrix4x4 & | m | ) |
The copy constructor
m | the matrix whose elements are copied |
cryph::Matrix4x4::Matrix4x4 | ( | double | m11, |
double | m12, | ||
double | m13, | ||
double | m14, | ||
double | m21, | ||
double | m22, | ||
double | m23, | ||
double | m24, | ||
double | m31, | ||
double | m32, | ||
double | m33, | ||
double | m34, | ||
double | m41, | ||
double | m42, | ||
double | m43, | ||
double | m44 | ||
) |
Construct a 4x4 matrix directly from 16 values given in row-major order
mrc | The element for row r, column c |
cryph::Matrix4x4::Matrix4x4 | ( | const Matrix3x3 & | M | ) |
Construct a 4x4 transformation matrix from a 3x3 matrix that is assumed to encode a 2D transformation in projective space. The implementation slides the third row and third column over to the fourth, and inserts a third row and third column from a 4x4 Identity matrix.
M | a 3x3 matrix that describes a 2D xform in projective space. That is, it is assumed to do (x', y', w')^T = M*(x, y, 1)^T. |
Construct a 4x4 matrix from an Affine transformation: (M, t), where (x', y', z')^T = M*(x, y, z)^T + t. The implementation places M in the upper left 3x3 submatrix of the 4x4 matrix, it places t in the first three rows of the fourth column, and it assigns (0,0,0,1) to the 4th row.
M | a 3x3 matrix encoding a linear transformation on 3D vectors |
t | a 3D vector |
Construct a 4x4 matrix from a 3x3 matrix, M (encoding a linear transformation on 3D vectors) and a fixed point. It first constructs the translation vector, t, such that: M*FixedPoint + t = FixedPoint. It then creates the matrix as if the constructor with prototype Matrix4x4(Matrix3x3, AffVector) were called.
M | a 3x3 matrix encoding a linear transformation on 3D vectors |
FixedPoint | a 3D affine point unaffected by the affine transformation |
cryph::Matrix4x4::Matrix4x4 | ( | const Matrix3x3 & | M, |
const AffPoint & | PreImage, | ||
const AffPoint & | PostImage | ||
) |
Construct a 4x4 matrix from a 3x3 matrix, M (encoding a linear transformation on 3D vectors) and a pair of points, the latter being the point to which the former is mapped by the transformation to be encoded in this newly constructed matrix. It first constructs the translation vector, t, such that: M*PreImage + t = PostImage. It then creates the matrix as if the constructor with prototype Matrix4x4(Matrix3x3, AffVector) were called.
M | a 3x3 matrix encoding a linear transformation on 3D vectors |
PreImage | a 3D affine point |
PostImage | the 3D affine point to which "PreImage" is mapped |
|
virtual |
The destructor
double cryph::Matrix4x4::determinant | ( | ) | const |
Compute the determinant of "this" matrix
double cryph::Matrix4x4::elementAt | ( | int | r, |
int | c | ||
) | const |
Retrieve a specific element of the matrix
r | the row containing the desired element |
c | the column containing the desired element |
Retrieve the affine transformation embedded in "this" 4x4 matrix. This method assumes that "this" matrix encodes an affine transformation and it simply places the upper left 3x3 into M, and the first three rows of the fourth column into t. It does not check to make sure that the 4th row is (0, 0, 0, 1).
M | [OUTPUT ONLY] the 3x3 matrix into which the upper left 3x3 submatrix of "this" matrix is to be written |
t | [OUTPUT ONLY] the 3D vector into which the first three rows of the fourth column of "this" matrix is to be written. |
int cryph::Matrix4x4::extractAxisAngle | ( | AffPoint & | B, |
AffVector & | w, | ||
double & | theta, | ||
AffVector & | postTranslation | ||
) | const |
The following routine attempts to find the unit axis vector (w) and angle (theta) which, when interpreted as a rotatition axis and angle, will reproduce the upper 3x3 portion of the matrix. It then computes a base point B which, when combined with (w,theta) will at least approximate the entire 4x4 matrix. At worst, a residual "postTranslation" will be required to reproduce the effect of the original 4x4 matrix. That translation (possibly 0) is returned in "postTranslation".
B | [OUTPUT ONLY] the base point for the equivalent rotation axis |
w | [OUTPUT ONLY] the unit rotation axis vector |
theta | [OUTPUT ONLY] the computed rotation angle in radians |
postTranslation | [OUTPUT ONLY] the post-translation required to complete the matching of the original 4x4 matrix |
float * cryph::Matrix4x4::extractColMajor | ( | float | m[16] | ) | 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 16 |
double * cryph::Matrix4x4::extractColMajor | ( | double | m[16] | ) | 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 16 |
float * cryph::Matrix4x4::extractRowMajor | ( | float | m[16] | ) | 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 16 |
double * cryph::Matrix4x4::extractRowMajor | ( | double | m[16] | ) | 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 16 |
|
static |
Factory method to create a 4x4 matrix from a single precision array of 16 elements assumed to hold the values of the matrix in column-major order.
m | an array of float of length 16 |
|
static |
Factory method to create a 4x4 matrix from a double precision array of 16 elements assumed to hold the values of the matrix in column-major order.
m | an array of double of length 16 |
|
static |
Factory method to create a 4x4 matrix from a single precision array of 16 elements assumed to hold the values of the matrix in row-major order.
m | an array of float of length 16 |
|
static |
Factory method to create a 4x4 matrix from a double precision array of 16 elements assumed to hold the values of the matrix in row-major order.
m | an array of double of length 16 |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about a general axis in 3D space.
B | a 3D point on the desired rotation axis |
axis | a 3D vector along the rotation axis |
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about a general axis in 3D space.
B | a 3D point on the desired rotation axis |
axis | a 3D vector along the rotation axis |
angle | the desired rotation angle in radians |
|
static |
Determine whether a given (eye, center, up) specification uniquely specifies a MC to EC transformation. This method is primarily designed for internal use (i.e., as a part of the implementation of "lookAt"), but it is potentially useful externally as well in order to ensure that a given set of viewing parameters is valid.
eye | the (x,y,z) model coordinate position of the viewer |
center | the (x,y,z) model coordinate position of the "center of attention", typically a point in front of the eye near the center of the scene to be viewed. |
up | a 3D vector to fix the final rotational degree of freedom. The component of the "up" vector perpendicular to the line of sight (the vector from "center" towards "eye") will become the y-axis of the eye coordinate system. |
v | [OUTPUT ONLY] the unit vector as measured in MC of the EC y-axis |
w | [OUTPUT ONLY] the unit vector as measured in MC of the EC z-axis |
bool cryph::Matrix4x4::inverse | ( | Matrix4x4 & | mInv | ) | const |
Invert "this" matrix. This method is NOT highly numerical stable. It is OK with well-conditioned matrices. For a better matrix inverse implementation for when the matrix may be poorly conditioned, use MatrixNxN::inverse.
mInv | [OUTPUT ONLY] the inverted matriux will be deposited here |
int cryph::Matrix4x4::isAffineTransformation | ( | ) | const |
Determine whether "this" matrix represents an affine transformation
|
static |
Factory method to create a 4x4 matrix that maps model coordinates into an eye coordinate system in which the x-axis is oriented left to right in the field of view; the y-axis is oriented bottom to top, and the z-axis is oriented from the scene back towards the eye.
eye | the (x,y,z) model coordinate position of the viewer |
center | the (x,y,z) model coordinate position of the "center of attention", typically a point in front of the eye near the center of the scene to be viewed. |
up | a 3D vector to fix the final rotational degree of freedom. The component of the "up" vector perpendicular to the line of sight (the vector from "center" towards "eye") will become the y-axis of the eye coordinate system. |
Factory method to create a 4x4 matrix that mirrors geometry about a general plane in 3D space.
B | a 3D point on the desired mirror plane |
n | a 3D vector perpendicular to the plane |
void cryph::Matrix4x4::multiply | ( | const double | a[], |
double | b[], | ||
int | nElements = 4 |
||
) | const |
Compute b = this * a
a | [INPUT ONLY] the untransformed tuple |
b | [OUTPUT ONLY] the computed product |
nElements | the length of the 'a' and 'b' arrays. If nElements<4, then (i) a[3] is assumed to be 1.0, and (ii) a[i] for nElements<=i<3 are assumed to be zero. nElements cannot be larger than 4. Only nElements positions of 'b' will be set. |
void cryph::Matrix4x4::multiply | ( | const float | a[], |
float | b[], | ||
int | nElements = 4 |
||
) | const |
Compute b = this * a
a | [INPUT ONLY] the untransformed tuple |
b | [OUTPUT ONLY] the computed product |
nElements | the length of the 'a' and 'b' arrays. If nElements<4, then (i) a[3] is assumed to be 1.0, and (ii) a[i] for nElements<=i<3 are assumed to be zero. nElements cannot be larger than 4. Only nElements positions of 'b' will be set. |
|
static |
Factory method to create a 4x4 matrix that performs an oblique projection from an eye coordinate system into a logical device space (LDS) in which the x, y, and z limits are -1 .. +1. This will incorporate a shear transformation that will produce an orthogonal left-handed LDS system as expected by OpenGL.
zpp | the eye coordinate z value that specifies the location of the projection plane |
xmin | the minimum x eye coordinate of the desired field of view defined on the projection plane |
xmax | the maximum x eye coordinate of the desired field of view defined on the projection plane |
ymin | the minimum y eye coordinate of the desired field of view defined on the projection plane |
ymax | the maximum y eye coordinate of the desired field of view defined on the projection plane |
zmin | the minimum z eye coordinate of the desired field of view |
zmax | the maximum z eye coordinate of the desired field of view |
projDir | a vector defined in eye coordinates that specifies the common direction of projection. projDir.dz cannot be zero. |
Multiply an affine point by "this" matrix: p' = this * p. The point will be transformed using only the upper left 3x3 submatrix, M, and the translation vector, t, taken from the first three rows of the fourth column: p' = M*p + t.
p | the 3D affine point to be transformed |
Multiply a point in projective space by "this" matrix: p' = this * p.
p | the 4D projective space point to be transformed |
Multiply a 3D vector by "this" matrix: v' = this * v. The vector will be transformed using only the upper left 3x3 submatrix, M. v' = M*v.
v | the 3D vector to be transformed |
Multiply "this" matrix on the right by "m2"
m2 | the matrix to be multiplied by "this" matrix |
Assign this = this*rhs
rhs | the 4x4 matrix to be multiplied on the right of "this" |
Matrix4x4 cryph::Matrix4x4::operator*= | ( | double | f | ) |
Assign this = f*this. (That is, scale all elements of "this" matrix by "f".)
f | the scale factor |
Add "this" matrix to matrix "m2"
m2 | the matrix to be added to "this" matrix |
Assign this = this + rhs
rhs | the 4x4 matrix whose elements are to be added to "this" |
Subtract m2 from "this" matrix
m2 | the matrix to be subtracted from "this" matrix |
Assigns the matrix "rhs" to "this" matrix
rhs | the matrix whose values are to be copied |
|
static |
Factory method to create a 4x4 matrix that performs an orthogonal projection from an eye coordinate system into a logical device space (LDS) in which the x, y, and z limits are -1 .. +1. This will produce a left-handed LDS system as expected by OpenGL.
xmin | the minimum x eye coordinate of the desired field of view |
xmax | the maximum x eye coordinate of the desired field of view |
ymin | the minimum y eye coordinate of the desired field of view |
ymax | the maximum y eye coordinate of the desired field of view |
zmin | the minimum z eye coordinate of the desired field of view |
zmax | the maximum z eye coordinate of the desired field of view |
|
static |
Factory method to create a 4x4 matrix that performs a perspective projection from an eye coordinate system into a logical device space (LDS) in which the x, y, and z limits are -1 .. +1. This will produce an orthogonal left-handed LDS system as expected by OpenGL.
zpp | the eye coordinate z value that specifies the location of the projection plane |
xmin | the minimum x eye coordinate of the desired field of view defined on the projection plane |
xmax | the maximum x eye coordinate of the desired field of view defined on the projection plane |
ymin | the minimum y eye coordinate of the desired field of view defined on the projection plane |
ymax | the maximum y eye coordinate of the desired field of view defined on the projection plane |
zmin | the minimum z eye coordinate of the desired field of view (must be negative) |
zmax | the maximum z eye coordinate of the desired field of view (must be negative AND strictly greater than zmin) |
h | the signed half-distance between the left and right eye, if generating a matrix for a stereo display. If (h<0), this is for the left eye; if (h>0) this is for the right eye. To generate a single perspective matrix for a monoscopic view, use the default h==0. |
NOTE: if a stereo pair is being created by generating two different MC to EC matrices, then a common perspective matrix should be used for both the left and right eye cumulative matrices, and h should be 0.
|
static |
Factory method to create a 4x4 matrix that performs a non-uniform scale transformation.
sx | the scale factor along the x-axis |
sy | the scale factor along the y-axis |
sz | the scale factor along the z-axis |
void cryph::Matrix4x4::setElementAt | ( | int | r, |
int | c, | ||
double | newValue | ||
) |
Set a specific element of the matrix
r | the row containing the desired element |
c | the column containing the desired element |
newValue | the value to be placed into this[r][c] |
Matrix3x3 cryph::Matrix4x4::subMatrix | ( | int | skipRow, |
int | skipCol | ||
) | const |
Extract the 3x3 submatrix determined by removing row "skipRow" and column "skipCol".
skipRow | the row to be removed |
skipCol | the column to be removed |
Factory method to create a 4x4 matrix that performs a translation
trans | the desired translation vector |
|
static |
Factory method to create a 4x4 matrix that performs a translation
dx | the x component of the desired translation vector |
dy | the y component of the desired translation vector |
dz | the z component of the desired translation vector |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about the x-axis.
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about the x-axis.
angle | the desired rotation angle in radians |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about the y-axis.
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about the y-axis.
angle | the desired rotation angle in radians |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about the z-axis.
angle | the desired rotation angle in degrees |
|
static |
Factory method to create a 4x4 matrix that performs a rotation about the z-axis.
angle | the desired rotation angle in radians |
Scale the given matrix by the given scale factor
f | the scale factor |
m | the matrix to scale (will not be modified) |
|
static |
the 4x4 identity matrix
|
static |
the 4x4 zero matrix