mathutils.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *    frankguettler@gmx.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  *   $Log: mathutils.h,v $
00024  *   Revision 1.10  2007/09/27 10:47:04  robot3
00025  *   mathutils: moved abs to selforg/stl_adds.h
00026  *   simulation,base: added callbackable support,
00027  *   added WSM (WindowStatisticsManager) funtionality
00028  *
00029  *   Revision 1.9  2007/04/03 16:33:13  der
00030  *   removed clip
00031  *
00032  *   Revision 1.8  2006/08/08 17:04:47  martius
00033  *   added new sensor model
00034  *
00035  *   Revision 1.7  2006/07/14 12:23:56  martius
00036  *   selforg becomes HEAD
00037  *
00038  *   Revision 1.3.4.10  2006/07/10 12:07:16  martius
00039  *   Matrixlib now in selforg
00040  *   optimised compilation
00041  *
00042  *   Revision 1.3.4.9  2006/06/27 14:14:30  robot3
00043  *   -optimized mesh and boundingshape code
00044  *   -other changes
00045  *
00046  *   Revision 1.3.4.8  2006/03/29 15:10:11  martius
00047  *   osgMatrix2matrixlib
00048  *
00049  *   Revision 1.3.4.7  2006/03/05 10:58:18  robot3
00050  *   added a template function normalize360
00051  *
00052  *   Revision 1.3.4.6  2006/03/04 16:57:36  robot3
00053  *   added a template function for abs
00054  *
00055  *   Revision 1.3.4.5  2006/02/07 15:48:56  martius
00056  *   axis
00057  *
00058  *   Revision 1.3.4.4  2005/12/15 17:04:32  martius
00059  *   getAngle
00060  *   min, max and so on are template functions now
00061  *
00062  *   Revision 1.3.4.3  2005/12/14 15:37:38  martius
00063  *   rotation matrix for axis
00064  *
00065  *   Revision 1.3.4.2  2005/11/24 16:21:45  fhesse
00066  *   multMatrixPosition added
00067  *
00068  *   Revision 1.3.4.1  2005/11/14 17:37:25  martius
00069  *   moved to selforg
00070  *
00071  *   Revision 1.3  2005/11/10 09:09:55  martius
00072  *   use defines for definitions of sqrt, min, max...
00073  *
00074  *   Revision 1.2  2005/10/27 14:16:11  martius
00075  *   some bugs fixed, module now works
00076  *   some functions from controller_misc.h are here now
00077  *
00078  *   Revision 1.1  2005/10/27 12:15:22  robot3
00079  *   several useful functions that provide mathematic operations
00080  *
00081  *                                                                         *
00082  ***************************************************************************/
00083 #ifndef __MATHUTILS_H
00084 #define __MATHUTILS_H
00085 
00086 #include <selforg/matrix.h>
00087 #include <selforg/position.h>
00088 #include "osgforwarddecl.h"
00089 #include <osg/Math>
00090 
00091 namespace lpzrobots {
00092 
00093   class Axis;
00094 
00095 /*   template<typename T> */
00096 /*   inline T clip(T v,T minimum, T maximum) */
00097 /*     { return clampBelow(clampAbove(v,minimum),maximum); } */
00098 
00099 /*template<typename T> */
00100 /*      inline T abs(T v) */
00101 /*{ return ((v>0)?v:-v); } */
00102 
00103   template<typename T>
00104   inline T normalize360(T v)
00105     { while (v>360) v-=360; while (v<360) v+=360; return v; }
00106   /*******************************************************************************/
00107 
00108 
00109   /**
00110    * returns a rotation matrix (osg) with the given angles
00111    * alpha, beta and gamma
00112    */
00113   osg::Matrix osgRotate(const double& alpha, const double& beta, const double& gamma);
00114 
00115   /**
00116      converts osg matrix to matrix of matrixlib
00117    */
00118   matrix::Matrix osgMatrix2Matrixlib(const osg::Matrix& m);
00119 
00120 
00121   /**
00122      returns a Rotation matrix that rotates the x-axis along with the given axis.
00123      The other 2 axis (y,z) are ambiguous.
00124   */
00125   osg::Matrix rotationMatrixFromAxisX(const Axis& axis);
00126 
00127   /**
00128      returns a Rotation matrix that rotates the z-axis along with the given axis.
00129      The other 2 axis (x,y) are ambiguous.
00130   */
00131   osg::Matrix rotationMatrixFromAxisZ(const Axis& axis);
00132 
00133   /**
00134    * returns the angle between two vectors (in rad)
00135    */
00136   double getAngle(const osg::Vec3& a, const osg::Vec3& b) ;
00137 
00138   /// converts an ode rotation matrix into a 3x3 rotation matrix (matrixlib)
00139   matrix::Matrix odeRto3x3RotationMatrixT ( const double R[12] );
00140 
00141   /// converts an ode rotation matrix into a 3x3 rotation matrix (matrixlib)
00142   matrix::Matrix odeRto3x3RotationMatrix ( const double R[12] );
00143 
00144   /*******************************************************************************/
00145 
00146   /**
00147      Multiplies 3x3 matrix with position
00148   */
00149   Position multMatrixPosition(const matrix::Matrix& r, Position& p);
00150 
00151   /**
00152    * returns a rotation matrix with the given angle
00153    */
00154   matrix::Matrix getRotationMatrix(const double& angle);
00155 
00156 
00157   /**
00158    * returns a translation matrix with the given Position
00159    */
00160   matrix::Matrix getTranslationMatrix(const Position& p) ;
00161 
00162 
00163   /**
00164    * removes the translation in the matrix
00165    */
00166   matrix::Matrix removeTranslationInMatrix(const matrix::Matrix& pose);
00167 
00168 
00169   /**
00170    * removes the rotation in the matrix
00171    */
00172   matrix::Matrix removeRotationInMatrix(const matrix::Matrix& pose) ;
00173 
00174 
00175   /**
00176    * returns the angle between two vectors
00177    */
00178   double getAngle(Position a, Position b) ;
00179 
00180 }
00181 
00182 #endif

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7