TAPs 0.7.7.3
TAPsMatrix3x3.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsMatrix3x3.hpp
00003 
00004 Matrix3x3 class is a class for 3-by-3 matrices.
00005 
00006 SUKITTI PUNAK   (09/14/2004)
00007 UPDATE          (07/30/2005)
00008 ******************************************************************************/
00009 #ifndef TAPs_MATRIX3X3_H
00010 #define TAPs_MATRIX3X3_H
00011 
00012 #include "TAPsMath.hpp"
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 // class forward
00017 template <typename T> class Vector3;
00018 //=============================================================================
00019 template <typename T>
00020 class Matrix3x3 {
00021 //=============================================================================
00022 private:
00023     // Matrix Elements
00024     //       --                --
00025     //      |  e[0]  e[1]  e[2]  |
00026     //      |  e[3]  e[4]  e[5]  |
00027     //      |  e[6]  e[7]  e[8]  |
00028     //       --                --
00029     T e[9];
00030     //-------------------------------------------------------------------------
00031     // Static Data Members for Data Conversions
00032     static float        g_f[9];
00033     static double       g_d[9];
00034     static long double  g_ld[9];
00035     //-------------------------------------------------------------------------
00036 public:
00037     //-------------------------------------------------------------------------
00038     // Output Operator <<
00039     friend std::ostream & operator<< ( std::ostream &output, Matrix3x3<T> const &M )
00040     {
00041         int width = 14;
00042         //output << typeid(*this).name() << "( ";
00043         output  << "Matrix3x3<" << typeid(T).name() << "> =\n"
00044                 << "| " << std::setw(width) << M.e[0] 
00045                         << std::setw(width) << M.e[1] 
00046                         << std::setw(width) << M.e[2] << " |\n"
00047                 << "| " << std::setw(width) << M.e[3] 
00048                         << std::setw(width) << M.e[4] 
00049                         << std::setw(width) << M.e[5] << " |\n"
00050                 << "| " << std::setw(width) << M.e[6] 
00051                         << std::setw(width) << M.e[7] 
00052                         << std::setw(width) << M.e[8] << " |\n";
00053         //output << std::endl;
00054         return output;
00055     }
00056     //-------------------------------------------------------------------------
00057     // Constructors and Destructor
00058     Matrix3x3 ();       // default constructor (Identity Matrix)
00059     Matrix3x3 ( Matrix3x3<T> const &M );        // copy constructor
00060     Matrix3x3 ( T );                            // constructor
00061     Matrix3x3 ( T, T, T, T, T, T, T, T, T );    // constructor
00062     Matrix3x3 ( T const af[9] );                // constructor from array
00063     ~Matrix3x3 ();                              // destructor
00064     //-------------------------------------------------------------------------
00065     // Member Access
00066     inline T &       operator[] ( int i );
00067     inline T const & operator[] ( int i ) const;
00068     inline T &       operator() ( int r, int c );
00069     inline T const & operator() ( int r, int c ) const;
00070     //-------------------------------------------------------------------------
00071     // Convert to one dimension array
00072     operator const T *() const;
00073     operator T *();
00074     //-------------------------------------------------------------------------
00075     // Useful Functions
00076     inline void SetAllElements ( T );                           // set all elements
00077     inline void SetAllElements ( T, T, T, T, T, T, T, T, T );   // set all elements
00078     inline void SetAllElements ( T const af[9] );               // set all elements
00079     inline void MakeIdentity ();                    // set to identity matrix
00080     inline void MakeDiagonal ( T d );               // set to diagonal matrix
00081     inline void MakeDiagonal ( T const af[3] );     // set to diagonal matrix
00082     inline void MakeZero ();                        // set all elements to zero
00083     inline bool IsIdentity () const;                // Is it an identity matrix?
00084     inline bool IsSymmetric () const                // Is it a symmetric matrix?
00085         { return e[1]==e[3] && e[2]==e[6] && e[5]==e[7]; }
00086     inline bool IsSquare () const                   // Is it a square matrix?
00087         { return true;}
00088     //-------------------------------------------------------------------------
00089     // Matrix Operations
00090     inline Matrix3x3<T> & Transposed ();
00091     inline Matrix3x3<T>   GetTranspose () const;
00092     inline Matrix3x3<T> & Inversed ();
00093     Matrix3x3<T>   GetInverse () const;
00094     inline T GetDeterminant () const;
00095     //-------------------------------------------------------------------------
00096     // Assignment Overloaded Operator
00097     Matrix3x3<T> & operator= ( Matrix3x3<T> const &M );
00098     //-------------------------------------------------------------------------
00099     // Unary Overloaded Operators
00100     Matrix3x3<T> operator- ();  // negation
00101     //-------------------------------------------------------------------------
00102     // Assign Overloaded Operators
00103     Matrix3x3<T> &operator+= ( Matrix3x3<T> const &M ); // += with matrix
00104     Matrix3x3<T> &operator-= ( Matrix3x3<T> const &M ); // -= with matrix
00105     Matrix3x3<T> &operator*= ( Matrix3x3<T> const &M ); // *= with matrix
00106     Matrix3x3<T> &operator*= ( T s );                   // *= with scalar
00107     Matrix3x3<T> &operator/= ( T s );                   // /= with scalar
00108     //-------------------------------------------------------------------------
00109     // Binary Overloaded Operators
00110     Matrix3x3<T> operator+ ( Matrix3x3<T> const &M ) const; // matrix + matrix
00111     Matrix3x3<T> operator- ( Matrix3x3<T> const &M ) const; // matrix - matrix
00112     Matrix3x3<T> operator* ( Matrix3x3<T> const &M ) const; // matrix * matrix
00113     Matrix3x3<T> operator* ( T s ) const;                   // matrix * scalar
00114     friend inline Matrix3x3<T> operator* ( T s, Matrix3x3<T> const &M ) // scalar * matrix
00115     {   return M * s;   }
00116     Matrix3x3<T> operator/ ( T s ) const;                   // matrix / scalar
00117     inline void MultLeft ( Matrix3x3<T> const &M );     // this matrix = matrix M * this matrix
00118     inline void MultRight ( Matrix3x3<T> const &M );    // this matrix = this matrix * matrix M
00119     //-------------------------------------------------------------------------
00120     // Matrix * Vector
00121     Vector3<T> operator* ( Vector3<T> const &V ) const;
00122     //-------------------------------------------------------------------------
00123     // Static Member Functions for Data Conversions
00124     const float *       GetDataFloat () const;
00125     const double *      GetDataDouble () const;
00126     const long double * GetDataLongDouble () const;
00127     const float *       GetTransposeDataFloat () const;
00128     const double *      GetTransposeDataDouble () const;
00129     const long double * GetTransposeDataLongDouble () const;
00130     //-------------------------------------------------------------------------
00131 }; // END CLASS Matrix3x3
00132 //=============================================================================
00133 //-----------------------------------------------------------------------------
00134 // Define Matrix3x3s
00135 typedef Matrix3x3<int>          Matrix3x3i;
00136 typedef Matrix3x3<float>        Matrix3x3f;
00137 typedef Matrix3x3<double>       Matrix3x3d;
00138 typedef Matrix3x3<long double>  Matrix3x3ld;
00139 //=============================================================================
00140 END_NAMESPACE_TAPs
00141 //-----------------------------------------------------------------------------
00142 // Include definition if TAPs_USE_EXPORT is not defined
00143 //#if !defined( TAPs_USE_EXPORT )
00144     #include "TAPsMatrix3x3.cpp"
00145 //#endif
00146 //-----------------------------------------------------------------------------
00147 #endif
00148 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00149 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines