mathutils.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  ***************************************************************************/
00024 #ifndef __MATHUTILS_H
00025 #define __MATHUTILS_H
00026 
00027 #include <selforg/matrix.h>
00028 #include <selforg/position.h>
00029 #include "osgforwarddecl.h"
00030 #include <osg/Math>
00031 
00032 namespace lpzrobots {
00033 
00034   class Axis;
00035 
00036 /*   template<typename T> */
00037 /*   inline T clip(T v,T minimum, T maximum) */
00038 /*     { return clampBelow(clampAbove(v,minimum),maximum); } */
00039 
00040 /*template<typename T> */
00041 /*      inline T abs(T v) */
00042 /*{ return ((v>0)?v:-v); } */
00043 
00044   template<typename T>
00045   inline T normalize360(T v)
00046     { while (v>360) v-=360; while (v<360) v+=360; return v; }
00047   /*******************************************************************************/
00048 
00049 
00050   /**
00051    * returns a rotation matrix (osg) with the given angles
00052    * alpha, beta and gamma
00053    */
00054   osg::Matrix osgRotate(const double& alpha, const double& beta, const double& gamma);
00055 
00056   /**
00057      converts osg matrix to matrix of matrixlib
00058    */
00059   matrix::Matrix osgMatrix2Matrixlib(const osg::Matrix& m);
00060 
00061 
00062   /**
00063      returns a Rotation matrix that rotates the x-axis along with the given axis.
00064      The other 2 axis (y,z) are ambiguous.
00065   */
00066   osg::Matrix rotationMatrixFromAxisX(const Axis& axis);
00067 
00068   /**
00069      returns a Rotation matrix that rotates the z-axis along with the given axis.
00070      The other 2 axis (x,y) are ambiguous.
00071   */
00072   osg::Matrix rotationMatrixFromAxisZ(const Axis& axis);
00073 
00074   /**
00075    * returns the angle between two vectors (in rad)
00076    */
00077   double getAngle(const osg::Vec3& a, const osg::Vec3& b) ;
00078 
00079   /// converts an ode rotation matrix into a 3x3 rotation matrix (matrixlib)
00080   matrix::Matrix odeRto3x3RotationMatrixT ( const double R[12] );
00081 
00082   /// converts an ode rotation matrix into a 3x3 rotation matrix (matrixlib)
00083   matrix::Matrix odeRto3x3RotationMatrix ( const double R[12] );
00084 
00085   /*******************************************************************************/
00086 
00087   /**
00088      Multiplies 3x3 matrix with position
00089   */
00090   Position multMatrixPosition(const matrix::Matrix& r, Position& p);
00091 
00092   /**
00093    * returns a rotation matrix with the given angle
00094    */
00095   matrix::Matrix getRotationMatrix(const double& angle);
00096 
00097 
00098   /**
00099    * returns a translation matrix with the given Position
00100    */
00101   matrix::Matrix getTranslationMatrix(const Position& p) ;
00102 
00103 
00104   /**
00105    * removes the translation in the matrix
00106    */
00107   matrix::Matrix removeTranslationInMatrix(const matrix::Matrix& pose);
00108 
00109 
00110   /**
00111    * removes the rotation in the matrix
00112    */
00113   matrix::Matrix removeRotationInMatrix(const matrix::Matrix& pose) ;
00114 
00115 
00116   /**
00117    * returns the angle between two vectors
00118    */
00119   double getAngle(Position a, Position b) ;
00120 
00121 }
00122 
00123 #endif
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3