Matrix3

Defines a 3x3 matrix with a load of constructors, operators, and methods.

[ GAMB | Source | Keywords | Summary | Ancestors | All Members | Descendants ]

Quick Index

AUTHORS
CHANGES LOG
GOALS
USAGE

Class Summary

class Matrix3
{
public:
// define real type
typedef Vector3::real real;
// Constructors
Matrix3() ;
explicit Matrix3(const real& d);
Matrix3(const real& xr, const real& yr, const real& zr);
Matrix3(const real& psi, const real& theta, const real& phi, const int& zxz);
Matrix3(const real a11, const real a12, const real a13, const real a21, const real a22, const real a23, const real a31, const real a32, const real a33);
explicit Matrix3(const real trn[9]);
explicit Matrix3(const double trn[9]);
explicit Matrix3(const real trn[3][3]);
explicit Matrix3(const double trn[3][3]);
Matrix3(const Vector3& v1, const Vector3& v2, const Vector3& v3) ;
explicit Matrix3(const Vector3& diag);
Matrix3(const Vector3& v1, const Vector3& v2);
// Inspection methods and properties.
const Vector3& operator[](const unsigned short r) const ;
Vector3 row(const unsigned short r) const ;
Vector3 column(const unsigned short col) const ;
Vector3 eigenvalues() const;
real element(const unsigned short r, const unsigned short col) const ;
real rotX() const ;
real rotY() const ;
real rotZ() const ;
Vector3 rot() const ;
Vector3 rotZXZ() const ;
real determinant() const;
real trace() const ;
Matrix3 adjoint() const;
// Operators
void transpose()
Matrix3 transposeMatrix() const ;
Matrix3& operator+=(const Matrix3&);
Matrix3& operator-=(const Matrix3&);
friend Matrix3 operator+(const Matrix3& t1, const Matrix3& t2) ;
friend Matrix3 operator-(const Matrix3& t1, const Matrix3& t2) ;
Matrix3& operator*=(const Matrix3 &);
friend Matrix3 operator*(const Matrix3& t1, const Matrix3& t2) ;
Matrix3& operator*=(const real &m);
Matrix3& operator/=(const real& m);
friend Matrix3 operator*(const Matrix3& t, const real& m) ;
friend Matrix3 operator!(const Matrix3&);
friend Vector3 operator*(const Matrix3& t, const Vector3& v) ;
friend ostream& operator<<(ostream& s, const Matrix3& t) ;
protected:
}; // Matrix3

Back to the top of Matrix3


AUTHORS

Meir Fuchs. (meirfux@math.tau.ac.il)

Copyright: SAMBA group, Tel-Aviv Univ. Israel, 1997.

Back to the top of Matrix3


CHANGES LOG

Back to the top of Matrix3


GOALS

Matrix3 was written in order to define a 3x3 matrix. The class was written so that vector-matrix operations in 3D will be performed with highest efficiency. The Matrix3 class can be implemented without any loops since the dimension is small and known.

Back to the top of Matrix3


USAGE

Matrix3 hosts a set of constructors, operators and inspection methods. Below are just several examples of how one may use the class.

    Matrix3 A(Vector3(1, 2, 3),   // construct matric out of 3 vector3
              Vector3(1, 0, 1),
	      Vector3(4, 5, 6));
    Matrix3 B=A;
    B.transpose();
    C=A+B;                        // + operator. C is symmetric.
    Vector3 v = C.eigenvalues();  // eigenvalues.
    Vector3 u = C*v;              // multiplication by vector.
    Matrix3 D(v);                 // D has v in the diagonal. 0's elsewhere.
    Matrix3 E(v,u);               // E=v*u'
A special note should be made regarding the rotational matrix constructors and methods. No special rotational matrix class was defined for reasons of conciseness and efficiency. Matrix3 hosts constructors for rotational matrices and inspectors for inspecting angular parameters. These inspection methods are probably meaningless when invoked on non-rotational matrices, but will not cause run-time errors and their likes.

    Matrix3 A(pi, pi, pi);   // rotational parameters for x-y-z. We get I.
    Matrix3 B(0,  0,  0 );   // again we get I.
    if (A.rotX() == 0) cout << "ok\n";

