template math functions in pimathmatrix.h and pimathvector.h and pimathbase.h

add PIMathMatrixT::rotate for matrix 2x2
This commit is contained in:
2020-10-22 17:29:58 +03:00
parent f5652efc32
commit fbe850abf0
4 changed files with 34 additions and 20 deletions

View File

@@ -425,7 +425,7 @@ public:
for (uint k = i; k < Cols; ++k) smat.m[k][j] -= mul * smat.m[k][i];
}
if (i < Cols - 1) {
if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) {
if (piAbs<Type>(smat.m[i + 1][i + 1]) < Type(1E-200)) {
if (ok != 0) *ok = false;
return *this;
}
@@ -469,7 +469,7 @@ public:
for (uint k = 0; k < Cols; ++k) mtmp.m[k][j] -= mul * mtmp.m[k][i];
}
if (i < Cols - 1) {
if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) {
if (piAbs<Type>(smat.m[i + 1][i + 1]) < Type(1E-200)) {
if (ok != 0) *ok = false;
return *this;
}
@@ -513,6 +513,18 @@ public:
return tm;
}
_CMatrix rotate(Type angle) {
static_assert(Rows == 2 && Cols == 2, "Works only with 2x2 matrix");
Type c = std::cos(angle);
Type s = std::sin(angle);
PIMathMatrixT<2u, 2u> tm;
tm[0][0] = tm[1][1] = c;
tm[0][1] = -s;
tm[1][0] = s;
*this = *this * tm;
return *this;
}
private:
Type m[Rows][Cols];
};