47 lines
956 B
C++
47 lines
956 B
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef MINIMAT2_H
|
||
#define MINIMAT2_H
|
||
|
||
/**
|
||
* very simple 2x2 matrix
|
||
*/
|
||
struct MiniMat2 {
|
||
|
||
/** store eigenvalues */
|
||
struct EV {float e1,e2;};
|
||
|
||
/** data */
|
||
float a,b,c,d;
|
||
|
||
/** ctor */
|
||
MiniMat2() : a(0), b(0), c(0), d(0) {;}
|
||
|
||
/** get the matrix' eigenvalues */
|
||
EV getEigenvalues() const {
|
||
const float T = a+d;
|
||
const float D = a*d - b*c;
|
||
EV res;
|
||
res.e1 = T/2 + std::sqrt(T*T/4-D);
|
||
res.e2 = T/2 - std::sqrt(T*T/4-D);
|
||
return res;
|
||
}
|
||
|
||
/** add (x,y) * (x,y)T to the matrix */
|
||
void addSquared(const float x, const float y) {
|
||
a += (x*x); b += (x*y);
|
||
c += (x*y); d += (y*y);
|
||
}
|
||
|
||
};
|
||
|
||
#endif // MINIMAT2_H
|