Line data Source code
1 : // SPDX-FileCopyrightText: 2024 Pairinteraction Developers 2 : // SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 : #include "pairinteraction/utils/euler.hpp" 5 : 6 : #include <array> 7 : #include <doctest/doctest.h> 8 : 9 : namespace pairinteraction { 10 1 : DOCTEST_TEST_CASE("construction of rotation matrixes") { 11 1 : auto rotator = euler::get_rotation_matrix<double>({0, 0, 1}, {0, 1, 0}); 12 1 : auto rotator_reference = Eigen::Matrix3<double>::Identity(); 13 1 : DOCTEST_CHECK((rotator - rotator_reference).norm() == 0); 14 : 15 1 : rotator = euler::get_rotation_matrix<double>({0, 0, 1}, {1, 1, 0}); 16 1 : auto y_axis = Eigen::Vector3<double>{0, 1, 0}; 17 1 : auto rotated_y_axis = rotator * y_axis; 18 1 : auto rotated_y_axis_reference = Eigen::Vector3<double>{1, 1, 0}.normalized(); 19 1 : DOCTEST_CHECK((rotated_y_axis - rotated_y_axis_reference).norm() == 0); 20 : 21 1 : rotator = euler::get_rotation_matrix<double>({1, 0, 0}, {0, 1, 0}); 22 1 : auto z_axis = Eigen::Vector3<double>{0, 0, 1}; 23 1 : auto rotated_z_axis = rotator * z_axis; 24 1 : auto rotated_z_axis_reference = Eigen::Vector3<double>{1, 0, 0}; 25 1 : DOCTEST_CHECK((rotated_z_axis - rotated_z_axis_reference).norm() == 0); 26 : 27 1 : std::string error_msg = "The z-axis and the y-axis are not orhogonal."; 28 1 : DOCTEST_CHECK_THROWS_WITH_AS(euler::get_rotation_matrix<double>({0, 0, 1}, {0, 1, 1}); 29 : , error_msg.c_str(), std::runtime_error); 30 1 : } 31 : 32 1 : DOCTEST_TEST_CASE("construction of zyz euler angles") { 33 1 : constexpr double PI = 3.141592653589793238462643383279502884; 34 : 35 1 : auto euler_angles = euler::get_euler_angles<double>({1, 1, 0}, {0, 0, 1}); 36 1 : std::array<double, 3> euler_angles_reference{0.25 * PI, 0.5 * PI, 0.5 * PI}; 37 1 : DOCTEST_CHECK(std::abs(euler_angles[0] - euler_angles_reference[0]) + 38 : std::abs(euler_angles[1] - euler_angles_reference[1]) + 39 : std::abs(euler_angles[2] - euler_angles_reference[2]) <= 40 : 1e-6); 41 1 : } 42 : } // namespace pairinteraction