#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 | |
| Matrix4 | identity () |
| Matrix4 | translation (const Point3 &p) |
| Matrix4 | translation (const Vector3 &v) |
| Matrix4 | rotation (const Vector3 &u, const Vector3 &v, const Vector3 &w) |
| Matrix4 | rotation (const Vector3 &axis, double angle) |
| Matrix4 | xrotation (double angle) |
| Matrix4 | yrotation (double angle) |
| Matrix4 | zrotation (double angle) |
| Matrix4 | scaling (const Vector3 &s) |
| Matrix4 | scaling (double x, double y, double z) |
| Matrix4 | scaling (double scale) |
Private Attributes | |
| double | mat [16] |
|
|
Definition at line 697 of file vecmath.h. 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 }
|
|
||||||||||||||||||||
|
Definition at line 703 of file vecmath.h. 00703 {
00704 for ( int i = 0; i < 4; i++ ) {
00705 mat[ index( 0, i ) ] = row0[i];
00706 mat[ index( 1, i ) ] = row1[i];
00707 mat[ index( 2, i ) ] = row2[i];
00708 mat[ index( 3, i ) ] = row3[i];
00709 }
00710 }
|
|
||||||||||||||||
|
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 }
|
|
|
Definition at line 723 of file vecmath.h. 00723 {
00724 (*this) = m;
00725 }
|
|
||||||||||||
|
Definition at line 829 of file vecmath.h. References EMAN::isZero(), and mat. 00829 {
00830 for ( int i = 0; i < 16; i++ )
00831 if ( isZero( mat[i] - m.mat[i], eps ) )
00832 return false;
00833 return true;
00834 }
|
|
|
Definition at line 742 of file vecmath.h. 00742 {
00743 return Vector4( mat[index(0,c)], mat[index(1,c)], mat[index(2,c)], mat[index(3,c)] );
00744 }
|
|
|
Definition at line 843 of file vecmath.h. 00843 {
00844 return Matrix4(Vector4(1, 0, 0, 0),
00845 Vector4(0, 1, 0, 0),
00846 Vector4(0, 0, 1, 0),
00847 Vector4(0, 0, 0, 1));
00848 }
|
|
||||||||||||
|
Definition at line 733 of file vecmath.h. References Assert. 00733 { Assert( row >= 0 && row < 4 ); Assert( col >= 0 && col < 4 ); return col * 4 + row; }
|
|
|
Definition at line 960 of file vecmath.h. References Assert, b, 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 }
|
|
|
Definition at line 786 of file vecmath.h. References v. 00786 {
00787 return Vector3((*this)(0,0) * v[0] + (*this)(0,1) * v[1] + (*this)(0,2) * v[2],
00788 (*this)(1,0) * v[0] + (*this)(1,1) * v[1] + (*this)(1,2) * v[2],
00789 (*this)(2,0) * v[0] + (*this)(2,1) * v[1] + (*this)(2,2) * v[2]);
00790 }
|
|
|
Definition at line 746 of file vecmath.h. 00746 {
00747 const Matrix4 matRet = (*this) * m;
00748 (*this) = matRet;
00749 return *this;
00750 }
|
|
||||||||||||
|
Definition at line 736 of file vecmath.h.
|
|
||||||||||||
|
Definition at line 735 of file vecmath.h.
|
|
|
Definition at line 772 of file vecmath.h. References mat. 00772 {
00773 Matrix4 matRet;
00774 for ( int i = 0; i < 16; i++ )
00775 matRet.mat[i] = mat[i] + m.mat[i];
00776 return matRet;
00777 }
|
|
|
Definition at line 752 of file vecmath.h. 00752 {
00753 const Matrix4 matRet = (*this) + m;
00754 (*this) = matRet;
00755 return *this;
00756 }
|
|
|
Definition at line 779 of file vecmath.h. References mat. 00779 {
00780 Matrix4 matRet;
00781 for ( int i = 0; i < 16; i++ )
00782 matRet.mat[i] = mat[i] - m.mat[i];
00783 return matRet;
00784 }
|
|
|
Definition at line 758 of file vecmath.h. 00758 {
00759 const Matrix4 matRet = (*this) - m;
00760 (*this) = matRet;
00761 return *this;
00762 }
|
|
|
Definition at line 727 of file vecmath.h. References mat. 00727 {
00728 memcpy( &mat[0], &m.mat[0], sizeof(double) * 16 );
00729 return *this;
00730 }
|
|
|
Definition at line 822 of file vecmath.h. References mat. 00822 {
00823 for ( int i = 0; i < 16; i++ )
00824 if ( mat[i] != m.mat[i] )
00825 return false;
00826 return true;
00827 }
|
|
|
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 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 }
|
|
||||||||||||||||
|
Definition at line 864 of file vecmath.h. References v. 00864 {
00865 return Matrix4(Vector4(u[0], u[1], u[2], 0),
00866 Vector4(v[0], v[1], v[2], 0),
00867 Vector4(w[0], w[1], w[2], 0),
00868 Vector4(0 , 0 , 0 , 1));
00869 }
|
|
|
Definition at line 738 of file vecmath.h. Referenced by EMAN::operator<<(). 00738 {
00739 return Vector4( mat[index(r,0)], mat[index(r,1)], mat[index(r,2)], mat[index(r,3)] );
00740 }
|
|
|
Definition at line 937 of file vecmath.h. 00937 {
00938 return scaling(Vector3(scale, scale, scale));
00939 }
|
|
||||||||||||||||
|
Definition at line 930 of file vecmath.h. 00930 {
00931 return Matrix4(Vector4(x, 0, 0, 0),
00932 Vector4(0, y, 0, 0),
00933 Vector4(0, 0, z, 0),
00934 Vector4(0, 0, 0, 1));
00935 }
|
|
|
Definition at line 923 of file vecmath.h. 00923 {
00924 return Matrix4(Vector4(s[0], 0 , 0 , 0),
00925 Vector4(0 , s[1], 0 , 0),
00926 Vector4(0 , 0 , s[2], 0),
00927 Vector4(0 , 0 , 0 , 1));
00928 }
|
|
|
Definition at line 857 of file vecmath.h. References v. 00857 {
00858 return Matrix4(Vector4(1, 0, 0, v[0]),
00859 Vector4(0, 1, 0, v[1]),
00860 Vector4(0, 0, 1, v[2]),
00861 Vector4(0, 0, 0, 1));
00862 }
|
|
|
Definition at line 850 of file vecmath.h. 00850 {
00851 return Matrix4(Vector4(1, 0, 0, p[0]),
00852 Vector4(0, 1, 0, p[1]),
00853 Vector4(0, 0, 1, p[2]),
00854 Vector4(0, 0, 0, 1));
00855 }
|
|
|
Definition at line 764 of file vecmath.h. 00764 {
00765 Matrix4 matRet;
00766 for ( int i = 0; i < 4; i++ )
00767 for ( int j = 0; j < 4; j++ )
00768 matRet(i,j) = (*this)(j,i);
00769 return matRet;
00770 }
|
|
|
Definition at line 893 of file vecmath.h. 00893 {
00894 const double c = cos(angle);
00895 const double s = sin(angle);
00896
00897 return Matrix4(Vector4(1, 0, 0, 0),
00898 Vector4(0, c, -s, 0),
00899 Vector4(0, s, c, 0),
00900 Vector4(0, 0, 0, 1));
00901 }
|
|
|
Definition at line 903 of file vecmath.h. 00903 {
00904 double c = cos(angle);
00905 double s = sin(angle);
00906
00907 return Matrix4(Vector4( c, 0, s, 0),
00908 Vector4( 0, 1, 0, 0),
00909 Vector4(-s, 0, c, 0),
00910 Vector4( 0, 0, 0, 1));
00911 }
|
|
|
Definition at line 913 of file vecmath.h. 00913 {
00914 const double c = cos(angle);
00915 const double s = sin(angle);
00916
00917 return Matrix4(Vector4(c, -s, 0, 0),
00918 Vector4(s, c, 0, 0),
00919 Vector4(0, 0, 1, 0),
00920 Vector4(0, 0, 0, 1));
00921 }
|
|
|
Definition at line 942 of file vecmath.h. Referenced by approxEqual(), operator+(), operator-(), operator=(), and operator==(). |
1.3.9.1