Back to the top of Matrix3


typedef Vector3::real real;

real is defined using the real defined in Vector3 class. By default this is of type float. For example , changing Vector3::real's defintion to double will turn the gamb library's vector operations to double precision.

  typedef Vector3::real real;

Back to the top of Matrix3


Matrix3() ;

Default constructor: 0 matrix.

  Matrix3()                                                          
;

Function is currently defined inline.


Back to the top of Matrix3


explicit Matrix3(const real& d);

Constructs a Matrix3 with d's in the diagonal and 0's else where.

  explicit Matrix3(const real& d);

Back to the top of Matrix3


Matrix3(const real& xr, const real& yr, const real& zr);

Creates a rotational Matrix3. given rotational values around the x axis (xr), around the y axis (yr) and around the z axis (zr) a linear transformation that rotates space in the order x-y-z is created. Rotation in this order is the default representation for the gamb++ library rotational transformations.

  Matrix3(const real& xr, const real& yr, const real& zr);

Back to the top of Matrix3


Matrix3(const real& psi, const real& theta, const real& phi, const int& zxz);

Creates a rotational Matrix3. given rotational values around the z axis (psi), around the x axis (theta) and around the z axis (phi), a linear transformation that rotates space in the order z-x-z is created. Rotation in this order is NOT the default representation for the gamb++ library rotational transformations. The int zxz specifies that the rotation order is ZXZ and not default XYZ.

  Matrix3(const real& psi, const real& theta, const real& phi, const int& zxz);

Back to the top of Matrix3


Matrix3(const real a11, const real a12, const real a13, const real a21, const real a22, const real a23, const real a31, const real a32, const real a33);

Initializes a Matrix3 object by stating all the matrix elements explicitly

  Matrix3(const real a11, const real a12, const real a13,
          const real a21, const real a22, const real a23,
          const real a31, const real a32, const real a33);

Back to the top of Matrix3


explicit Matrix3(const real trn[9]);

Creates a Matrix3 out of a real type array with first 3 elements for the 1st row, 2nd 3 elements for second row and last 3 elements for the 3rd row.

  explicit Matrix3(const real trn[9]);

Back to the top of Matrix3


explicit Matrix3(const double trn[9]);

Creates a Matrix3 out of a double type array with first 3 elements for the 1st row, 2nd 3 elements for second row and last 3 elements for the 3rd row.

  explicit Matrix3(const double trn[9]);

Back to the top of Matrix3


explicit Matrix3(const real trn[3][3]);

Use a 3x3 real 2D array to initialize matrix.

  explicit Matrix3(const real trn[3][3]);

Back to the top of Matrix3


explicit Matrix3(const double trn[3][3]);

Use a 3x3 double 2D array to initialize matrix.

  explicit Matrix3(const double trn[3][3]);

Back to the top of Matrix3


Matrix3(const Vector3& v1, const Vector3& v2, const Vector3& v3) ;

Constructs a Matrix3 using the 3 given row vectors. For construction with column vectors use this constructor and then the transpose method.

  Matrix3(const Vector3& v1, const Vector3& v2, const Vector3& v3)                                                                                       
;

Function is currently defined inline.


Back to the top of Matrix3


explicit Matrix3(const Vector3& diag);

Constructs a Matrix3 with Vector3 diag's values in the matrix diagonal and 0's elsewhere.

  explicit Matrix3(const Vector3& diag);

Back to the top of Matrix3


Matrix3(const Vector3& v1, const Vector3& v2);

Creates the matrix v1*v2' from the two given Vector3s

  Matrix3(const Vector3& v1, const Vector3& v2);

Back to the top of Matrix3


const Vector3& operator[](const unsigned short r) const ;

Returns the requested row of the matrix. r must be within 0..2. If not run-time errors may be caused. Notice that a const reference is returned so that this method will perform better than the row method and should be used when const rows are good enough.

  const Vector3& operator[](const unsigned short r) const                          
;

Function is currently defined inline.


