39 #include <visp3/core/vpConfig.h>
41 #ifdef VISP_HAVE_CATCH2
42 #include <visp3/core/vpHomogeneousMatrix.h>
44 #define CATCH_CONFIG_RUNNER
47 #ifdef ENABLE_VISP_NAMESPACE
53 for (
unsigned int i = 0; i < 4; i++) {
54 for (
unsigned int j = 0; j < 4; j++) {
63 TEST_CASE(
"vpHomogeneousMatrix re-orthogonalize rotation matrix",
"[vpHomogeneousMatrix]")
67 -0.0571, 0.0352, 0.1744, 0.0478, -0.9835, 0.9470 };
70 SECTION(
"check re-orthogonalize rotation part")
73 -0.0571, 0.0352, 0.1744, 0.0478, -0.9835, 0.9470 };
90 for (
unsigned int i = 0; i < 4; i++) {
91 for (
unsigned int j = 0; j < 4; j++) {
92 CHECK(M1[i][j] == Approx(M2[i][j]).margin(std::numeric_limits<double>::epsilon()));
99 0.2072, 0.0481, 0.1551, -0.2199, -0.9631, 0.9583 };
101 std::cout <<
"Original data:" << std::endl;
102 std::cout <<
"0.9835 -0.0581 0.1716 0.0072" << std::endl;
103 std::cout <<
" -0.0937 -0.9738 0.2072 0.0481" << std::endl;
104 std::cout <<
"0.1551 -0.2199 -0.9631 0.9583" << std::endl;
105 std::cout <<
"0 0 0 1" << std::endl;
106 std::cout <<
"M after rotation re-orthogonalization:\n" << M << std::endl;
111 0.2072, 0.0481, 0.1551, -0.2199, -0.9631, 0.9583 };
114 vpRotationMatrix R { M1[0][0], M1[0][1], M1[0][2], M1[1][0], M1[1][1], M1[1][2], M1[2][0], M1[2][1], M1[2][2] };
118 vpHomogeneousMatrix M { 0.983, -0.058, 0.171, 0.0072, -0.093, -0.973, 0.207, 0.0481, 0.155, -0.219, -0.963, 0.9583 };
122 TEST_CASE(
"vpRotationMatrix re-orthogonalize rotation matrix",
"[vpRotationMatrix]")
125 []() {
vpRotationMatrix R { 0.9835, -0.0581, 0.1716, -0.0489, -0.9972, -0.0571, 0.1744, 0.0478, -0.9835 }; }());
128 vpRotationMatrix R { 0.9835, -0.0581, 0.1716, -0.0937, -0.9738, 0.2072, 0.1551, -0.2199, -0.9631 };
130 std::cout <<
"Original data:" << std::endl;
131 std::cout <<
"0.9835 -0.0581 0.1716" << std::endl;
132 std::cout <<
" -0.0937 -0.9738 0.2072" << std::endl;
133 std::cout <<
"0.1551 -0.2199 -0.9631" << std::endl;
134 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
139 0.46682, -0.74434, 0.47754, -0.83228, -0.55233, -0.04733, 0.29899, -0.37535, -0.87734,
142 std::cout <<
"Original data:" << std::endl;
143 std::cout <<
"0.46682, -0.74434, 0.47754" << std::endl;
144 std::cout <<
"-0.83228, -0.55233, -0.04733" << std::endl;
145 std::cout <<
"0.29899, -0.37535, -0.87734" << std::endl;
146 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
152 0.46682, -0.74434, 0.47754, -0.83228, -0.55233, -0.04733, 0.29899, -0.37535, -0.87734,
155 std::cout <<
"Original data:" << std::endl;
156 std::cout <<
"0.46682, -0.74434, 0.47754" << std::endl;
157 std::cout <<
"-0.83228, -0.55233, -0.04733" << std::endl;
158 std::cout <<
"0.29899, -0.37535, -0.87734" << std::endl;
159 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
162 CHECK_THROWS([]() {
vpRotationMatrix R { 0.983, -0.058, 0.171, -0.093, -0.973, 0.207, 0.155, -0.219, -0.963 }; }());
165 TEST_CASE(
"ENU to NED conversion",
"[enu2ned]")
167 vpHomogeneousMatrix enu_M_flu { 0, -1, 0, 0.2, 1, 0, 0, 1., 0, 0, 1, 0.3 };
168 std::cout <<
"enu_M_flu:\n" << enu_M_flu << std::endl;
170 vpHomogeneousMatrix enu_M_ned { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0 };
171 std::cout <<
"enu_M_ned:\n" << enu_M_ned << std::endl;
173 vpHomogeneousMatrix flu_M_frd { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0 };
174 std::cout <<
"flu_M_frd:\n" << flu_M_frd << std::endl;
181 std::cout <<
"ned_M_frd:\n" << ned_M_frd << std::endl;
184 std::cout <<
"ned_M_frd_est:\n" << ned_M_frd_est << std::endl;
186 bool success = test_matrix_equal(ned_M_frd, ned_M_frd_est);
187 std::cout <<
"Test enu2ned 1 " << (success ?
"succeed" :
"failed") << std::endl;
194 std::cout <<
"ned_M_flu:\n" << ned_M_flu << std::endl;
197 std::cout <<
"ned_M_flu_est:\n" << ned_M_flu_est << std::endl;
199 bool success = test_matrix_equal(ned_M_flu, ned_M_flu_est);
200 std::cout <<
"Test enu2ned 2 " << (success ?
"succeed" :
"failed") << std::endl;
206 TEST_CASE(
"vpHomogenousMatrix * vpRotationMatrix",
"[operator*]")
210 0.9835, -0.0581, 0.1716, 0.0072,
211 -0.0489, -0.9972, -0.0571, 0.0352,
212 0.1744, 0.0478, -0.9835, 0.9470
215 0.9835, -0.0581, 0.1716, 0,
216 -0.0489, -0.9972, -0.0571, 0,
217 0.1744, 0.0478, -0.9835, 0
223 bool success = test_matrix_equal(_1_M_3_, _1_M_3_truth);
224 std::cout <<
"Test vpHomogeneousMatrix vpHomogeneousMatrix::operator*(vpRotationMatrix) " << (success ?
"succeed" :
"failed") << std::endl;
228 int main(
int argc,
char *argv[])
230 Catch::Session session;
233 session.applyCommandLine(argc, argv);
235 int numFailed = session.run();
245 int main() {
return EXIT_SUCCESS; }
Implementation of an homogeneous matrix and operations on such kind of matrices.
void orthogonalizeRotation()
vpHomogeneousMatrix inverse() const
static bool equal(double x, double y, double threshold=0.001)
static vpHomogeneousMatrix enu2ned(const vpHomogeneousMatrix &enu_M)
Implementation of a rotation matrix and operations on such kind of matrices.