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

Generated on Tue Jan 16 02:14:36 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8