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