EMAN2
Public Member Functions | Static Public Member Functions | Private Attributes
EMAN::Matrix3 Class Reference

#include <vecmath.h>

List of all members.

Public Member Functions

 Matrix3 ()
 Matrix3 (const Vector3 &row0, const Vector3 &row1, const Vector3 &row2)
 Matrix3 (const Matrix3 &m)
Matrix3operator= (const Matrix3 &m)
int index (int row, int col) const
const double & operator() (int row, int col) const
double & operator() (int row, int col)
Vector3 row (int r) const
Vector3 column (int c) const
Matrix3 transpose () const
Matrix3 operator+ (const Matrix3 &m) const
Matrix3operator*= (double s)
Vector3 operator* (const Vector3 &v) const
Point3 operator* (const Point3 &p) const
Matrix3 operator* (const Matrix3 &m) const
double determinant () const
Matrix3 inverse () const
bool operator== (const Matrix3 &m) const
bool approxEqual (const Matrix3 &m, double eps=1e-12) const
void print () const

Static Public Member Functions

static Matrix3 identity ()
static Matrix3 rotationXYZtoUVW (Vector3 u, Vector3 v, Vector3 w)
static double det2x2 (double a, double b, double c, double d)

Private Attributes

double mat [9]

Detailed Description

Definition at line 417 of file vecmath.h.


Constructor & Destructor Documentation

EMAN::Matrix3::Matrix3 ( ) [inline]

Definition at line 419 of file vecmath.h.

References index(), and mat.

Referenced by identity(), inverse(), and rotationXYZtoUVW().

                      {
                for ( int i = 0; i < 3; i++ )
                    for ( int j = 0; j < 3; j++ )
                        mat[ index(i,j) ] = (i == j) ? 1.0 : 0.0;
            }
EMAN::Matrix3::Matrix3 ( const Vector3 row0,
const Vector3 row1,
const Vector3 row2 
) [inline]

Definition at line 425 of file vecmath.h.

References index(), and mat.

                                                                                   {
                for ( int i = 0; i < 3; i++ ) {
                    mat[ index( 0, i ) ] = row0[i];
                    mat[ index( 1, i ) ] = row1[i];
                    mat[ index( 2, i ) ] = row2[i];
                }
            }
EMAN::Matrix3::Matrix3 ( const Matrix3 m) [inline]

Definition at line 433 of file vecmath.h.

                                      {
                (*this) = m;
            }

Member Function Documentation

bool EMAN::Matrix3::approxEqual ( const Matrix3 m,
double  eps = 1e-12 
) const [inline]

Definition at line 553 of file vecmath.h.

References EMAN::isZero(), and mat.

                                                                           {
                for ( int i = 0; i < 9; i++ )
                    if ( isZero( mat[i] - m.mat[i], eps ) )
                        return false;
                return true;
            }
Vector3 EMAN::Matrix3::column ( int  c) const [inline]

Definition at line 452 of file vecmath.h.

References index(), and mat.

                                        {
                return Vector3( mat[index(0,c)], mat[index(1,c)], mat[index(2,c)] );
            }
static double EMAN::Matrix3::det2x2 ( double  a,
double  b,
double  c,
double  d 
) [inline, static]

Definition at line 515 of file vecmath.h.

Referenced by inverse().

                                                                         {
                return a * d - b * c;
            }
double EMAN::Matrix3::determinant ( ) const [inline]

Definition at line 519 of file vecmath.h.

Referenced by inverse().

                                       {
                return ((*this)(0,0) * (*this)(1,1) * (*this)(2,2) +
                        (*this)(0,1) * (*this)(1,2) * (*this)(2,0) +
                        (*this)(0,2) * (*this)(1,0) * (*this)(2,1) -
                        (*this)(0,2) * (*this)(1,1) * (*this)(2,0) -
                        (*this)(0,0) * (*this)(1,2) * (*this)(2,1) -
                        (*this)(0,1) * (*this)(1,0) * (*this)(2,2));
            }
static Matrix3 EMAN::Matrix3::identity ( ) [inline, static]

Definition at line 503 of file vecmath.h.

References Matrix3().

                                      {
                return Matrix3(Vector3(1, 0, 0),
                               Vector3(0, 1, 0),
                               Vector3(0, 0, 1));
            }
int EMAN::Matrix3::index ( int  row,
int  col 
) const [inline]

Definition at line 443 of file vecmath.h.

References Assert, and row().

Referenced by column(), Matrix3(), operator()(), and row().

{ Assert( row >= 0 && row < 3 ); Assert( col >= 0 && col < 3 ); return col * 3 + row; }
Matrix3 EMAN::Matrix3::inverse ( ) const [inline]

Definition at line 528 of file vecmath.h.

References Assert, det2x2(), determinant(), EMAN::isZero(), and Matrix3().

                                    {
                        Matrix3 adjoint = Matrix3( Vector3(  det2x2((*this)(1,1), (*this)(1,2), (*this)(2,1), (*this)(2,2)),
                                          -det2x2((*this)(1,0), (*this)(1,2), (*this)(2,0), (*this)(2,2)),
                                           det2x2((*this)(1,0), (*this)(1,1), (*this)(2,0), (*this)(2,1)) ),
                                                        Vector3( -det2x2((*this)(0,1), (*this)(0,2), (*this)(2,1), (*this)(2,2)),
                                           det2x2((*this)(0,0), (*this)(0,2), (*this)(2,0), (*this)(2,2)),
                                          -det2x2((*this)(0,0), (*this)(0,1), (*this)(2,0), (*this)(2,1)) ),
                                                        Vector3(  det2x2((*this)(0,1), (*this)(0,2), (*this)(1,1), (*this)(1,2)),
                                          -det2x2((*this)(0,0), (*this)(0,2), (*this)(1,0), (*this)(1,2)),
                                           det2x2((*this)(0,0), (*this)(0,1), (*this)(1,0), (*this)(1,1)) ) );
                const double dDet = determinant();
        
                Assert( isZero( dDet ) == false );
                adjoint *= 1.0 / dDet;
        
                return adjoint;
            }
