# SIBCMatrix33d.h

    00001 //***************************************************************************************
    00002 //
    00003 // File supervisor: Crosswalk team
    00004 //
    00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.
    00006 // Use of this software is subject to the terms of the Autodesk license agreement
    00007 // provided at the time of installation or download, or which otherwise accompanies
    00008 // this software in either electronic or hard copy form.
    00009 //
    00010 //***************************************************************************************
    00011
    00012 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
    00013 #pragma once
    00014 #endif
    00015
    00016 //******************************************************************************
    00017 //
    00018 // Defines
    00019 //
    00020 //******************************************************************************
    00021 #ifndef _MATRIX33_H_
    00022 #define _MATRIX33_H_
    00023
    00024 //******************************************************************************
    00025 //
    00026 // Includes
    00027 //
    00028 //******************************************************************************
    00029 #include "SIBCMathLib.h"
    00030
    00031 //******************************************************************************
    00032 //
    00033 // CSIBCMatrix33d | General 3X3 matrix.
    00034 //
    00035 //******************************************************************************
    00036
    00038
    00050 class XSICOREEXPORT CSIBCMatrix33d
    00051 {
    00052     // Public members
    00053     public:
    00054
    00055         //****************************************
    00056         // Constructors/destructor:
    00057         //****************************************
    00058
    00063         CSIBCMatrix33d( void );
    00064
    00075         CSIBCMatrix33d(
    00076             const CSIBCVector3Dd& in_vct0,
    00077             const CSIBCVector3Dd& in_vct1,
    00078             const CSIBCVector3Dd& in_vct2,
    00079             const bool in_bAreRows = true );
    00080
    00093         CSIBCMatrix33d(
    00094             const double in_dA00, const double in_dA01, const double in_dA02,
    00095             const double in_dA10, const double in_dA11, const double in_dA12,
    00096             const double in_dA20, const double in_dA21, const double in_dA22 );
    00097
    00108         CSIBCMatrix33d( int in_nRow, int in_nCol, const CSIBCMatrix44d& in_mat );
    00109
    00110
    00111         // Destructor.
    00112         ~CSIBCMatrix33d();
    00113
    00114         //****************************************
    00115         // General access functions:
    00116         //****************************************
    00117
    00124         double Get( const int in_nRow, const int in_nCol ) const;
    00125
    00126         //****************************************
    00127         // Matrix element modification functions:
    00128         //****************************************
    00129
    00140         CSIBCMatrix33d& Set( int in_nRow, int in_nCol, const double in_dVal );
    00141
    00158         CSIBCMatrix33d& Set(
    00159             const double in_dA00, const double in_dA01, const double in_dA02,
    00160             const double in_dA10, const double in_dA11, const double in_dA12,
    00161             const double in_dA20, const double in_dA21, const double in_dA22 );
    00162
    00172         CSIBCMatrix33d& Set( double in_dVal[3][3] );
    00173
    00182         CSIBCMatrix33d& Set( const CSIBCMatrix33d& in_mat );
    00183
    00195         CSIBCMatrix33d& Set( int in_nRow, int in_nCol, const CSIBCMatrix44d& in_mat );
    00196
    00206         CSIBCMatrix33d& SetRow( const int in_nRow, const CSIBCVector3Dd& in_vct );
    00207
    00218         CSIBCMatrix33d& SetRow( const int in_nRow, double in_dA0, double in_dA1, double in_dA2 );
    00219
    00229         CSIBCMatrix33d& SetCol( const int in_nCol, const CSIBCVector3Dd& in_vct );
    00230
    00241         CSIBCMatrix33d& SetCol( const int in_nCol, double in_dA0, double in_dA1,    double in_dA2 );
    00242
    00248         CSIBCMatrix33d& SetNull();
    00249
    00255         CSIBCMatrix33d& SetIdentity();
    00256
    00257         //****************************************
    00258         // Matrix comparison functions:
    00259         //****************************************
    00260
    00271         friend bool AreAlmostEqual( const CSIBCMatrix33d& in_mat1,
    00272             const CSIBCMatrix33d& in_mat2, const double in_dEpsilon = PICO_EPS );
    00273
    00281         bool operator ==( const CSIBCMatrix33d& in_mat ) const;
    00282
    00290         bool operator !=( const CSIBCMatrix33d& in_mat ) const;
    00291
    00301         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
    00302
    00312         bool IsSingular( const double in_dEpsilon=PICO_EPS ) const;
    00313
    00322         bool IsSymmetric( const double in_dEpsilon=PICO_EPS ) const;
    00323
    00324         //****************************************
    00325         // Matrix algebra functions:
    00326         //****************************************
    00327
    00335         CSIBCMatrix33d& Add( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
    00336
    00343         CSIBCMatrix33d& Add( const CSIBCMatrix33d& in_mat );
    00344
    00352         CSIBCMatrix33d& Sub( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
    00353
    00361         CSIBCMatrix33d& Sub( const CSIBCMatrix33d& in_mat );
    00362
    00373         CSIBCMatrix33d& Mul( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
    00374
    00384         CSIBCMatrix33d& Mul( const CSIBCMatrix33d& in_mat );
    00385
    00396         CSIBCMatrix33d& MulTransByReg( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
    00397
    00408         CSIBCMatrix33d& MulRegByTrans( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
    00409
    00416         CSIBCMatrix33d& Negate( const CSIBCMatrix33d& in_mat );
    00417
    00423         CSIBCMatrix33d& Negate();
    00424
    00433         CSIBCMatrix33d& Mul( const double in_dFactor, const CSIBCMatrix33d& in_mat );
    00434
    00443         CSIBCMatrix33d& Mul( const CSIBCMatrix33d& in_mat, const double in_dFactor );
    00444
    00451         CSIBCMatrix33d& Mul( const double in_dFactor );
    00452
    00461         CSIBCMatrix33d& Div( const CSIBCMatrix33d& in_mat, const double in_dFactor );
    00462
    00469         CSIBCMatrix33d& Div( const double in_dFactor );
    00470
    00476         double GetDet( void ) const;
    00477
    00482         double GetTrace( void ) const;
    00483
    00491         CSIBCMatrix33d& Transpose( const CSIBCMatrix33d& in_mat );
    00492
    00498         CSIBCMatrix33d& Transpose( void );
    00499
    00507         bool Invert( const CSIBCMatrix33d& in_mat );
    00508
    00515         bool Invert( void );
    00516
    00525         bool TransposeInverse( const CSIBCMatrix33d& in_mat );
    00526
    00534         bool TransposeInverse( void );
    00535
    00541         CSIBCMatrix33d& Adjoint( const CSIBCMatrix33d& in_mat );
    00542
    00547         CSIBCMatrix33d& Adjoint( void );
    00548
    00556         bool GetEigenVectors( CSIBCMatrix33d& out_matEigenVectors, CSIBCVector3Dd& out_vctEigenValues, const double in_dEps=PICO_EPS ) const;
    00557
    00558         //****************************************
    00559         // Utility functions:
    00560         //****************************************
    00561
    00562         //****************************************
    00563         // To be implemented later:
    00564         //****************************************
    00565
    00566         // Set this matrix to the symmetrical of the input matrix.
    00568         CSIBCMatrix33d& Symmetry( CSIBCMatrix33d& in_mat ) const;
    00569
    00570         // Set this matrix to its symmetrical.
    00572         CSIBCMatrix33d& Symmetry( void ) const;
    00573
    00574         // Set this matrix to the product of V1^T and V2.
    00576         void SetOuterProduct( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
    00577
    00578     // Protected members
    00579     protected:
    00580
    00581         //****************************************
    00582         // Protected data
    00583         //****************************************
    00584         // double[3][3] | CSIBCMatrix33d | m_dMat | Matrix itself.
    00585         double m_dMat[3][3];
    00586
    00587         //****************************************
    00588         // Utility functions:
    00589         //****************************************
    00590
    00591         // Computes the inverse of a matrix.
    00592         bool ComputeInverse( const double in_dMat[3][3], double out_dInv[3][3],
    00593                 const bool in_bTransposeResult=false, const double in_dDetMin=PICO_EPS ) const;
    00594         // Computes the adjoint of a matrix.
    00595         void ComputeAdjoint( const double in_dMat[3][3], double out_dAdj[3][3] ) const;
    00596
    00597         // Computes the determinant of a matrix given its adjoint.
    00598         double ComputeDetFast( double in_dMat[3][3], double in_dAdj[3][3] ) const;
    00599
    00600         // Compute the determinant of a matrix and compute a measure of its scale (max. order of magnitude).
    00601         void ComputeDetAndDetSize( const double in_dMat[3][3],
    00602                 double &out_dDet, double &out_dDetSize ) const;
    00603         // Computes eigenvalues and eigenvectors of a symmetric matrix
    00604         bool ComputeEigen( const double in_dMat[3][3], double out_dMatEigenVectors[3][3], CSIBCVector3Dd &out_vctEigenValues,
    00605                 const double in_dEps=PICO_EPS ) const;
    00606 };
    00607
    00608
    00609 #endif
    00610