• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #include "main.h"
11 #include <Eigen/Geometry>
12 #include <Eigen/LU>
13 #include <Eigen/SVD>
14 
eulerangles(void)15 template<typename Scalar> void eulerangles(void)
16 {
17   typedef Matrix<Scalar,3,3> Matrix3;
18   typedef Matrix<Scalar,3,1> Vector3;
19   typedef Quaternion<Scalar> Quaternionx;
20   typedef AngleAxis<Scalar> AngleAxisx;
21 
22   Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
23   Quaternionx q1;
24   q1 = AngleAxisx(a, Vector3::Random().normalized());
25   Matrix3 m;
26   m = q1;
27 
28   #define VERIFY_EULER(I,J,K, X,Y,Z) { \
29     Vector3 ea = m.eulerAngles(I,J,K); \
30     VERIFY_IS_APPROX(m,  Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z()))); \
31   }
32   VERIFY_EULER(0,1,2, X,Y,Z);
33   VERIFY_EULER(0,1,0, X,Y,X);
34   VERIFY_EULER(0,2,1, X,Z,Y);
35   VERIFY_EULER(0,2,0, X,Z,X);
36 
37   VERIFY_EULER(1,2,0, Y,Z,X);
38   VERIFY_EULER(1,2,1, Y,Z,Y);
39   VERIFY_EULER(1,0,2, Y,X,Z);
40   VERIFY_EULER(1,0,1, Y,X,Y);
41 
42   VERIFY_EULER(2,0,1, Z,X,Y);
43   VERIFY_EULER(2,0,2, Z,X,Z);
44   VERIFY_EULER(2,1,0, Z,Y,X);
45   VERIFY_EULER(2,1,2, Z,Y,Z);
46 }
47 
test_geo_eulerangles()48 void test_geo_eulerangles()
49 {
50   for(int i = 0; i < g_repeat; i++) {
51     CALL_SUBTEST_1( eulerangles<float>() );
52     CALL_SUBTEST_2( eulerangles<double>() );
53   }
54 }
55