EMAN2
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
EMAN::Matrix3 Class Reference

#include <vecmath.h>

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 413 of file vecmath.h.

Constructor & Destructor Documentation

◆ Matrix3() [1/3]

EMAN::Matrix3::Matrix3 ( )
inline

Definition at line 415 of file vecmath.h.

415 {
416 for ( int i = 0; i < 3; i++ )
417 for ( int j = 0; j < 3; j++ )
418 mat[ index(i,j) ] = (i == j) ? 1.0 : 0.0;
419 }
int index(int row, int col) const
Definition: vecmath.h:439
double mat[9]
Definition: vecmath.h:563

References index(), and mat.

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

◆ Matrix3() [2/3]

EMAN::Matrix3::Matrix3 ( const Vector3 row0,
const Vector3 row1,
const Vector3 row2 
)
inline

Definition at line 421 of file vecmath.h.

421 {
422 for ( int i = 0; i < 3; i++ ) {
423 mat[ index( 0, i ) ] = row0[i];
424 mat[ index( 1, i ) ] = row1[i];
425 mat[ index( 2, i ) ] = row2[i];
426 }
427 }

References index(), and mat.

◆ Matrix3() [3/3]

EMAN::Matrix3::Matrix3 ( const Matrix3 m)
inline

Definition at line 429 of file vecmath.h.

429 {
430 (*this) = m;
431 }

Member Function Documentation

◆ approxEqual()

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

Definition at line 549 of file vecmath.h.

549 {
550 for ( int i = 0; i < 9; i++ )
551 if ( isZero( mat[i] - m.mat[i], eps ) )
552 return false;
553 return true;
554 }
bool isZero(double in_d, double in_dEps=1e-16)
Definition: vecmath.h:44

References EMAN::isZero(), and mat.

◆ column()

Vector3 EMAN::Matrix3::column ( int  c) const
inline

Definition at line 448 of file vecmath.h.

448 {
449 return Vector3( mat[index(0,c)], mat[index(1,c)], mat[index(2,c)] );
450 }

References index(), and mat.

◆ det2x2()

static double EMAN::Matrix3::det2x2 ( double  a,
double  b,
double  c,
double  d 
)
inlinestatic

Definition at line 511 of file vecmath.h.

511 {
512 return a * d - b * c;
513 }

Referenced by inverse().

◆ determinant()

double EMAN::Matrix3::determinant ( ) const
inline

Definition at line 515 of file vecmath.h.

515 {
516 return ((*this)(0,0) * (*this)(1,1) * (*this)(2,2) +
517 (*this)(0,1) * (*this)(1,2) * (*this)(2,0) +
518 (*this)(0,2) * (*this)(1,0) * (*this)(2,1) -
519 (*this)(0,2) * (*this)(1,1) * (*this)(2,0) -
520 (*this)(0,0) * (*this)(1,2) * (*this)(2,1) -
521 (*this)(0,1) * (*this)(1,0) * (*this)(2,2));
522 }

Referenced by inverse().

◆ identity()

static Matrix3 EMAN::Matrix3::identity ( )
inlinestatic

Definition at line 499 of file vecmath.h.

499 {
500 return Matrix3(Vector3(1, 0, 0),
501 Vector3(0, 1, 0),
502 Vector3(0, 0, 1));
503 }

References Matrix3().

◆ index()

int EMAN::Matrix3::index ( int  row,
int  col 
) const
inline

Definition at line 439 of file vecmath.h.

439{ Assert( row >= 0 && row < 3 ); Assert( col >= 0 && col < 3 ); return col * 3 + row; }
Vector3 row(int r) const
Definition: vecmath.h:444
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
Definition: emassert.h:42

References Assert, and row().

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

◆ inverse()

Matrix3 EMAN::Matrix3::inverse ( ) const
inline

Definition at line 524 of file vecmath.h.

524 {
525 Matrix3 adjoint = Matrix3( Vector3( det2x2((*this)(1,1), (*this)(1,2), (*this)(2,1), (*this)(2,2)),
526 -det2x2((*this)(1,0), (*this)(1,2), (*this)(2,0), (*this)(2,2)),
527 det2x2((*this)(1,0), (*this)(1,1), (*this)(2,0), (*this)(2,1)) ),
528 Vector3( -det2x2((*this)(0,1), (*this)(0,2), (*this)(2,1), (*this)(2,2)),
529 det2x2((*this)(0,0), (*this)(0,2), (*this)(2,0), (*this)(2,2)),
530 -det2x2((*this)(0,0), (*this)(0,1), (*this)(2,0), (*this)(2,1)) ),
531 Vector3( det2x2((*this)(0,1), (*this)(0,2), (*this)(1,1), (*this)(1,2)),
532 -det2x2((*this)(0,0), (*this)(0,2), (*this)(1,0), (*this)(1,2)),
533 det2x2((*this)(0,0), (*this)(0,1), (*this)(1,0), (*this)(1,1)) ) );
534 const double dDet = determinant();
535
536 Assert( isZero( dDet ) == false );
537 adjoint *= 1.0 / dDet;
538
539 return adjoint;
540 }
static double det2x2(double a, double b, double c, double d)
Definition: vecmath.h:511
double determinant() const
Definition: vecmath.h:515

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

