⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgceigen.h

📁 3D Game Engine Design Source Code非常棒
💻 H
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf

#ifndef MGCEIGEN_H
#define MGCEIGEN_H

#include "MgcMath.h"


class MgcEigen
{
public:
    MgcEigen (int iSize);
    ~MgcEigen ();

    // set the matrix for eigensolving
    MgcReal& Matrix (int iRow, int iCol);
    void SetMatrix (MgcReal** aafMat);

    // get the results of eigensolving (eigenvectors are columns of matrix)
    MgcReal GetEigenvalue (int i) const;
    MgcReal GetEigenvector (int iRow, int iCol) const;
    MgcReal* GetEigenvalue ();
    MgcReal** GetEigenvector ();

    // solve eigensystem
    void EigenStuff2 ();
    void EigenStuff3 ();
    void EigenStuff4 ();
    void EigenStuffN ();
    void EigenStuff  ();

    // solve eigensystem, use decreasing sort on eigenvalues
    void DecrSortEigenStuff2 ();
    void DecrSortEigenStuff3 ();
    void DecrSortEigenStuff4 ();
    void DecrSortEigenStuffN ();
    void DecrSortEigenStuff  ();

    // solve eigensystem, use increasing sort on eigenvalues
    void IncrSortEigenStuff2 ();
    void IncrSortEigenStuff3 ();
    void IncrSortEigenStuff4 ();
    void IncrSortEigenStuffN ();
    void IncrSortEigenStuff  ();

protected:
    int m_iSize;
    MgcReal** m_aafMat;
    MgcReal* m_afDiag;
    MgcReal* m_afSubd;

    // Householder reduction to tridiagonal form
    static void Tridiagonal2 (MgcReal** aafMat, MgcReal* afDiag,
        MgcReal* afSubd);
    static void Tridiagonal3 (MgcReal** aafMat, MgcReal* afDiag,
        MgcReal* afSubd);
    static void Tridiagonal4 (MgcReal** aafMat, MgcReal* afDiag,
        MgcReal* afSubd);
    static void TridiagonalN (int iSize, MgcReal** aafMat, MgcReal* afDiag,
        MgcReal* afSubd);

    // QL algorithm with implicit shifting, applies to tridiagonal matrices
    static bool QLAlgorithm (int iSize, MgcReal* afDiag, MgcReal* afSubd,
        MgcReal** aafMat);

    // sort eigenvalues from largest to smallest
    static void DecreasingSort (int iSize, MgcReal* afEigval,
        MgcReal** aafEigvec);

    // sort eigenvalues from smallest to largest
    static void IncreasingSort (int iSize, MgcReal* afEigval,
        MgcReal** aafEigvec);
};

//---------------------------------------------------------------------------
inline MgcReal& MgcEigen::Matrix (int iRow, int iCol)
{
    return m_aafMat[iRow][iCol];
}
//---------------------------------------------------------------------------
inline MgcReal MgcEigen::GetEigenvalue (int i) const
{
    return m_afDiag[i];
}
//---------------------------------------------------------------------------
inline MgcReal MgcEigen::GetEigenvector (int iRow, int iCol) const
{
    return m_aafMat[iRow][iCol];
}
//---------------------------------------------------------------------------
inline MgcReal* MgcEigen::GetEigenvalue ()
{
    return m_afDiag;
}
//---------------------------------------------------------------------------
inline MgcReal** MgcEigen::GetEigenvector ()
{
    return m_aafMat;
}
//---------------------------------------------------------------------------

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -