MathHelper.hpp
Go to the documentation of this file.
00001 
00020 #ifndef MYMATHHELPER_HPP_
00021 #define MYMATHHELPER_HPP_
00022 
00023 #include "robot_model_services/typedef.hpp"
00024 #include <boost/math/special_functions/binomial.hpp>
00025 #include <boost/random/mersenne_twister.hpp>
00026 #include <boost/random/uniform_int.hpp>
00027 #include <boost/random/uniform_real.hpp>
00028 #include <boost/random/normal_distribution.hpp>
00029 #include <boost/random/variate_generator.hpp>
00030 #include <boost/foreach.hpp>
00031 #include <ros/ros.h>
00032 #include <set>
00033 #include <vector>
00034 #include <geometry_msgs/Quaternion.h>
00035 
00036 namespace robot_model_services {
00044         class MathHelper {
00045         private:
00049                 static boost::mt19937& getRandomnessGenerator();
00050         public:
00056                 static SimpleSphereCoordinates convertC2S(const SimpleVector3 &cartesian);
00057 
00063                 static void convertC2S(const SimpleVector3 &cartesian, SimpleSphereCoordinates &sphere);
00064 
00070                 static SimpleVector3 convertS2C(const SimpleSphereCoordinates &sphere);
00071 
00077                 static void convertS2C(const SimpleSphereCoordinates &sphere, SimpleVector3 &cartesian);
00078 
00079                 static SimpleVector3 getVisualAxis(const SimpleQuaternion &orientation);
00080 
00081                 static void getVisualAxis(const SimpleQuaternion &orientation, SimpleVector3 &resultAxis);
00082 
00087                 static double getSignum(const double &value);
00088 
00094                 static SimpleVector3 getProjection(const std::size_t &idx, const SimpleVector3 &X);
00095 
00101                 static Precision getCosinus(const SimpleVector3 &X, const SimpleVector3 &Y);
00102 
00108         static Precision getAngle(const SimpleVector3 &X, const SimpleVector3 &Y);
00109 
00115                 static Precision getMinimumAngleDifference(const Precision &firstAngle, const Precision &secondAngle);
00116 
00122                 static int getRandomInteger(const int &min, const int &max);
00123 
00129                 static Precision getRandomNumber(const Precision &mean, const Precision &standardDeviation);
00130 
00136                 static SimpleVectorX getRandomVector(const SimpleVectorX &mean, const SimpleVectorX &standardDeviation);
00137 
00141                 static SimpleQuaternion getRandomQuaternion();
00142 
00149                 static SimpleQuaternion getQuaternionByAngles(const Precision &heading, const Precision &attitude, const Precision &bank);
00150 
00155                 static SimpleQuaternionCollectionPtr getOrientationsOnUnitSphere(const int &numberOfPoints);
00156 
00161                 static double radToDeg(double input);
00162 
00167                 static double degToRad(double input);
00168 
00169                 static double getDotProduct(SimpleVector3 v1, SimpleVector3 v2);
00170 
00171                 template<typename Set> static void printSet(boost::shared_ptr<Set> &setPtr) {
00172                         std::cout << "\t{ ";
00173                         BOOST_FOREACH(typename Set::value_type value, *setPtr) {
00174                                 std::cout << value << ", ";
00175                         }
00176                         std::cout << "}" << std::endl;
00177                 }
00178 
00179                 template<typename Set> static void printPowerSet(boost::shared_ptr<std::set<boost::shared_ptr<Set> > > &powerSetPtr) {
00180                         std::cout << "{ " << std::endl;
00181                         BOOST_FOREACH(boost::shared_ptr<Set> subSetPtr, *powerSetPtr) {
00182                                 printSet(subSetPtr);
00183                         }
00184                         std::cout << "} " << std::endl;
00185                         std::cout << powerSetPtr->size() << " Items" << std::endl;
00186                 }
00187 
00188                 template<typename Set> static boost::shared_ptr<std::set<boost::shared_ptr<Set> > > powerSet(const boost::shared_ptr<Set> &setPtr) {
00189                         boost::shared_ptr<std::set<boost::shared_ptr<Set> > > powerSetPtr(new std::set<boost::shared_ptr<Set> >);
00190 
00191                         std::size_t value = 0;
00192                         assert(setPtr->size() <= 31);
00193 
00194 
00195                         std::size_t limit = (1 << setPtr->size());
00196                         for (std::size_t counter = 0; counter < limit; ++counter) {
00197                                 boost::shared_ptr<Set> subSetPtr(new Set);
00198                                 std::size_t idx = 0;
00199                                 for (typename Set::iterator setIter = setPtr->begin(); setIter != setPtr->end();  ++setIter, ++idx) {
00200                                         if ( (value & (1 << idx)) != 0 ) {
00201                                                 subSetPtr->insert(*setIter);
00202                                         }
00203                                 }
00204                                 powerSetPtr->insert(subSetPtr);
00205 
00206                                 // the value
00207                                 ++value;
00208                         }
00209 
00210                         return powerSetPtr;
00211                 }
00212 
00213 
00214                 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) {
00215                         boost::shared_ptr<PowerSet> resultPowerSetPtr(new PowerSet);
00216 
00217                         for (typename PowerSet::iterator powerSetIter = powerSetPtr->begin(); powerSetIter != powerSetPtr->end(); ++powerSetIter) {
00218                                 if ((*powerSetIter)->size() < min || (*powerSetIter)->size() > max) {
00219                                         continue;
00220                                 }
00221 
00222                                 resultPowerSetPtr->insert(*powerSetIter);
00223                         }
00224 
00225                         return resultPowerSetPtr;
00226                 }
00227 
00228                 template<typename PowerSet> static boost::shared_ptr<PowerSet> filterCardinalityPowerSet(const boost::shared_ptr<PowerSet> &setPtr, const std::size_t min) {
00229                         return filterCardinalityPowerSet<PowerSet>(setPtr, min, setPtr->size());
00230                 }
00231         };
00232 }
00233 
00234 
00235 
00236 #endif /* MYMATHHELPER_HPP_ */


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 Sat Jun 8 2019 18:24:52