#include <vecmath.h>
Public Member Functions | |
Matrix4 () | |
Matrix4 (const Vector4 &row0, const Vector4 &row1, const Vector4 &row2, const Vector4 &row3) | |
Matrix4 (const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) | |
Matrix4 (const Matrix4 &m) | |
Matrix4 & | operator= (const Matrix4 &m) |
int | index (int row, int col) const |
const double & | operator() (int row, int col) const |
double & | operator() (int row, int col) |
Vector4 | row (int r) const |
Vector4 | column (int c) const |
Matrix4 & | operator *= (const Matrix4 &m) |
Matrix4 & | operator+= (const Matrix4 &m) |
Matrix4 & | operator-= (const Matrix4 &m) |
Matrix4 | transpose () const |
Matrix4 | operator+ (const Matrix4 &m) const |
Matrix4 | operator- (const Matrix4 &m) const |
Vector3 | operator * (const Vector3 &v) const |
Point3 | operator * (const Point3 &p) const |
Vector4 | operator * (const Vector4 &v) const |
Matrix4 | operator * (const Matrix4 &b) const |
Matrix4 | inverse () const |
bool | operator== (const Matrix4 &m) const |
bool | approxEqual (const Matrix4 &m, double eps=1e-12) const |
void | print () const |
Static Public Member Functions | |
static Matrix4 | identity () |
static Matrix4 | translation (const Point3 &p) |
static Matrix4 | translation (const Vector3 &v) |
static Matrix4 | rotation (const Vector3 &u, const Vector3 &v, const Vector3 &w) |
static Matrix4 | rotation (const Vector3 &axis, double angle) |
static Matrix4 | xrotation (double angle) |
static Matrix4 | yrotation (double angle) |
static Matrix4 | zrotation (double angle) |
static Matrix4 | scaling (const Vector3 &s) |
static Matrix4 | scaling (double x, double y, double z) |
static Matrix4 | scaling (double scale) |
Private Attributes | |
double | mat [16] |
Definition at line 695 of file vecmath.h.
EMAN::Matrix4::Matrix4 | ( | ) | [inline] |
Definition at line 697 of file vecmath.h.
Referenced by identity(), rotation(), scaling(), translation(), xrotation(), yrotation(), and zrotation().
00697 { 00698 for ( int i = 0; i < 4; i++ ) 00699 for ( int j = 0; j < 4; j++ ) 00700 mat[ index(i,j) ] = (i == j) ? 1.0 : 0.0; 00701 }
EMAN::Matrix4::Matrix4 | ( | const Vector3 & | row0, | |
const Vector3 & | row1, | |||
const Vector3 & | row2 | |||
) | [inline] |
Definition at line 712 of file vecmath.h.
00712 { 00713 for ( int i = 0; i < 3; i++ ) { 00714 mat[ index( 0, i ) ] = row0[i]; 00715 mat[ index( 1, i ) ] = row1[i]; 00716 mat[ index( 2, i ) ] = row2[i]; 00717 mat[ index(i,3) ] = 0.0; 00718 mat[ index(3,i) ] = 0.0; 00719 } 00720 mat[ index(3,3) ] = 1.0; 00721 }
EMAN::Matrix4::Matrix4 | ( | const Matrix4 & | m | ) | [inline] |
bool EMAN::Matrix4::approxEqual | ( | const Matrix4 & | m, | |
double | eps = 1e-12 | |||
) | const [inline] |
Vector4 EMAN::Matrix4::column | ( | int | c | ) | const [inline] |
static Matrix4 EMAN::Matrix4::identity | ( | ) | [inline, static] |
int EMAN::Matrix4::index | ( | int | row, | |
int | col | |||
) | const [inline] |
Matrix4 EMAN::Matrix4::inverse | ( | ) | const [inline] |
Definition at line 960 of file vecmath.h.
References Assert, b, identity(), and EMAN::isZero().
00960 { 00961 // Compute inverse using Gauss-Jordan elimination; caller is responsible 00962 // for ensuring that the matrix isn't singular. 00963 Matrix4 a(*this); 00964 Matrix4 b(Matrix4::identity()); 00965 int i, j; 00966 int p; 00967 00968 for (j = 0; j < 4; j++) { 00969 p = j; 00970 for (i = j + 1; i < 4; i++) { 00971 if (fabs(a(i,j)) > fabs(a(p,j))) 00972 p = i; 00973 } 00974 // Swap rows p and j 00975 if ( p != j ) { 00976 for ( i = 0; i < 4; i++ ) { 00977 const double ta = a(p,i); 00978 a(p,i) = a(j,i); 00979 a(j,i) = ta; 00980 00981 const double tb = b(p,i); 00982 b(p,i) = b(j,i); 00983 b(j,i) = tb; 00984 } 00985 } 00986 00987 const double s = a(j,j); // if s == 0, the matrix is singular 00988 Assert( isZero( s ) == false ); 00989 for ( i = 0; i < 4; i++ ) { 00990 a(j,i) *= (1.0 / s); 00991 b(j,i) *= (1.0 / s); 00992 } 00993 // Eliminate off-diagonal elements 00994 for (i = 0; i < 4; i++) { 00995 if (i != j) { 00996 for ( int k = 0; k < 4; k++ ) { 00997 b(i,k) -= a(i,j) * b(j,k); 00998 a(i,k) -= a(i,j) * a(j,k); 00999 } 01000 } 01001 } 01002 } 01003 return b; 01004 }
Definition at line 808 of file vecmath.h.
References b.
00808 { 00809 Matrix4 matRet; 00810 for ( int i = 0; i < 4; i++ ) { 00811 for ( int j = 0; j < 4; j++ ) { 00812 matRet(i,j) = 0.0; 00813 for ( int k = 0; k < 4; k++ ) 00814 matRet(i,j) += (*this)(i,k) * b(k,j); 00815 } 00816 } 00817 return matRet; 00818 }
Definition at line 801 of file vecmath.h.
References v.
00801 { 00802 return Vector4((*this)(0,0) * v[0] + (*this)(0,1) * v[1] + (*this)(0,2) * v[2] + (*this)(0,3) * v[3], 00803 (*this)(1,0) * v[0] + (*this)(1,1) * v[1] + (*this)(1,2) * v[2] + (*this)(1,3) * v[3], 00804 (*this)(2,0) * v[0] + (*this)(2,1) * v[1] + (*this)(2,2) * v[2] + (*this)(2,3) * v[3], 00805 (*this)(3,0) * v[0] + (*this)(3,1) * v[1] + (*this)(3,2) * v[2] + (*this)(3,3) * v[3]); 00806 }
Definition at line 792 of file vecmath.h.
References Assert, and EMAN::isZero().
00792 { 00793 const Point3 pt((*this)(0,0) * p[0] + (*this)(0,1) * p[1] + (*this)(0,2) * p[2] + (*this)(0,3), 00794 (*this)(1,0) * p[0] + (*this)(1,1) * p[1] + (*this)(1,2) * p[2] + (*this)(1,3), 00795 (*this)(2,0) * p[0] + (*this)(2,1) * p[1] + (*this)(2,2) * p[2] + (*this)(2,3)); 00796 const double w = (*this)(3,0) * p[0] + (*this)(3,1) * p[1] + (*this)(3,2) * p[2] + (*this)(3,3); 00797 Assert( isZero( w ) == false ); 00798 return Point3( pt[0] / w, pt[1] / w, pt[2] / w ); 00799 }
double& EMAN::Matrix4::operator() | ( | int | row, | |
int | col | |||
) | [inline] |
const double& EMAN::Matrix4::operator() | ( | int | row, | |
int | col | |||
) | const [inline] |
bool EMAN::Matrix4::operator== | ( | const Matrix4 & | m | ) | const [inline] |
void EMAN::Matrix4::print | ( | ) | const [inline] |
Definition at line 836 of file vecmath.h.
00836 { 00837 std::cout << "( " << (*this)(0,0) << ", " << (*this)(0,1) << ", " << (*this)(0,2) << ", " << (*this)(0,3) << "\n"; 00838 std::cout << " " << (*this)(1,0) << ", " << (*this)(1,1) << ", " << (*this)(1,2) << ", " << (*this)(1,3) << "\n"; 00839 std::cout << " " << (*this)(2,0) << ", " << (*this)(2,1) << ", " << (*this)(2,2) << ", " << (*this)(2,3) << "\n"; 00840 std::cout << " " << (*this)(3,0) << ", " << (*this)(3,1) << ", " << (*this)(3,2) << ", " << (*this)(3,3) << ")\n"; 00841 }
Definition at line 871 of file vecmath.h.
References Matrix4(), EMAN::Vector3::normalize(), and t.
00871 { 00872 Vector3 a = axis; 00873 a.normalize(); 00874 const double c = cos(angle); 00875 const double s = sin(angle); 00876 const double t = 1 - c; 00877 00878 return Matrix4(Vector4(t * a[0] * a[0] + c, 00879 t * a[0] * a[1] - s * a[2], 00880 t * a[0] * a[2] + s * a[1], 00881 0), 00882 Vector4(t * a[0] * a[1] + s * a[2], 00883 t * a[1] * a[1] + c, 00884 t * a[1] * a[2] - s * a[0], 00885 0), 00886 Vector4(t * a[0] * a[2] - s * a[1], 00887 t * a[1] * a[2] + s * a[0], 00888 t * a[2] * a[2] + c, 00889 0), 00890 Vector4(0, 0, 0, 1)); 00891 }
Vector4 EMAN::Matrix4::row | ( | int | r | ) | const [inline] |
static Matrix4 EMAN::Matrix4::scaling | ( | double | scale | ) | [inline, static] |
static Matrix4 EMAN::Matrix4::scaling | ( | double | x, | |
double | y, | |||
double | z | |||
) | [inline, static] |
Matrix4 EMAN::Matrix4::transpose | ( | ) | const [inline] |
static Matrix4 EMAN::Matrix4::xrotation | ( | double | angle | ) | [inline, static] |
static Matrix4 EMAN::Matrix4::yrotation | ( | double | angle | ) | [inline, static] |
static Matrix4 EMAN::Matrix4::zrotation | ( | double | angle | ) | [inline, static] |
double EMAN::Matrix4::mat[16] [private] |
Definition at line 942 of file vecmath.h.
Referenced by approxEqual(), column(), Matrix4(), operator()(), operator+(), operator-(), operator=(), operator==(), and row().