MathHelper.hpp
Go to the documentation of this file.
1 
20 #ifndef MYMATHHELPER_HPP_
21 #define MYMATHHELPER_HPP_
22 
24 #include <boost/math/special_functions/binomial.hpp>
25 #include <boost/random/mersenne_twister.hpp>
26 #include <boost/random/uniform_int.hpp>
27 #include <boost/random/uniform_real.hpp>
28 #include <boost/random/normal_distribution.hpp>
29 #include <boost/random/variate_generator.hpp>
30 #include <boost/foreach.hpp>
31 #include <ros/ros.h>
32 #include <set>
33 #include <vector>
34 #include <geometry_msgs/Quaternion.h>
35 
36 namespace robot_model_services {
44  class MathHelper {
45  private:
49  static boost::mt19937& getRandomnessGenerator();
50  public:
56  static SimpleSphereCoordinates convertC2S(const SimpleVector3 &cartesian);
57 
63  static void convertC2S(const SimpleVector3 &cartesian, SimpleSphereCoordinates &sphere);
64 
70  static SimpleVector3 convertS2C(const SimpleSphereCoordinates &sphere);
71 
77  static void convertS2C(const SimpleSphereCoordinates &sphere, SimpleVector3 &cartesian);
78 
79  static SimpleVector3 getVisualAxis(const SimpleQuaternion &orientation);
80 
81  static void getVisualAxis(const SimpleQuaternion &orientation, SimpleVector3 &resultAxis);
82 
87  static double getSignum(const double &value);
88 
94  static SimpleVector3 getProjection(const std::size_t &idx, const SimpleVector3 &X);
95 
101  static Precision getCosinus(const SimpleVector3 &X, const SimpleVector3 &Y);
102 
108  static Precision getAngle(const SimpleVector3 &X, const SimpleVector3 &Y);
109 
115  static Precision getMinimumAngleDifference(const Precision &firstAngle, const Precision &secondAngle);
116 
122  static int getRandomInteger(const int &min, const int &max);
123 
129  static Precision getRandomNumber(const Precision &mean, const Precision &standardDeviation);
130 
136  static SimpleVectorX getRandomVector(const SimpleVectorX &mean, const SimpleVectorX &standardDeviation);
137 
142 
149  static SimpleQuaternion getQuaternionByAngles(const Precision &heading, const Precision &attitude, const Precision &bank);
150 
155  static SimpleQuaternionCollectionPtr getOrientationsOnUnitSphere(const int &numberOfPoints);
156 
161  static double radToDeg(double input);
162 
167  static double degToRad(double input);
168 
169  static double getDotProduct(SimpleVector3 v1, SimpleVector3 v2);
170 
171  template<typename Set> static void printSet(boost::shared_ptr<Set> &setPtr) {
172  std::cout << "\t{ ";
173  BOOST_FOREACH(typename Set::value_type value, *setPtr) {
174  std::cout << value << ", ";
175  }
176  std::cout << "}" << std::endl;
177  }
178 
179  template<typename Set> static void printPowerSet(boost::shared_ptr<std::set<boost::shared_ptr<Set> > > &powerSetPtr) {
180  std::cout << "{ " << std::endl;
181  BOOST_FOREACH(boost::shared_ptr<Set> subSetPtr, *powerSetPtr) {
182  printSet(subSetPtr);
183  }
184  std::cout << "} " << std::endl;
185  std::cout << powerSetPtr->size() << " Items" << std::endl;
186  }
187 
188  template<typename Set> static boost::shared_ptr<std::set<boost::shared_ptr<Set> > > powerSet(const boost::shared_ptr<Set> &setPtr) {
190 
191  std::size_t value = 0;
192  assert(setPtr->size() <= 31);
193 
194 
195  std::size_t limit = (1 << setPtr->size());
196  for (std::size_t counter = 0; counter < limit; ++counter) {
197  boost::shared_ptr<Set> subSetPtr(new Set);
198  std::size_t idx = 0;
199  for (typename Set::iterator setIter = setPtr->begin(); setIter != setPtr->end(); ++setIter, ++idx) {
200  if ( (value & (1 << idx)) != 0 ) {
201  subSetPtr->insert(*setIter);
202  }
203  }
204  powerSetPtr->insert(subSetPtr);
205 
206  // the value
207  ++value;
208  }
209 
210  return powerSetPtr;
211  }
212 
213 
214  template<typename PowerSet> static boost::shared_ptr<PowerSet> filterCardinalityPowerSet(const boost::shared_ptr<PowerSet> &powerSetPtr, const std::size_t min, const std::size_t max) {
215  boost::shared_ptr<PowerSet> resultPowerSetPtr(new PowerSet);
216 
217  for (typename PowerSet::iterator powerSetIter = powerSetPtr->begin(); powerSetIter != powerSetPtr->end(); ++powerSetIter) {
218  if ((*powerSetIter)->size() < min || (*powerSetIter)->size() > max) {
219  continue;
220  }
221 
222  resultPowerSetPtr->insert(*powerSetIter);
223  }
224 
225  return resultPowerSetPtr;
226  }
227 
228  template<typename PowerSet> static boost::shared_ptr<PowerSet> filterCardinalityPowerSet(const boost::shared_ptr<PowerSet> &setPtr, const std::size_t min) {
229  return filterCardinalityPowerSet<PowerSet>(setPtr, min, setPtr->size());
230  }
231  };
232 }
233 
234 
235 
236 #endif /* MYMATHHELPER_HPP_ */
static SimpleQuaternion getRandomQuaternion()
Definition: MathHelper.cpp:113
static void printPowerSet(boost::shared_ptr< std::set< boost::shared_ptr< Set > > > &powerSetPtr)
Definition: MathHelper.hpp:179
static SimpleVector3 convertS2C(const SimpleSphereCoordinates &sphere)
converts sphere coordinates to cartesian coordinates (lightweight)
Definition: MathHelper.cpp:41
static double degToRad(double input)
Definition: MathHelper.cpp:172
static boost::mt19937 & getRandomnessGenerator()
Definition: MathHelper.cpp:24
MathHelper unites the generally needed math operations.
Definition: MathHelper.hpp:44
static Precision getRandomNumber(const Precision &mean, const Precision &standardDeviation)
Definition: MathHelper.cpp:98
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:50
static double getSignum(const double &value)
Definition: MathHelper.cpp:63
static SimpleVector3 getVisualAxis(const SimpleQuaternion &orientation)
Definition: MathHelper.cpp:53
SimpleVector3 SimpleSphereCoordinates
Definition: typedef.hpp:51
static boost::shared_ptr< std::set< boost::shared_ptr< Set > > > powerSet(const boost::shared_ptr< Set > &setPtr)
Definition: MathHelper.hpp:188
static double radToDeg(double input)
Definition: MathHelper.cpp:168
static SimpleVector3 getProjection(const std::size_t &idx, const SimpleVector3 &X)
Definition: MathHelper.cpp:67
Eigen::Matrix< Precision, Eigen::Dynamic, 1 > SimpleVectorX
Definition: typedef.hpp:53
static boost::shared_ptr< PowerSet > filterCardinalityPowerSet(const boost::shared_ptr< PowerSet > &setPtr, const std::size_t min)
Definition: MathHelper.hpp:228
static Precision getCosinus(const SimpleVector3 &X, const SimpleVector3 &Y)
Definition: MathHelper.cpp:71
this namespace contains all generally usable classes.
Definition: DebugHelper.hpp:27
static SimpleVectorX getRandomVector(const SimpleVectorX &mean, const SimpleVectorX &standardDeviation)
Definition: MathHelper.cpp:104
static SimpleQuaternionCollectionPtr getOrientationsOnUnitSphere(const int &numberOfPoints)
Definition: MathHelper.cpp:136
static Precision getMinimumAngleDifference(const Precision &firstAngle, const Precision &secondAngle)
Definition: MathHelper.cpp:87
static SimpleSphereCoordinates convertC2S(const SimpleVector3 &cartesian)
converts cartesian coordinates to sphere coordinates
Definition: MathHelper.cpp:29
static int getRandomInteger(const int &min, const int &max)
Definition: MathHelper.cpp:92
static boost::shared_ptr< PowerSet > filterCardinalityPowerSet(const boost::shared_ptr< PowerSet > &powerSetPtr, const std::size_t min, const std::size_t max)
Definition: MathHelper.hpp:214
int min(int a, int b)
static Precision getAngle(const SimpleVector3 &X, const SimpleVector3 &Y)
Definition: MathHelper.cpp:81
static SimpleQuaternion getQuaternionByAngles(const Precision &heading, const Precision &attitude, const Precision &bank)
Definition: MathHelper.cpp:118
static double getDotProduct(SimpleVector3 v1, SimpleVector3 v2)
Definition: MathHelper.cpp:176
static void printSet(boost::shared_ptr< Set > &setPtr)
Definition: MathHelper.hpp:171
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:64


asr_robot_model_services
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:49:59