39 #include <visp3/core/vpConfig.h>
41 #ifdef VISP_HAVE_CATCH2
42 #include <visp3/core/vpHomogeneousMatrix.h>
44 #define CATCH_CONFIG_RUNNER
49 for (
unsigned int i = 0; i < 4; i++) {
50 for (
unsigned int j = 0; j < 4; j++) {
59 TEST_CASE(
"vpHomogeneousMatrix re-orthogonalize rotation matrix",
"[vpHomogeneousMatrix]")
63 -0.0571, 0.0352, 0.1744, 0.0478, -0.9835, 0.9470 };
66 SECTION(
"check re-orthogonalize rotation part")
69 -0.0571, 0.0352, 0.1744, 0.0478, -0.9835, 0.9470 };
86 for (
unsigned int i = 0; i < 4; i++) {
87 for (
unsigned int j = 0; j < 4; j++) {
88 CHECK(M1[i][j] == Approx(M2[i][j]).margin(std::numeric_limits<double>::epsilon()));
95 0.2072, 0.0481, 0.1551, -0.2199, -0.9631, 0.9583 };
97 std::cout <<
"Original data:" << std::endl;
98 std::cout <<
"0.9835 -0.0581 0.1716 0.0072" << std::endl;
99 std::cout <<
" -0.0937 -0.9738 0.2072 0.0481" << std::endl;
100 std::cout <<
"0.1551 -0.2199 -0.9631 0.9583" << std::endl;
101 std::cout <<
"0 0 0 1" << std::endl;
102 std::cout <<
"M after rotation re-orthogonalization:\n" << M << std::endl;
107 0.2072, 0.0481, 0.1551, -0.2199, -0.9631, 0.9583 };
110 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] };
114 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 };
118 TEST_CASE(
"vpRotationMatrix re-orthogonalize rotation matrix",
"[vpRotationMatrix]")
121 []() {
vpRotationMatrix R { 0.9835, -0.0581, 0.1716, -0.0489, -0.9972, -0.0571, 0.1744, 0.0478, -0.9835 }; }());
124 vpRotationMatrix R { 0.9835, -0.0581, 0.1716, -0.0937, -0.9738, 0.2072, 0.1551, -0.2199, -0.9631 };
126 std::cout <<
"Original data:" << std::endl;
127 std::cout <<
"0.9835 -0.0581 0.1716" << std::endl;
128 std::cout <<
" -0.0937 -0.9738 0.2072" << std::endl;
129 std::cout <<
"0.1551 -0.2199 -0.9631" << std::endl;
130 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
135 0.46682, -0.74434, 0.47754, -0.83228, -0.55233, -0.04733, 0.29899, -0.37535, -0.87734,
138 std::cout <<
"Original data:" << std::endl;
139 std::cout <<
"0.46682, -0.74434, 0.47754" << std::endl;
140 std::cout <<
"-0.83228, -0.55233, -0.04733" << std::endl;
141 std::cout <<
"0.29899, -0.37535, -0.87734" << std::endl;
142 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
148 0.46682, -0.74434, 0.47754, -0.83228, -0.55233, -0.04733, 0.29899, -0.37535, -0.87734,
151 std::cout <<
"Original data:" << std::endl;
152 std::cout <<
"0.46682, -0.74434, 0.47754" << std::endl;
153 std::cout <<
"-0.83228, -0.55233, -0.04733" << std::endl;
154 std::cout <<
"0.29899, -0.37535, -0.87734" << std::endl;
155 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
158 CHECK_THROWS([]() {
vpRotationMatrix R { 0.983, -0.058, 0.171, -0.093, -0.973, 0.207, 0.155, -0.219, -0.963 }; }());
161 TEST_CASE(
"ENU to NED conversion",
"[enu2ned]")
163 vpHomogeneousMatrix enu_M_flu { 0, -1, 0, 0.2, 1, 0, 0, 1., 0, 0, 1, 0.3 };
164 std::cout <<
"enu_M_flu:\n" << enu_M_flu << std::endl;
166 vpHomogeneousMatrix enu_M_ned { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0 };
167 std::cout <<
"enu_M_ned:\n" << enu_M_ned << std::endl;
169 vpHomogeneousMatrix flu_M_frd { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0 };
170 std::cout <<
"flu_M_frd:\n" << flu_M_frd << std::endl;
177 std::cout <<
"ned_M_frd:\n" << ned_M_frd << std::endl;
180 std::cout <<
"ned_M_frd_est:\n" << ned_M_frd_est << std::endl;
182 bool success = test_matrix_equal(ned_M_frd, ned_M_frd_est);
183 std::cout <<
"Test enu2ned 1 " << (success ?
"succeed" :
"failed") << std::endl;
190 std::cout <<
"ned_M_flu:\n" << ned_M_flu << std::endl;
193 std::cout <<
"ned_M_flu_est:\n" << ned_M_flu_est << std::endl;
195 bool success = test_matrix_equal(ned_M_flu, ned_M_flu_est);
196 std::cout <<
"Test enu2ned 2 " << (success ?
"succeed" :
"failed") << std::endl;
202 TEST_CASE(
"vpHomogenousMatrix * vpRotationMatrix",
"[operator*]")
206 0.9835, -0.0581, 0.1716, 0.0072,
207 -0.0489, -0.9972, -0.0571, 0.0352,
208 0.1744, 0.0478, -0.9835, 0.9470
211 0.9835, -0.0581, 0.1716, 0,
212 -0.0489, -0.9972, -0.0571, 0,
213 0.1744, 0.0478, -0.9835, 0
219 bool success = test_matrix_equal(_1_M_3_, _1_M_3_truth);
220 std::cout <<
"Test vpHomogeneousMatrix vpHomogeneousMatrix::operator*(vpRotationMatrix) " << (success ?
"succeed" :
"failed") << std::endl;
224 int main(
int argc,
char *argv[])
226 Catch::Session session;
229 session.applyCommandLine(argc, argv);
231 int numFailed = session.run();
241 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.