Rotation remake

This commit is contained in:
Шишов Максим Денисович
2020-09-03 15:23:54 +03:00
parent 4d03ba1210
commit 9544d5ef0d
3 changed files with 36 additions and 30 deletions

View File

@@ -63,9 +63,9 @@ class PIP_EXPORT PIMathMatrixT {
typedef PIMathMatrixT<Cols, Rows, Type> _CMatrixI; typedef PIMathMatrixT<Cols, Rows, Type> _CMatrixI;
typedef PIMathVectorT<Rows, Type> _CMCol; typedef PIMathVectorT<Rows, Type> _CMCol;
typedef PIMathVectorT<Cols, Type> _CMRow; typedef PIMathVectorT<Cols, Type> _CMRow;
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic"); static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
static_assert(Rows > 0, "Row count must be > 0"); static_assert(Rows > 0, "Row count must be > 0");
static_assert(Cols > 0, "Column count must be > 0"); static_assert(Cols > 0, "Column count must be > 0");
public: public:
PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT() {resize(Rows, Cols);}
PIMathMatrixT(const PIVector<Type> & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} PIMathMatrixT(const PIVector<Type> & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];}
@@ -86,7 +86,7 @@ public:
static _CMatrix filled(const Type & v) {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = v; return tm;} static _CMatrix filled(const Type & v) {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = v; return tm;}
/** /**
* @brief Rotation the matrix by an "angle" * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, else return _CMatrix
* *
* @param angle is the angle of rotation of the matrix * @param angle is the angle of rotation of the matrix
* @return rotated matrix * @return rotated matrix
@@ -94,7 +94,7 @@ public:
static _CMatrix rotation(double angle) {return _CMatrix();} static _CMatrix rotation(double angle) {return _CMatrix();}
/** /**
* @brief Rotation of the matrix by an "angle" along the X axis * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix
* *
* @param angle is the angle of rotation of the matrix along the X axis * @param angle is the angle of rotation of the matrix along the X axis
* @return rotated matrix * @return rotated matrix
@@ -102,7 +102,7 @@ public:
static _CMatrix rotationX(double angle) {return _CMatrix();} static _CMatrix rotationX(double angle) {return _CMatrix();}
/** /**
* @brief Rotation of the matrix by an "angle" along the Y axis * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix
* *
* @param angle is the angle of rotation of the matrix along the Y axis * @param angle is the angle of rotation of the matrix along the Y axis
* @return rotated matrix * @return rotated matrix
@@ -110,7 +110,7 @@ public:
static _CMatrix rotationY(double angle) {return _CMatrix();} static _CMatrix rotationY(double angle) {return _CMatrix();}
/** /**
* @brief Rotation of the matrix by an "angle" along the Z axis * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix
* *
* @param angle is the angle of rotation of the matrix along the Z axis * @param angle is the angle of rotation of the matrix along the Z axis
* @return rotated matrix * @return rotated matrix
@@ -118,7 +118,7 @@ public:
static _CMatrix rotationZ(double angle) {return _CMatrix();} static _CMatrix rotationZ(double angle) {return _CMatrix();}
/** /**
* @brief Scaling the matrix along the X axis by the value "factor" * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix
* *
* @param factor is the value of scaling by X axis * @param factor is the value of scaling by X axis
* @return rotated matrix * @return rotated matrix
@@ -126,7 +126,7 @@ public:
static _CMatrix scaleX(double factor) {return _CMatrix();} static _CMatrix scaleX(double factor) {return _CMatrix();}
/** /**
* @brief Scaling the matrix along the Y axis by the value "factor" * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix
* *
* @param factor is the value of scaling by Y axis * @param factor is the value of scaling by Y axis
* @return rotated matrix * @return rotated matrix
@@ -134,7 +134,7 @@ public:
static _CMatrix scaleY(double factor) {return _CMatrix();} static _CMatrix scaleY(double factor) {return _CMatrix();}
/** /**
* @brief Scaling the matrix along the Z axis by the value "factor" * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix
* *
* @param factor is the value of scaling by Z axis * @param factor is the value of scaling by Z axis
* @return rotated matrix * @return rotated matrix

View File

@@ -3,7 +3,6 @@
#include "pithread.h" #include "pithread.h"
#include <atomic> #include <atomic>
#include "pistring.h"
/** /**
* Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests
@@ -58,5 +57,4 @@ public:
} }
}; };
#endif //AWRCANFLASHER_TESTUTIL_H #endif //AWRCANFLASHER_TESTUTIL_H

View File

@@ -674,24 +674,6 @@ TEST(PIMathMatrixT_Test, transposed)
ASSERT_TRUE(b); ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, rotation)
{
double angle = 1.0;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle);
double c = cos(angle);
double s = sin(angle);
if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrixT_Test, scaleX_two) TEST(PIMathMatrixT_Test, scaleX_two)
{ {
double factor = 5.64; double factor = 5.64;
@@ -726,6 +708,31 @@ TEST(PIMathMatrixT_Test, scaleY_two)
ASSERT_TRUE(b); ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, rotation_2x2)
{
double angle = 1.0;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle);
double c = cos(angle);
double s = sin(angle);
if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrixT_Test, rotation_3x3)
{
double angle = 1.0;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle);
ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0));
}
TEST(PIMathMatrixT_Test, rotationX) TEST(PIMathMatrixT_Test, rotationX)
{ {
double angle = 1.0; double angle = 1.0;
@@ -831,3 +838,4 @@ TEST(PIMathMatrixT_Test, scaleZ_three)
ASSERT_TRUE(b); ASSERT_TRUE(b);
} }