geo_eulerangles.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 #include <Eigen/Geometry>
00027 #include <Eigen/LU>
00028 #include <Eigen/SVD>
00029 
00030 template<typename Scalar> void eulerangles(void)
00031 {
00032   typedef Matrix<Scalar,3,3> Matrix3;
00033   typedef Matrix<Scalar,3,1> Vector3;
00034   typedef Quaternion<Scalar> Quaternionx;
00035   typedef AngleAxis<Scalar> AngleAxisx;
00036 
00037   Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
00038   Quaternionx q1;
00039   q1 = AngleAxisx(a, Vector3::Random().normalized());
00040   Matrix3 m;
00041   m = q1;
00042 
00043   #define VERIFY_EULER(I,J,K, X,Y,Z) { \
00044     Vector3 ea = m.eulerAngles(I,J,K); \
00045     Matrix3 m1 = Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z())); \
00046     VERIFY_IS_APPROX(m,  Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z()))); \
00047   }
00048   VERIFY_EULER(0,1,2, X,Y,Z);
00049   VERIFY_EULER(0,1,0, X,Y,X);
00050   VERIFY_EULER(0,2,1, X,Z,Y);
00051   VERIFY_EULER(0,2,0, X,Z,X);
00052 
00053   VERIFY_EULER(1,2,0, Y,Z,X);
00054   VERIFY_EULER(1,2,1, Y,Z,Y);
00055   VERIFY_EULER(1,0,2, Y,X,Z);
00056   VERIFY_EULER(1,0,1, Y,X,Y);
00057 
00058   VERIFY_EULER(2,0,1, Z,X,Y);
00059   VERIFY_EULER(2,0,2, Z,X,Z);
00060   VERIFY_EULER(2,1,0, Z,Y,X);
00061   VERIFY_EULER(2,1,2, Z,Y,Z);
00062 }
00063 
00064 void test_geo_eulerangles()
00065 {
00066   for(int i = 0; i < g_repeat; i++) {
00067     CALL_SUBTEST_1( eulerangles<float>() );
00068     CALL_SUBTEST_2( eulerangles<double>() );
00069   }
00070 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:15