◆ operator()() [1/2]

double & EMAN::Matrix3::operator() ( int  row,
int  col 
)
inline

Definition at line 442 of file vecmath.h.

442{ return mat[ index(row,col) ]; }

References index(), mat, and row().

◆ operator()() [2/2]

const double & EMAN::Matrix3::operator() ( int  row,
int  col 
) const
inline

Definition at line 441 of file vecmath.h.

441{ return mat[ index(row,col) ]; }

References index(), mat, and row().

◆ operator*() [1/3]

Matrix3 EMAN::Matrix3::operator* ( const Matrix3 m) const
inline

Definition at line 487 of file vecmath.h.

487 {
488 Matrix3 matRet;
489 for ( int i = 0; i < 3; i++ ) {
490 for ( int j = 0; j < 3; j++ ) {
491 matRet(i,j) = 0.0;
492 for ( int k = 0; k < 3; k++ )
493 matRet(i,j) += (*this)(i,k) * m(k,j);
494 }
495 }
496 return matRet;
497 }

◆ operator*() [2/3]

Point3 EMAN::Matrix3::operator* ( const Point3 p) const
inline

Definition at line 481 of file vecmath.h.

481 {
482 return Point3((*this)(0,0) * p[0] + (*this)(0,1) * p[1] + (*this)(0,2) * p[2],
483 (*this)(1,0) * p[0] + (*this)(1,1) * p[1] + (*this)(1,2) * p[2],
484 (*this)(2,0) * p[0] + (*this)(2,1) * p[1] + (*this)(2,2) * p[2]);
485 }

◆ operator*() [3/3]

Vector3 EMAN::Matrix3::operator* ( const Vector3 v) const
inline

Definition at line 474 of file vecmath.h.

474 {
475 return Vector3((*this)(0,0) * v[0] + (*this)(0,1) * v[1] + (*this)(0,2) * v[2],
476 (*this)(1,0) * v[0] + (*this)(1,1) * v[1] + (*this)(1,2) * v[2],
477 (*this)(2,0) * v[0] + (*this)(2,1) * v[1] + (*this)(2,2) * v[2]);
478 }

◆ operator*=()

Matrix3 & EMAN::Matrix3::operator*= ( double  s)
inline

Definition at line 467 of file vecmath.h.

467 {
468 for ( int i = 0; i < 9; i++ )
469 mat[i] *= s;
470 return *this;
471 }

References mat.

◆ operator+()

Matrix3 EMAN::Matrix3::operator+ ( const Matrix3 m) const
inline

Definition at line 460 of file vecmath.h.

460 {
461 Matrix3 matRet;
462 for ( int i = 0; i < 9; i++ )
463 matRet.mat[i] = mat[i] + m.mat[i];
464 return matRet;
465 }

References mat.

◆ operator=()

Matrix3 & EMAN::Matrix3::operator= ( const Matrix3 m)
inline

Definition at line 433 of file vecmath.h.

433 {
434 memcpy( &mat[0], &m.mat[0], sizeof(double) * 16 );
435 return *this;
436 }

References mat.

◆ operator==()

bool EMAN::Matrix3::operator== ( const Matrix3 m) const
inline

Definition at line 542 of file vecmath.h.

542 {
543 for ( int i = 0; i < 9; i++ )
544 if ( mat[i] != m.mat[i] )
545 return false;
546 return true;
547 }

References mat.

◆ print()

void EMAN::Matrix3::print ( ) const
inline

Definition at line 556 of file vecmath.h.

556 {
557 std::cout << "( " << (*this)(0,0) << ", " << (*this)(0,1) << ", " << (*this)(0,2) << "\n";
558 std::cout << " " << (*this)(1,0) << ", " << (*this)(1,1) << ", " << (*this)(1,2) << "\n";
559 std::cout << " " << (*this)(2,0) << ", " << (*this)(2,1) << ", " << (*this)(2,2) << ")\n";
560 }

◆ rotationXYZtoUVW()

static Matrix3 EMAN::Matrix3::rotationXYZtoUVW ( Vector3  u,
Vector3  v,
Vector3  w 
)
inlinestatic

Definition at line 505 of file vecmath.h.

505 {
506 return Matrix3(Vector3(u[0], v[0], w[0]),
507 Vector3(u[1], v[1], w[1]),
508 Vector3(u[2], v[2], w[2]));
509 }

References Matrix3().

◆ row()

Vector3 EMAN::Matrix3::row ( int  r) const
inline

Definition at line 444 of file vecmath.h.

444 {
445 return Vector3( mat[index(r,0)], mat[index(r,1)], mat[index(r,2)] );
446 }

References index(), and mat.

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

◆ transpose()

Matrix3 EMAN::Matrix3::transpose ( ) const
inline

Definition at line 452 of file vecmath.h.

452 {
453 Matrix3 matRet;
454 for ( int i = 0; i < 3; i++ )
455 for ( int j = 0; j < 3; j++ )
456 matRet(i,j) = (*this)(j,i);
457 return matRet;
458 }

Member Data Documentation

◆ mat

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

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