www.pudn.com > ZFXMath-latest.zip > MatrixMxN.inl


// Datei:         TMatrixMxN.inl
// ///////////////////////////////////////////////////////////////////////////
// Autor:         Patrick Ullmann
// Erstellt:      05.04.04
// Änderungen:    05.04.04 (Patrick)  Datei erstellt
// ///////////////////////////////////////////////////////////////////////////
// Beschreibung:  Struktur für eine Matrix mit frei belegbaren Spalten 
//                und Zeilenanzahl (Inline-File)

#ifndef _TMATRIXMXN_INL__25_07_2004_
#define _TMATRIXMXN_INL__25_07_2004_

// I N C L U D E S ///////////////////////////////////////////////////////////
#include 

// F U N K T I O N E N ///////////////////////////////////////////////////////
namespace ZFXMath
{
// ///////////////////////////////////////////////////////////////////////////
// PUBLIC Constructor
//
// Default Constructor
// ///////////////////////////////////////////////////////////////////////////
template inline TMatrixMxN::TMatrixMxN (void)
{	
    identity ();
}

// ///////////////////////////////////////////////////////////////////////////
// PUBLIC Constructor
//
// Erstellt eine Matrix mit dem übergebenen Wert.
//
// [in] value: Wert womit alle Zeilen und Spalten gefüllt werden soll.
// ///////////////////////////////////////////////////////////////////////////
template inline TMatrixMxN::TMatrixMxN (const T& value)
{	
        // Druchlaufe alle Einträge und setze sie auf den jeweiligen Wert
    for (int i=0; i inline TMatrixMxN::TMatrixMxN (TMatrixMxN const &other)
{
    (*this) = other;
}

// ///////////////////////////////////////////////////////////////////////////
// PUBLIC Constructor
//
// Erstellt eine Matrix mit Werten eines Übergebenen 1D Array der größe M*N
//
// [in] value: Ein 1D Array der größe M*N
// ///////////////////////////////////////////////////////////////////////////
template inline TMatrixMxN::TMatrixMxN (const T (&value)[M*N])
{	
        // Druchlaufe alle Einträge und setze sie auf den jeweiligen Wert
    for (int i=0; i inline TMatrixMxN::~TMatrixMxN (void)
{
}


// ///////////////////////////////////////////////////////////////////////////
// M A T R I Z E N   -   F U N K T I O N E N #################################
// ///////////////////////////////////////////////////////////////////////////

// ///////////////////////////////////////////////////////////////////////////
// PUBLIC
//
// Erstellt eine Null-Matrix
// ///////////////////////////////////////////////////////////////////////////
template inline void TMatrixMxN::zero (void)
{
        // alles auf 0 setzen
    ::memset ((*this).matrix, 0, sizeof(T&)*M*N);
}

// ///////////////////////////////////////////////////////////////////////////
// PUBLIC
//
// Erstellt eine Null-Matrix
// ///////////////////////////////////////////////////////////////////////////
template inline void TMatrixMxN::identity (void)
{
        // alles auf 0 setzen
    ::memset ((*this).matrix, 0, sizeof(T&)*M*N);

        // Quadratisch?
    if (M == N)
    {
            // Hauptdiagonale auf 1 setzen
        for (int i=0; i N)	// Mehr Spalten als Zeilen
    {
        // Hauptdiagonale auf 1 setzen
        for (int i=0; i M)	// Mehr Zeilen als Spalten
    {
            // Hauptdiagonale auf 1 setzen
        for (int i=0; i inline TMatrixMxN TMatrixMxN::transpose(void) const
{
        // Achtung: Hier geben wir nicht die Grundform (M,N) zurück sondern die
        //          Entgegengesetzte Form (N,M)!!
    TMatrixMxN ret;
        
        // Druchlaufe alle Einträge und vertausche sie
    for (int i=0; i inline void TMatrixMxN::negate (void)
{        
        // Druchlaufe alle Einträge und rechne |*(-1)
    for (int i=0; i inline TMatrixMxN const &TMatrixMxN::operator= (TMatrixMxN const &other)
{
        // Matrix gleichsetzen
    ::memcpy ((*this).matrix, other.matrix, sizeof(T&)*M*N);

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator= (const T& value)
{
        // Druchlaufe alle Einträge und setze den wert 'value'
    for (int i=0; i inline TMatrixMxN const &TMatrixMxN::operator= (const T (&value)[M*N])
{
        // Druchlaufe alle Einträge und setze den wert 'value'
    for (int i=0; i inline bool TMatrixMxN::operator== (TMatrixMxN const &other)
{
        // Druchlaufe alle Einträge und teste sie zueinander
    for (int i=0; i inline bool TMatrixMxN::operator== (const T& value)
{
        // Druchlaufe alle Einträge und teste sie zueinander
    for (int i=0; i inline bool TMatrixMxN::operator== (const T (&value)[M*N])
{
        // Druchlaufe alle Einträge und teste sie zueinander
    for (int i=0; i inline bool TMatrixMxN::operator!= (TMatrixMxN const &other)
{
    return (!((*this) == other));
}

template inline bool TMatrixMxN::operator!= (const T& value)
{
    return (!((*this) == TMatrixMxN(value)));
}

template inline bool TMatrixMxN::operator!= (const T (&value)[M*N])
{
    return (!((*this) == TMatrixMxN(value)));
}


	// #######################################################################
	// A D D I T I O N S  -  O P E R A T O R E N
	// #######################################################################
template inline TMatrixMxN TMatrixMxN::operator+ (TMatrixMxN const &other) const
{
    TMatrixMxN ret;
            
        // Druchlaufe alle Einträge und addiere
    for (int i=0; i inline TMatrixMxN TMatrixMxN::operator+ (const T& value) const
{
    return ((*this) + TMatrixMxN(value));
}

template inline TMatrixMxN TMatrixMxN::operator+ (const T (&value)[M*N]) const
{
    return ((*this) + TMatrixMxN(value));
}

template inline TMatrixMxN const &TMatrixMxN::operator+= (TMatrixMxN const &other)
{
    (*this) = (*this) + other;

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator+= (const T& value)
{
    (*this) = (*this) + TMatrixMxN(value);

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator+= (const T (&value)[M*N])
{
    (*this) = (*this) + TMatrixMxN(value);

    return (*this);
}

	// #######################################################################
	// S U B T R A K T I O N S  -  O P E R A T O R E N
	// #######################################################################
template inline TMatrixMxN TMatrixMxN::operator- (void) const
{
    negate ();
}

template inline TMatrixMxN TMatrixMxN::operator- (TMatrixMxN const &other) const
{
    TMatrixMxN ret;

	// Druchlaufe alle Einträge und rechne minus der anderen Matrix
    for (int i=0; imatrix[i][j] - other.matrix[i][j];
        }
    }

    return ret;
}

template inline TMatrixMxN TMatrixMxN::operator- (const T& value) const
{
    return ((*this) - TMatrixMxN(value));
}

template inline TMatrixMxN TMatrixMxN::operator- (const T (&value)[M*N]) const
{
    return ((*this) - TMatrixMxN(value));
}

template inline TMatrixMxN const &TMatrixMxN::operator-= (TMatrixMxN const &other)
{
    (*this) = (*this) - other;

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator-= (const T& value)
{
    (*this) = (*this) - TMatrixMxN(value);

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator-= (const T (&value)[M*N])
{
    (*this) = (*this) - TMatrixMxN(value);

    return (*this);
}

	// #######################################################################
	// M U L T I P L I K A T I O N S  -  O P E R A T O R E N
	// #######################################################################
template inline TMatrixMxN TMatrixMxN::operator* (TMatrixMxN const &other) const
{
    TMatrixMxN ret;

    for (int i=0; i inline TMatrixMxN TMatrixMxN::operator* (const T& value) const
{
    TMatrixMxN ret;

        // Druchlaufe alle Einträge und rechne mal value
    for (int i=0; i inline TMatrixMxN TMatrixMxN::operator* (const T (&value)[M*N]) const
{
    return ((*this) * TMatrixMxN(value));
}

template inline TMatrixMxN const &TMatrixMxN::operator*= (TMatrixMxN const &other)
{    
    (*this) = (*this) * other;

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator*= (const T& value)
{    
    (*this) = (*this) * value;

    return (*this);
}

template inline TMatrixMxN const &TMatrixMxN::operator*= (const T (&value)[M*N])
{    
    (*this) = (*this) * TMatrixMxN(value);

    return (*this);
}

}; // Namespace

#endif // _TMATRIXMXN_INL__25_07_2004_