double& EMAN::Matrix3::operator() ( int  row,
int  col 
) [inline]

Definition at line 446 of file vecmath.h.

References index(), and mat.

{ return mat[ index(row,col) ]; }
const double& EMAN::Matrix3::operator() ( int  row,
int  col 
) const [inline]

Definition at line 445 of file vecmath.h.

References index(), and mat.

{ return mat[ index(row,col) ]; }
Vector3 EMAN::Matrix3::operator* ( const Vector3 v) const [inline]

Definition at line 478 of file vecmath.h.

                                                      {
                return Vector3((*this)(0,0) * v[0] + (*this)(0,1) * v[1] + (*this)(0,2) * v[2],
                               (*this)(1,0) * v[0] + (*this)(1,1) * v[1] + (*this)(1,2) * v[2],
                               (*this)(2,0) * v[0] + (*this)(2,1) * v[1] + (*this)(2,2) * v[2]);
            }
Point3 EMAN::Matrix3::operator* ( const Point3 p) const [inline]

Definition at line 485 of file vecmath.h.

                                                    {
                return Point3((*this)(0,0) * p[0] + (*this)(0,1) * p[1] + (*this)(0,2) * p[2],
                              (*this)(1,0) * p[0] + (*this)(1,1) * p[1] + (*this)(1,2) * p[2],
                              (*this)(2,0) * p[0] + (*this)(2,1) * p[1] + (*this)(2,2) * p[2]);
            }
Matrix3 EMAN::Matrix3::operator* ( const Matrix3 m) const [inline]

Definition at line 491 of file vecmath.h.

                                                         {
                Matrix3 matRet;
                for ( int i = 0; i < 3; i++ ) {
                    for ( int j = 0; j < 3; j++ ) {
                        matRet(i,j) = 0.0;
                        for ( int k = 0; k < 3; k++ )
                            matRet(i,j) += (*this)(i,k) * m(k,j);
                    }
                }
                return matRet;
            }
Matrix3& EMAN::Matrix3::operator*= ( double  s) [inline]

Definition at line 471 of file vecmath.h.

References mat.

                                          {
                for ( int i = 0; i < 9; i++ )
                    mat[i] *= s;
                return *this;
            }
Matrix3 EMAN::Matrix3::operator+ ( const Matrix3 m) const [inline]

Definition at line 464 of file vecmath.h.

References mat.

                                                       {
                Matrix3 matRet;
                for ( int i = 0; i < 9; i++ )
                    matRet.mat[i] = mat[i] + m.mat[i];
                return matRet;
            }
Matrix3& EMAN::Matrix3::operator= ( const Matrix3 m) [inline]

Definition at line 437 of file vecmath.h.

References mat.

                                                 {
                memcpy( &mat[0], &m.mat[0], sizeof(double) * 16 );
                return *this;
            }
bool EMAN::Matrix3::operator== ( const Matrix3 m) const [inline]

Definition at line 546 of file vecmath.h.

References mat.

                                                      {
                for ( int i = 0; i < 9; i++ )
                    if ( mat[i] != m.mat[i] )
                        return false;
                return true;
            }
void EMAN::Matrix3::print ( ) const [inline]

Definition at line 560 of file vecmath.h.

                               {
                std::cout << "( " << (*this)(0,0) << ", " << (*this)(0,1) << ", " << (*this)(0,2) << "\n";
                std::cout << "  " << (*this)(1,0) << ", " << (*this)(1,1) << ", " << (*this)(1,2) << "\n";
                std::cout << "  " << (*this)(2,0) << ", " << (*this)(2,1) << ", " << (*this)(2,2) << ")\n";
            }
static Matrix3 EMAN::Matrix3::rotationXYZtoUVW ( Vector3  u,
Vector3  v,
Vector3  w 
) [inline, static]

Definition at line 509 of file vecmath.h.

References Matrix3().

                                                                             {
                return Matrix3(Vector3(u[0], v[0], w[0]),
                               Vector3(u[1], v[1], w[1]),
                               Vector3(u[2], v[2], w[2]));
            }
Vector3 EMAN::Matrix3::row ( int  r) const [inline]

Definition at line 448 of file vecmath.h.

References index(), and mat.

Referenced by index(), and EMAN::operator<<().

                                     {
                return Vector3( mat[index(r,0)], mat[index(r,1)], mat[index(r,2)] );
            }
Matrix3 EMAN::Matrix3::transpose ( ) const [inline]

Definition at line 456 of file vecmath.h.

                                      {
                Matrix3 matRet;
                for ( int i = 0; i < 3; i++ )
                    for ( int j = 0; j < 3; j++ )
                        matRet(i,j) = (*this)(j,i);
                return matRet;
            }

Member Data Documentation

double EMAN::Matrix3::mat[9] [private]

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