You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "main.h"
  10. #include <Eigen/Geometry>
  11. #include <Eigen/LU>
  12. #include <Eigen/SVD>
  13. template<typename Scalar> void eulerangles(void)
  14. {
  15. typedef Matrix<Scalar,3,3> Matrix3;
  16. typedef Matrix<Scalar,3,1> Vector3;
  17. typedef Quaternion<Scalar> Quaternionx;
  18. typedef AngleAxis<Scalar> AngleAxisx;
  19. Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
  20. Quaternionx q1;
  21. q1 = AngleAxisx(a, Vector3::Random().normalized());
  22. Matrix3 m;
  23. m = q1;
  24. #define VERIFY_EULER(I,J,K, X,Y,Z) { \
  25. Vector3 ea = m.eulerAngles(I,J,K); \
  26. VERIFY_IS_APPROX(m, Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z()))); \
  27. }
  28. VERIFY_EULER(0,1,2, X,Y,Z);
  29. VERIFY_EULER(0,1,0, X,Y,X);
  30. VERIFY_EULER(0,2,1, X,Z,Y);
  31. VERIFY_EULER(0,2,0, X,Z,X);
  32. VERIFY_EULER(1,2,0, Y,Z,X);
  33. VERIFY_EULER(1,2,1, Y,Z,Y);
  34. VERIFY_EULER(1,0,2, Y,X,Z);
  35. VERIFY_EULER(1,0,1, Y,X,Y);
  36. VERIFY_EULER(2,0,1, Z,X,Y);
  37. VERIFY_EULER(2,0,2, Z,X,Z);
  38. VERIFY_EULER(2,1,0, Z,Y,X);
  39. VERIFY_EULER(2,1,2, Z,Y,Z);
  40. }
  41. void test_geo_eulerangles()
  42. {
  43. for(int i = 0; i < g_repeat; i++) {
  44. CALL_SUBTEST_1( eulerangles<float>() );
  45. CALL_SUBTEST_2( eulerangles<double>() );
  46. }
  47. }