39 #include <visp3/core/vpConfig.h>
41 #if defined(VISP_HAVE_CATCH2)
42 #include <visp3/core/vpHomogeneousMatrix.h>
44 #include <catch_amalgamated.hpp>
46 #ifdef ENABLE_VISP_NAMESPACE
52 for (
unsigned int i = 0; i < 4; i++) {
53 for (
unsigned int j = 0; j < 4; j++) {
62 TEST_CASE(
"vpHomogeneousMatrix re-orthogonalize rotation matrix",
"[vpHomogeneousMatrix]")
66 -0.0571, 0.0352, 0.1744, 0.0478, -0.9835, 0.9470 };
69 SECTION(
"check re-orthogonalize rotation part")
72 -0.0571, 0.0352, 0.1744, 0.0478, -0.9835, 0.9470 };
89 for (
unsigned int i = 0; i < 4; i++) {
90 for (
unsigned int j = 0; j < 4; j++) {
91 CHECK(M1[i][j] == Catch::Approx(M2[i][j]).margin(std::numeric_limits<double>::epsilon()));
98 0.2072, 0.0481, 0.1551, -0.2199, -0.9631, 0.9583 };
100 std::cout <<
"Original data:" << std::endl;
101 std::cout <<
"0.9835 -0.0581 0.1716 0.0072" << std::endl;
102 std::cout <<
" -0.0937 -0.9738 0.2072 0.0481" << std::endl;
103 std::cout <<
"0.1551 -0.2199 -0.9631 0.9583" << std::endl;
104 std::cout <<
"0 0 0 1" << std::endl;
105 std::cout <<
"M after rotation re-orthogonalization:\n" << M << std::endl;
110 0.2072, 0.0481, 0.1551, -0.2199, -0.9631, 0.9583 };
113 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] };
117 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 };
121 TEST_CASE(
"vpRotationMatrix re-orthogonalize rotation matrix",
"[vpRotationMatrix]")
124 []() {
vpRotationMatrix R { 0.9835, -0.0581, 0.1716, -0.0489, -0.9972, -0.0571, 0.1744, 0.0478, -0.9835 }; }());
127 vpRotationMatrix R { 0.9835, -0.0581, 0.1716, -0.0937, -0.9738, 0.2072, 0.1551, -0.2199, -0.9631 };
129 std::cout <<
"Original data:" << std::endl;
130 std::cout <<
"0.9835 -0.0581 0.1716" << std::endl;
131 std::cout <<
" -0.0937 -0.9738 0.2072" << std::endl;
132 std::cout <<
"0.1551 -0.2199 -0.9631" << std::endl;
133 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
138 0.46682, -0.74434, 0.47754, -0.83228, -0.55233, -0.04733, 0.29899, -0.37535, -0.87734,
141 std::cout <<
"Original data:" << std::endl;
142 std::cout <<
"0.46682, -0.74434, 0.47754" << std::endl;
143 std::cout <<
"-0.83228, -0.55233, -0.04733" << std::endl;
144 std::cout <<
"0.29899, -0.37535, -0.87734" << std::endl;
145 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
151 0.46682, -0.74434, 0.47754, -0.83228, -0.55233, -0.04733, 0.29899, -0.37535, -0.87734,
154 std::cout <<
"Original data:" << std::endl;
155 std::cout <<
"0.46682, -0.74434, 0.47754" << std::endl;
156 std::cout <<
"-0.83228, -0.55233, -0.04733" << std::endl;
157 std::cout <<
"0.29899, -0.37535, -0.87734" << std::endl;
158 std::cout <<
"R after rotation re-orthogonalization:\n" << R << std::endl;
161 CHECK_THROWS([]() {
vpRotationMatrix R { 0.983, -0.058, 0.171, -0.093, -0.973, 0.207, 0.155, -0.219, -0.963 }; }());
164 TEST_CASE(
"ENU to NED conversion",
"[enu2ned]")
166 vpHomogeneousMatrix enu_M_flu { 0, -1, 0, 0.2, 1, 0, 0, 1., 0, 0, 1, 0.3 };
167 std::cout <<
"enu_M_flu:\n" << enu_M_flu << std::endl;
169 vpHomogeneousMatrix enu_M_ned { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0 };
170 std::cout <<
"enu_M_ned:\n" << enu_M_ned << std::endl;
172 vpHomogeneousMatrix flu_M_frd { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0 };
173 std::cout <<
"flu_M_frd:\n" << flu_M_frd << std::endl;
180 std::cout <<
"ned_M_frd:\n" << ned_M_frd << std::endl;
183 std::cout <<
"ned_M_frd_est:\n" << ned_M_frd_est << std::endl;
185 bool success = test_matrix_equal(ned_M_frd, ned_M_frd_est);
186 std::cout <<
"Test enu2ned 1 " << (success ?
"succeed" :
"failed") << std::endl;
193 std::cout <<
"ned_M_flu:\n" << ned_M_flu << std::endl;
196 std::cout <<
"ned_M_flu_est:\n" << ned_M_flu_est << std::endl;
198 bool success = test_matrix_equal(ned_M_flu, ned_M_flu_est);
199 std::cout <<
"Test enu2ned 2 " << (success ?
"succeed" :
"failed") << std::endl;
205 TEST_CASE(
"vpHomogenousMatrix * vpRotationMatrix",
"[operator*]")
209 0.9835, -0.0581, 0.1716, 0.0072,
210 -0.0489, -0.9972, -0.0571, 0.0352,
211 0.1744, 0.0478, -0.9835, 0.9470
214 0.9835, -0.0581, 0.1716, 0,
215 -0.0489, -0.9972, -0.0571, 0,
216 0.1744, 0.0478, -0.9835, 0
222 bool success = test_matrix_equal(_1_M_3_, _1_M_3_truth);
223 std::cout <<
"Test vpHomogeneousMatrix vpHomogeneousMatrix::operator*(vpRotationMatrix) " << (success ?
"succeed" :
"failed") << std::endl;
227 int main(
int argc,
char *argv[])
229 Catch::Session session;
230 session.applyCommandLine(argc, argv);
231 int numFailed = session.run();
237 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.