Back to the top of Matrix3


Vector3 row(const unsigned short r) const ;

Returns a vector matching the r'th row of the matrix. r must be in the range 1..3 or run time errors may occur.

  Vector3 row(const unsigned short r) const                                     
;

Function is currently defined inline.


Back to the top of Matrix3


Vector3 column(const unsigned short col) const ;

Returns a vector matching the col'th column of the matrix. col must be in the range of 1..3 or run time errors may occur.

  Vector3 column(const unsigned short col) const                                                                          
;

Function is currently defined inline.


Back to the top of Matrix3


Vector3 eigenvalues() const;

Returns a Vector3 with eigenvalues of Matrix3. If eigenvalues are not real (i.e. complex) the function will return the 0 Vector3. So if the Matrix3 is not a 0-matrix and the function returned a 0-vector the Matrix's eigenvalues are not real.

  Vector3 eigenvalues() const;

Back to the top of Matrix3


real element(const unsigned short r, const unsigned short col) const ;

Returns the numerical value at position row, col in the 3X3 matrix row, col should be within the range of 1..3 or run time errors may occur.

  real element(const unsigned short r, const unsigned short col) const                                   
;

Function is currently defined inline.


Back to the top of Matrix3


real rotX() const ;

Returns the rotation around the x-axis for a rotational matrix assuming rotations are performed in the order of x-y-z. Note that results are meaningless if Matrix3 is not a rotational matrix.

  real rotX() const                                                    
;

Function is currently defined inline.


Back to the top of Matrix3


real rotY() const ;

Returns the rotation around the y-axis for a rotational matrix assuming rotations are performed in the order of x-y-z. Note that results are meaningless if Matrix3 is not a rotational matrix.

  real rotY() const                                                                                 
;

Function is currently defined inline.


Back to the top of Matrix3


real rotZ() const ;

Returns the rotation around the z-axis for a rotational matrix assuming rotations are performed in the order of x-y-z. Note that results are meaningless if Matrix3 is not a rotational matrix.

  real rotZ() const                                                    
;

Function is currently defined inline.


Back to the top of Matrix3


Vector3 rot() const ;

Returns 3 rotation angles assuming rotations are performed in the order of x-y-z. Note that results are meaningless if Matrix3 is not a rotational matrix.

  Vector3 rot() const                                                  
;

Function is currently defined inline.


Back to the top of Matrix3


Vector3 rotZXZ() const ;

Returns 3 rotation angles assuming rotations are performed in the order of z-x-z. Note that results are meaningless if Matrix3 is not a rotational matrix.

  Vector3 rotZXZ() const                                                                                                                                                                                                                                 
;

Function is currently defined inline.


Back to the top of Matrix3


real determinant() const;

Returns the determinant of the matrix

  real determinant() const;

Back to the top of Matrix3


real trace() const ;

Returns the trace of the matrix

  real trace() const                                                             
;

Function is currently defined inline.


Back to the top of Matrix3


Matrix3 adjoint() const;

Returns the adjoint matrix.

  Matrix3 adjoint() const;

Back to the top of Matrix3


void transpose()

Transposes the given matrix.

  void  transpose()                                   

Back to the top of Matrix3


Matrix3 transposeMatrix() const ;

Returns the matrix transpose.

  Matrix3 transposeMatrix() const                                                                                                                                                                          
;

Function is currently defined inline.


Back to the top of Matrix3


Matrix3& operator+=(const Matrix3&);

In place addition of given matrice's members.

  Matrix3& operator+=(const Matrix3&);

Back to the top of Matrix3


Matrix3& operator-=(const Matrix3&);

In-place subtraction of give matrice's members.

  Matrix3& operator-=(const Matrix3&);

Back to the top of Matrix3


friend Matrix3 operator+(const Matrix3& t1, const Matrix3& t2) ;

Addition of two matrices.

  friend Matrix3 operator+(const Matrix3& t1, const Matrix3& t2)                                                                                                    
;

Function is currently defined inline.


Back to the top of Matrix3


friend Matrix3 operator-(const Matrix3& t1, const Matrix3& t2) ;

