Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | Related Pages

MgcMatrix3.h

00001 // Magic Software, Inc.
00002 // http://www.magic-software.com
00003 // Copyright (c) 2000-2002.  All Rights Reserved
00004 //
00005 // Source code from Magic Software is supplied under the terms of a license
00006 // agreement and may not be copied or disclosed except in accordance with the
00007 // terms of that agreement.  The various license agreements may be found at
00008 // the Magic Software web site.  This file is subject to the license
00009 //
00010 // FREE SOURCE CODE
00011 // http://www.magic-software.com/License/free.pdf
00012 
00013 #ifndef MGCMATRIX3_H
00014 #define MGCMATRIX3_H
00015 
00016 #include "MgcVector3.h"
00017 
00018 namespace Mgc {
00019 
00020 // NOTE.  The (x,y,z) coordinate system is assumed to be right-handed.
00021 // Coordinate axis rotation matrices are of the form
00022 //   RX =    1       0       0
00023 //           0     cos(t) -sin(t)
00024 //           0     sin(t)  cos(t)
00025 // where t > 0 indicates a counterclockwise rotation in the yz-plane
00026 //   RY =  cos(t)    0     sin(t)
00027 //           0       1       0
00028 //        -sin(t)    0     cos(t)
00029 // where t > 0 indicates a counterclockwise rotation in the zx-plane
00030 //   RZ =  cos(t) -sin(t)    0
00031 //         sin(t)  cos(t)    0
00032 //           0       0       1
00033 // where t > 0 indicates a counterclockwise rotation in the xy-plane.
00034 
00035 
00036 class UTILITIES_API MAGICFM Matrix3
00037 {
00038 public:
00039     // construction
00040     Matrix3 ();
00041     Matrix3 (const Real aafEntry[3][3]);
00042     Matrix3 (const Matrix3& rkMatrix);
00043     Matrix3 (Real fEntry00, Real fEntry01, Real fEntry02,
00044              Real fEntry10, Real fEntry11, Real fEntry12,
00045              Real fEntry20, Real fEntry21, Real fEntry22);
00046 
00047     // member access, allows use of construct mat[r][c]
00048     Real* operator[] (int iRow) const;
00049     operator Real* ();
00050     Vector3 GetColumn (int iCol) const;
00051 
00052     // assignment and comparison
00053     Matrix3& operator= (const Matrix3& rkMatrix);
00054     bool operator== (const Matrix3& rkMatrix) const;
00055     bool operator!= (const Matrix3& rkMatrix) const;
00056 
00057     // arithmetic operations
00058     Matrix3 operator+ (const Matrix3& rkMatrix) const;
00059     Matrix3 operator- (const Matrix3& rkMatrix) const;
00060     Matrix3 operator* (const Matrix3& rkMatrix) const;
00061     Matrix3 operator- () const;
00062 
00063     // matrix * vector [3x3 * 3x1 = 3x1]
00064     Vector3 operator* (const Vector3& rkVector) const;
00065 
00066     // vector * matrix [1x3 * 3x3 = 1x3]
00067     MAGICFM friend Vector3 operator* (const Vector3& rkVector,
00068         const Matrix3& rkMatrix);
00069 
00070     // matrix * scalar
00071     Matrix3 operator* (Real fScalar) const;
00072 
00073     // scalar * matrix
00074     MAGICFM friend Matrix3 operator* (Real fScalar, const Matrix3& rkMatrix);
00075 
00076     // M0.TransposeTimes(M1) = M0^t*M1 where M0^t is the transpose of M0
00077     Matrix3 TransposeTimes (const Matrix3& rkM) const;
00078 
00079     // M0.TimesTranspose(M1) = M0*M1^t where M1^t is the transpose of M1
00080     Matrix3 TimesTranspose (const Matrix3& rkM) const;
00081 
00082     // utilities
00083     Matrix3 Transpose () const;
00084     bool Inverse (Matrix3& rkInverse, Real fTolerance = 1e-06f) const;
00085     Matrix3 Inverse (Real fTolerance = 1e-06f) const;
00086     Real Determinant () const;
00087 
00088     // SLERP (spherical linear interpolation) without quaternions.  Computes
00089     // R(t) = R0*(Transpose(R0)*R1)^t.  If Q is a rotation matrix with
00090     // unit-length axis U and angle A, then Q^t is a rotation matrix with
00091     // unit-length axis U and rotation angle t*A.
00092     static Matrix3 Slerp (Real fT, const Matrix3& rkR0, const Matrix3& rkR1);
00093 
00094     // singular value decomposition
00095     void SingularValueDecomposition (Matrix3& rkL, Vector3& rkS,
00096         Matrix3& rkR) const;
00097     void SingularValueComposition (const Matrix3& rkL,
00098         const Vector3& rkS, const Matrix3& rkR);
00099 
00100     // Gram-Schmidt orthonormalization (applied to columns of rotation matrix)
00101     void Orthonormalize ();
00102 
00103     // orthogonal Q, diagonal D, upper triangular U stored as (u01,u02,u12)
00104     void QDUDecomposition (Matrix3& rkQ, Vector3& rkD, Vector3& rkU) const;
00105 
00106     Real SpectralNorm () const;
00107 
00108     // matrix must be orthonormal
00109     void ToAxisAngle (Vector3& rkAxis, Real& rfRadians) const;
00110     void FromAxisAngle (const Vector3& rkAxis, Real fRadians);
00111 
00112     // The matrix must be orthonormal.  The decomposition is yaw*pitch*roll
00113     // where yaw is rotation about the Up vector, pitch is rotation about the
00114     // Right axis, and roll is rotation about the Direction axis.
00115     bool ToEulerAnglesXYZ (Real& rfYAngle, Real& rfPAngle,
00116         Real& rfRAngle) const;
00117     bool ToEulerAnglesXZY (Real& rfYAngle, Real& rfPAngle,
00118         Real& rfRAngle) const;
00119     bool ToEulerAnglesYXZ (Real& rfYAngle, Real& rfPAngle,
00120         Real& rfRAngle) const;
00121     bool ToEulerAnglesYZX (Real& rfYAngle, Real& rfPAngle,
00122         Real& rfRAngle) const;
00123     bool ToEulerAnglesZXY (Real& rfYAngle, Real& rfPAngle,
00124         Real& rfRAngle) const;
00125     bool ToEulerAnglesZYX (Real& rfYAngle, Real& rfPAngle,
00126         Real& rfRAngle) const;
00127     void FromEulerAnglesXYZ (Real fYAngle, Real fPAngle, Real fRAngle);
00128     void FromEulerAnglesXZY (Real fYAngle, Real fPAngle, Real fRAngle);
00129     void FromEulerAnglesYXZ (Real fYAngle, Real fPAngle, Real fRAngle);
00130     void FromEulerAnglesYZX (Real fYAngle, Real fPAngle, Real fRAngle);
00131     void FromEulerAnglesZXY (Real fYAngle, Real fPAngle, Real fRAngle);
00132     void FromEulerAnglesZYX (Real fYAngle, Real fPAngle, Real fRAngle);
00133 
00134     // eigensolver, matrix must be symmetric
00135     void EigenSolveSymmetric (Real afEigenvalue[3],
00136         Vector3 akEigenvector[3]) const;
00137 
00138     static void TensorProduct (const Vector3& rkU, const Vector3& rkV,
00139         Matrix3& rkProduct);
00140 
00141     static const Real EPSILON;
00142     static const Matrix3 ZERO;
00143     static const Matrix3 IDENTITY;
00144 
00145 protected:
00146     // support for eigensolver
00147     void Tridiagonal (Real afDiag[3], Real afSubDiag[3]);
00148     bool QLAlgorithm (Real afDiag[3], Real afSubDiag[3]);
00149 
00150     // support for singular value decomposition
00151     static const Real ms_fSvdEpsilon;
00152     static const int ms_iSvdMaxIterations;
00153     static void Bidiagonalize (Matrix3& kA, Matrix3& kL, Matrix3& kR);
00154     static void GolubKahanStep (Matrix3& kA, Matrix3& kL, Matrix3& kR);
00155 
00156     // support for spectral norm
00157     static Real MaxCubicRoot (Real afCoeff[3]);
00158 
00159     Real m_aafEntry[3][3];
00160 };
00161 
00162 #include "MgcMatrix3.inl"
00163 
00164 } // namespace Mgc
00165 
00166 #endif
00167 
00168 

Generated on Tue Sep 30 18:19:43 2003 for Pointshop3D by doxygen 1.3.3