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

Generated on Mon Aug 7 16:40:14 2006 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7