00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4MATRIX3_H
00018 #define WM4MATRIX3_H
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "Wm4FoundationLIB.h"
00055 #include "Wm4Vector3.h"
00056
00057 namespace Wm4
00058 {
00059
00060 template <class Real>
00061 class Matrix3
00062 {
00063 public:
00064
00065
00066 Matrix3 (bool bZero = true);
00067
00068
00069 Matrix3 (const Matrix3& rkM);
00070
00071
00072 Matrix3 (Real fM00, Real fM01, Real fM02,
00073 Real fM10, Real fM11, Real fM12,
00074 Real fM20, Real fM21, Real fM22);
00075
00076
00077
00078
00079
00080 Matrix3 (const Real afEntry[9], bool bRowMajor);
00081
00082
00083
00084
00085 Matrix3 (const Vector3<Real>& rkU, const Vector3<Real>& rkV,
00086 const Vector3<Real>& rkW, bool bColumns);
00087 Matrix3 (const Vector3<Real>* akV, bool bColumns);
00088
00089
00090 Matrix3 (Real fM00, Real fM11, Real fM22);
00091
00092
00093
00094 Matrix3 (const Vector3<Real>& rkAxis, Real fAngle);
00095
00096
00097 Matrix3 (const Vector3<Real>& rkU, const Vector3<Real>& rkV);
00098
00099
00100 Matrix3& MakeZero ();
00101 Matrix3& MakeIdentity ();
00102 Matrix3& MakeDiagonal (Real fM00, Real fM11, Real fM22);
00103 Matrix3& FromAxisAngle (const Vector3<Real>& rkAxis, Real fAngle);
00104 Matrix3& MakeTensorProduct (const Vector3<Real>& rkU,
00105 const Vector3<Real>& rkV);
00106
00107
00108 operator const Real* () const;
00109 operator Real* ();
00110 const Real* operator[] (int iRow) const;
00111 Real* operator[] (int iRow);
00112 Real operator() (int iRow, int iCol) const;
00113 Real& operator() (int iRow, int iCol);
00114 void SetRow (int iRow, const Vector3<Real>& rkV);
00115 Vector3<Real> GetRow (int iRow) const;
00116 void SetColumn (int iCol, const Vector3<Real>& rkV);
00117 Vector3<Real> GetColumn (int iCol) const;
00118 void GetColumnMajor (Real* afCMajor) const;
00119
00120
00121 Matrix3& operator= (const Matrix3& rkM);
00122
00123
00124 bool operator== (const Matrix3& rkM) const;
00125 bool operator!= (const Matrix3& rkM) const;
00126 bool operator< (const Matrix3& rkM) const;
00127 bool operator<= (const Matrix3& rkM) const;
00128 bool operator> (const Matrix3& rkM) const;
00129 bool operator>= (const Matrix3& rkM) const;
00130
00131
00132 Matrix3 operator+ (const Matrix3& rkM) const;
00133 Matrix3 operator- (const Matrix3& rkM) const;
00134 Matrix3 operator* (const Matrix3& rkM) const;
00135 Matrix3 operator* (Real fScalar) const;
00136 Matrix3 operator/ (Real fScalar) const;
00137 Matrix3 operator- () const;
00138
00139
00140 Matrix3& operator+= (const Matrix3& rkM);
00141 Matrix3& operator-= (const Matrix3& rkM);
00142 Matrix3& operator*= (Real fScalar);
00143 Matrix3& operator/= (Real fScalar);
00144
00145
00146 Vector3<Real> operator* (const Vector3<Real>& rkV) const;
00147
00148
00149 Matrix3 Transpose () const;
00150 Matrix3 TransposeTimes (const Matrix3& rkM) const;
00151 Matrix3 TimesTranspose (const Matrix3& rkM) const;
00152 Matrix3 Inverse () const;
00153 Matrix3 Adjoint () const;
00154 Real Determinant () const;
00155 Real QForm (const Vector3<Real>& rkU,
00156 const Vector3<Real>& rkV) const;
00157 Matrix3 TimesDiagonal (const Vector3<Real>& rkDiag) const;
00158 Matrix3 DiagonalTimes (const Vector3<Real>& rkDiag) const;
00159
00160
00161
00162
00163
00164 void ToAxisAngle (Vector3<Real>& rkAxis, Real& rfAngle) const;
00165 void Orthonormalize ();
00166
00167
00168
00169
00170
00171
00172 void EigenDecomposition (Matrix3& rkRot, Matrix3& rkDiag) const;
00173
00174
00175 Matrix3& FromEulerAnglesXYZ (Real fXAngle, Real fYAngle, Real fZAngle);
00176 Matrix3& FromEulerAnglesXZY (Real fXAngle, Real fZAngle, Real fYAngle);
00177 Matrix3& FromEulerAnglesYXZ (Real fYAngle, Real fXAngle, Real fZAngle);
00178 Matrix3& FromEulerAnglesYZX (Real fYAngle, Real fZAngle, Real fXAngle);
00179 Matrix3& FromEulerAnglesZXY (Real fZAngle, Real fXAngle, Real fYAngle);
00180 Matrix3& FromEulerAnglesZYX (Real fZAngle, Real fYAngle, Real fXAngle);
00181
00182
00183
00184
00185
00186
00187
00188
00189 bool ToEulerAnglesXYZ (Real& rfXAngle, Real& rfYAngle, Real& rfZAngle)
00190 const;
00191 bool ToEulerAnglesXZY (Real& rfXAngle, Real& rfZAngle, Real& rfYAngle)
00192 const;
00193 bool ToEulerAnglesYXZ (Real& rfYAngle, Real& rfXAngle, Real& rfZAngle)
00194 const;
00195 bool ToEulerAnglesYZX (Real& rfYAngle, Real& rfZAngle, Real& rfXAngle)
00196 const;
00197 bool ToEulerAnglesZXY (Real& rfZAngle, Real& rfXAngle, Real& rfYAngle)
00198 const;
00199 bool ToEulerAnglesZYX (Real& rfZAngle, Real& rfYAngle, Real& rfXAngle)
00200 const;
00201
00202
00203
00204
00205
00206 Matrix3& Slerp (Real fT, const Matrix3& rkR0, const Matrix3& rkR1);
00207
00208
00209
00210 void SingularValueDecomposition (Matrix3& rkL, Matrix3& rkS,
00211 Matrix3& rkR) const;
00212 void SingularValueComposition (const Matrix3& rkL, const Matrix3& rkS,
00213 const Matrix3& rkR);
00214
00215
00216 void QDUDecomposition (Matrix3& rkQ, Matrix3& rkD, Matrix3& rkU) const;
00217
00218
00219 WM4_FOUNDATION_ITEM static const Matrix3 ZERO;
00220 WM4_FOUNDATION_ITEM static const Matrix3 IDENTITY;
00221
00222 private:
00223
00224
00225
00226
00227
00228
00229 bool Tridiagonalize (Real afDiag[3], Real afSubd[2]);
00230 bool QLAlgorithm (Real afDiag[3], Real afSubd[2]);
00231
00232
00233 static void Bidiagonalize (Matrix3& rkA, Matrix3& rkL, Matrix3& rkR);
00234 static void GolubKahanStep (Matrix3& rkA, Matrix3& rkL, Matrix3& rkR);
00235
00236
00237 int CompareArrays (const Matrix3& rkM) const;
00238
00239 Real m_afEntry[9];
00240 };
00241
00242
00243 template <class Real>
00244 Matrix3<Real> operator* (Real fScalar, const Matrix3<Real>& rkM);
00245
00246
00247 template <class Real>
00248 Vector3<Real> operator* (const Vector3<Real>& rkV, const Matrix3<Real>& rkM);
00249
00250 }
00251
00252 #include "Wm4Matrix3.inl"
00253
00254 namespace Wm4
00255 {
00256 typedef Matrix3<float> Matrix3f;
00257 typedef Matrix3<double> Matrix3d;
00258 }
00259
00260 #endif