UtilFunctions.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Stefan Kohlbrecher, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Simulation, Systems Optimization and Robotics
13 // group, TU Darmstadt nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef utilfunctions_h__
30 #define utilfunctions_h__
31 
32 #include <cmath>
33 
34 namespace util{
35 
36 static inline float normalize_angle_pos(float angle)
37 {
38  return fmod(fmod(angle, 2.0f*M_PI) + 2.0f*M_PI, 2.0f*M_PI);
39 }
40 
41 static inline float normalize_angle(float angle)
42 {
43  float a = normalize_angle_pos(angle);
44  if (a > M_PI){
45  a -= 2.0f*M_PI;
46  }
47  return a;
48 }
49 
50 static inline float sqr(float val)
51 {
52  return val*val;
53 }
54 
55 static inline int sign(int x)
56 {
57  return x > 0 ? 1 : -1;
58 }
59 
60 template<typename T>
61 static T toDeg(const T radVal)
62 {
63  return radVal * static_cast<T>(180.0 / M_PI);
64 }
65 
66 template<typename T>
67 static T toRad(const T degVal)
68 {
69  return degVal * static_cast<T>(M_PI / 180.0);
70 }
71 
72 static bool poseDifferenceLargerThan(const Eigen::Vector3f& pose1, const Eigen::Vector3f& pose2, float distanceDiffThresh, float angleDiffThresh)
73 {
74  //check distance
75  if ( ( (pose1.head<2>() - pose2.head<2>()).norm() ) > distanceDiffThresh){
76  return true;
77  }
78 
79  float angleDiff = (pose1.z() - pose2.z());
80 
81  if (angleDiff > M_PI) {
82  angleDiff -= M_PI * 2.0f;
83  } else if (angleDiff < -M_PI) {
84  angleDiff += M_PI * 2.0f;
85  }
86 
87  if (abs(angleDiff) > angleDiffThresh){
88  return true;
89  }
90  return false;
91 }
92 
93 }
94 
95 #endif
f
static float sqr(float val)
Definition: UtilFunctions.h:50
static float normalize_angle_pos(float angle)
Definition: UtilFunctions.h:36
static int sign(int x)
Definition: UtilFunctions.h:55
static float normalize_angle(float angle)
Definition: UtilFunctions.h:41
static T toRad(const T degVal)
Definition: UtilFunctions.h:67
static T toDeg(const T radVal)
Definition: UtilFunctions.h:61
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
static bool poseDifferenceLargerThan(const Eigen::Vector3f &pose1, const Eigen::Vector3f &pose2, float distanceDiffThresh, float angleDiffThresh)
Definition: UtilFunctions.h:72


hector_mapping
Author(s): Stefan Kohlbrecher
autogenerated on Sun Nov 3 2019 03:18:33