26 #include "Matrix2x2.hh"
28 #include "Base/Common/CompareFloatingPoint.hh"
30 #include <Base/Common/BIASpragma.hh>
38 #define MATRIX2X2_ZERO_EPS 1e-13
43 #define MATRIX_DEBUG(arg)
77 const T a2,
const T a3)
91 register const T *matP = mat.
GetData();
92 register T *destP = this->GetData();
93 memcpy(destP, matP, 4*
sizeof(T));
100 BIASERR(
"newsize(" << rows <<
", " << cols <<
") does not make sense "
101 "for fixed size 2x2 matrix!");
108 BIASERR(
"Unsigned integer matrix can not be inverted!");
117 T den=(*this)[0][0]*(*this)[1][1]-(*this)[0][1]*(*this)[1][0];
119 if (den==0.0)
return -1;
120 BIASASSERT(den!=0.0);
122 result[0][0]=(*this)[1][1]/den;
123 result[1][0]=-(*this)[1][0]/den;
124 result[0][1]=-(*this)[0][1]/den;
125 result[1][1]=(*this)[0][0]/den;
134 BIASERR(
"Eigenvalue decomposition can not be computed for integer matrices!");
144 double a=(*this)[0][0], b=(*this)[0][1], c=(*this)[1][1], d=(*this)[1][0];
145 MATRIX_DEBUG(
"a "<<a <<
"\tb "<<b<<
"\tc "<<c<<
"\td "<<d<<endl);
194 norm2=(a+c)*(a+c)/4.0-a*c+b*d;
195 if (norm2 > -numeric_limits<double>::epsilon() && norm2 < 0.0 ) {
199 MATRIX_DEBUG(
"only imaginary solutions\n");
200 MATRIX_DEBUG(
"norm2<0.0: "<<norm2<<endl);
208 res = ((fabs(value1)<DOUBLE_EPSILON)?0:1) +
209 ((fabs(value2)<DOUBLE_EPSILON)?0:1);
210 MATRIX_DEBUG(
"rank "<<res<<
"\t"<<value1<<
"\t"<<value2<<
"\n");
212 norm1 = sqrt(b*b+(a-value1)*(a-value1));
213 MATRIX_DEBUG(
"norm1: "<<norm1<<endl);
214 if (norm1>=MATRIX2X2_ZERO_EPS){
215 vec1[0] = - b / norm1;
216 vec1[1] = (a-value1) / norm1;
221 MATRIX_DEBUG(
"vec1: "<<vec1<<endl);
223 norm2 = sqrt(d*d+(c-value2)*(c-value2));
224 MATRIX_DEBUG(
"norm2: "<<norm2<<endl);
225 if (norm2>=MATRIX2X2_ZERO_EPS){
226 vec2[0] = - (c-value2) / norm2;
232 MATRIX_DEBUG(
"vec2: "<<vec2<<endl);
278 template class BIASMathBase_EXPORT BIAS::Matrix2x2<type>;\
Subscript num_cols() const
is a 'fixed size' quadratic matrix of dim.
Matrix2x2 & newsize(int rows, int cols)
just neccessary to avoid resizing of this 'fixed size' matrix because it is derived from the resizabl...
class Vector2 contains a Vector of dim.
Matrix2x2< T > Invert() const
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
int EigenvalueDecomposition(T &value1, Vector2< T > &vector1, T &value2, Vector2< T > &vector2) const
Eigenvalue decomposition.
Matrix2x2< T > & operator=(const Matrix2x2< T > &mat)
assignment operator
matrix class with arbitrary size, indexing is row major.
Subscript num_rows() const