Substraction of two matrices

  friend Matrix3 operator-(const Matrix3& t1, const Matrix3& t2)                                                                                                    
;

Function is currently defined inline.


Back to the top of Matrix3


Matrix3& operator*=(const Matrix3 &);

In place multiplication with given matrix.

  Matrix3& operator*=(const Matrix3 &);

Back to the top of Matrix3


friend Matrix3 operator*(const Matrix3& t1, const Matrix3& t2) ;

Matrix multiplication of two matrices.

  friend Matrix3 operator*(const Matrix3& t1, const Matrix3& t2)                                                                                                                                                                                                                                                                                                               
;

Function is currently defined inline.


Back to the top of Matrix3


Matrix3& operator*=(const real &m);

In-place matrix mutiplication by real scalar.

  Matrix3& operator*=(const real &m);

Back to the top of Matrix3


Matrix3& operator/=(const real& m);

In-place matrix division by real scalar.

  Matrix3& operator/=(const real& m);

Back to the top of Matrix3


friend Matrix3 operator*(const Matrix3& t, const real& m) ;

Matrix mutiplication by real scalar.

  friend Matrix3 operator*(const Matrix3& t, const real& m)                                                                 
;

Function is currently defined inline.


Back to the top of Matrix3


friend Matrix3 operator!(const Matrix3&);

Matrix inverse. If matrix inverse is un-defined a 0-matrix is returned

  friend Matrix3 operator!(const Matrix3&);

Back to the top of Matrix3


friend Vector3 operator*(const Matrix3& t, const Vector3& v) ;

Matrix by vector multiplication.

  friend Vector3 operator*(const Matrix3& t, const Vector3& v)                                                                 
;

Function is currently defined inline.


Back to the top of Matrix3


friend ostream& operator<<(ostream& s, const Matrix3& t) ;

Default Matrix output. 3 row vectors are output using Vector3's << operator with new-lines between rows.

  friend ostream& operator<<(ostream& s, const Matrix3& t)                                                                                     
;

Function is currently defined inline.


Back to the top of Matrix3


All Members

public:
// define real type
typedef Vector3::real real;
// Constructors
explicit Matrix3(const real& d);
explicit Matrix3(const real trn[9]);
explicit Matrix3(const double trn[9]);
explicit Matrix3(const real trn[3][3]);
explicit Matrix3(const double trn[3][3]);
explicit Matrix3(const Vector3& diag);
// Inspection methods and properties.
const Vector3& operator[](const unsigned short r) const ;
Vector3 row(const unsigned short r) const ;
Vector3 column(const unsigned short col) const ;
Vector3 eigenvalues() const;
real element(const unsigned short r, const unsigned short col) const ;
real rotX() const ;
real rotY() const ;
real rotZ() const ;
Vector3 rot() const ;
Vector3 rotZXZ() const ;
real determinant() const;
real trace() const ;
Matrix3 adjoint() const;
// Operators
void transpose()
Matrix3 transposeMatrix() const ;
Matrix3& operator+=(const Matrix3&);
Matrix3& operator-=(const Matrix3&);
friend Matrix3 operator+(const Matrix3& t1, const Matrix3& t2) ;
friend Matrix3 operator-(const Matrix3& t1, const Matrix3& t2) ;
Matrix3& operator*=(const Matrix3 &);
friend Matrix3 operator*(const Matrix3& t1, const Matrix3& t2) ;
Matrix3& operator*=(const real &m);
Matrix3& operator/=(const real& m);
friend Matrix3 operator*(const Matrix3& t, const real& m) ;
friend Matrix3 operator!(const Matrix3&);
friend Vector3 operator*(const Matrix3& t, const Vector3& v) ;
friend ostream& operator<<(ostream& s, const Matrix3& t) ;
protected:

Back to the top of Matrix3


Ancestors

Class does not inherit from any other class.

Back to the top of Matrix3


Descendants

Class is not inherited by any others.

Back to the top of Matrix3


Generated from source by the Cocoon utilities on Sun Nov 15 13:35:25 2009 .

Report problems to jkotula@unimax.com