From 15eca2432a071815884af6ccc2ceb66be91e9db7 Mon Sep 17 00:00:00 2001 From: Tal Hadad Date: Tue, 18 Oct 2016 23:24:57 +0300 Subject: Euler tests: Tighter precision when no roll exists and clean code. --- unsupported/test/EulerAngles.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'unsupported/test/EulerAngles.cpp') diff --git a/unsupported/test/EulerAngles.cpp b/unsupported/test/EulerAngles.cpp index 149cf7f94..79ee72847 100644 --- a/unsupported/test/EulerAngles.cpp +++ b/unsupported/test/EulerAngles.cpp @@ -50,7 +50,7 @@ void verify_euler(const EulerAngles& e) std::cos(e.beta()) : std::sin(e.beta()) ); - const Scalar precision = test_precision() / longitudeRadius; + Scalar precision = test_precision() / longitudeRadius; Scalar betaRangeStart, betaRangeEnd; if (EulerSystem::IsTaitBryan) @@ -84,15 +84,22 @@ void verify_euler(const EulerAngles& e) const Matrix3 m(e); VERIFY_IS_APPROX(Scalar(m.determinant()), ONE); - Vector3 eabis = static_cast(m).angles(); + EulerAnglesType ebis(m); + + // When no roll(acting like polar representation), we have the best precision. + // One of those cases is when the Euler angles are on the pole, and because it's singular case, + // the computation returns no roll. + if (ebis.beta() == 0) + precision = test_precision(); // Check that eabis in range - VERIFY_APPROXED_RANGE(-PI, eabis[0], PI); - VERIFY_APPROXED_RANGE(betaRangeStart, eabis[1], betaRangeEnd); - VERIFY_APPROXED_RANGE(-PI, eabis[2], PI); + VERIFY_APPROXED_RANGE(-PI, ebis.alpha(), PI); + VERIFY_APPROXED_RANGE(betaRangeStart, ebis.beta(), betaRangeEnd); + VERIFY_APPROXED_RANGE(-PI, ebis.gamma(), PI); - const Matrix3 mbis(AngleAxisType(eabis[0], I) * AngleAxisType(eabis[1], J) * AngleAxisType(eabis[2], K)); + const Matrix3 mbis(AngleAxisType(ebis.alpha(), I) * AngleAxisType(ebis.beta(), J) * AngleAxisType(ebis.gamma(), K)); VERIFY_IS_APPROX(Scalar(mbis.determinant()), ONE); + VERIFY_IS_APPROX(mbis, ebis.toRotationMatrix()); /*std::cout << "===================\n" << "e: " << e << std::endl << "eabis: " << eabis.transpose() << std::endl << @@ -116,8 +123,8 @@ void verify_euler(const EulerAngles& e) // Quaternions const QuaternionType q(e); - eabis = static_cast(q).angles(); - const QuaternionType qbis(AngleAxisType(eabis[0], I) * AngleAxisType(eabis[1], J) * AngleAxisType(eabis[2], K)); + ebis = q; + const QuaternionType qbis(ebis); VERIFY(internal::isApprox(std::abs(q.dot(qbis)), ONE, precision)); //VERIFY_IS_APPROX(eabis, eabis2);// Verify that the euler angles are still the same @@ -170,7 +177,7 @@ template void check_singular_cases(const Scalar& singularBeta) typedef Matrix Vector3; const Scalar PI = Scalar(EIGEN_PI); - for (Scalar epsilon = std::numeric_limits::epsilon(); epsilon < 1; epsilon *= Scalar(1.2)) + for (Scalar epsilon = NumTraits::epsilon(); epsilon < 1; epsilon *= Scalar(1.2)) { check_all_var(Vector3(PI/4, singularBeta, PI/3)); check_all_var(Vector3(PI/4, singularBeta - epsilon, PI/3)); -- cgit v1.2.3