00001 /* 00002 * Angle.cpp 00003 * 00004 * Created on: Oct 27, 2011 00005 * Author: mriedel 00006 */ 00007 00008 #include <telekyb_base/Spaces/Angle.hpp> 00009 00010 #include <ros/ros.h> 00011 00012 #include <boost/lexical_cast.hpp> 00013 00014 namespace TELEKYB_NAMESPACE { 00015 00016 const double Angle::M_2PI=2.0*M_PI; /*for efficency*/ 00017 00018 double Angle::alDiff(const Angle &other) const { 00019 return normPi(other.theta - theta); 00020 } 00021 00022 double Angle::ccwDiff(const Angle &other) const { 00023 double otherTheta = theta <= other.theta ? other.theta : other.theta + 2.0*M_PI; 00024 return otherTheta - theta; 00025 } 00026 00027 double Angle::cwDiff(const Angle &other) const { 00028 double myTheta = theta >= other.theta ? theta : theta + 2.0*M_PI; 00029 return other.theta - myTheta; 00030 } 00031 00032 00033 //bool Angle::almostEqual(const Angle& A, const double& toll) const { 00034 // double ad = alDiff(A); 00035 // if ( doubleUtilities::equal(ad, 0.0, toll) ) return true; 00036 // return false; 00037 //} 00038 00039 Angle Angle::nearestMean(const Angle &other, double w1) const { 00040 if (w1 < 0.0 || w1>1.0 ){ 00041 ROS_FATAL("(Angle) Weight exceeds range in weigthedCcwMean."); 00042 //ROS_BREAK(); 00043 ros::shutdown(); 00044 } 00045 return Angle(theta + (1.0 - w1)*(alDiff(other))); 00046 } 00047 00048 Angle Angle::ccwMean(const Angle &other) const { 00049 if(other.theta == theta ){ 00050 return Angle(theta + M_PI); 00051 } 00052 double otherTheta = theta <= other.theta ? other.theta : other.theta + 2.0*M_PI; 00053 return Angle((otherTheta + theta)/2.0); 00054 } 00055 00056 Angle Angle::cwMean(const Angle &other) const { 00057 00058 double myTheta = theta >= other.theta ? theta : theta + 2.0*M_PI; 00059 return Angle((other.theta + myTheta)/2.0); 00060 } 00061 00062 00063 std::string Angle::toString(int precision) const { 00064 // stringstream s; 00065 // s.precision(precision); 00066 // s.setf(ios::fixed,ios::floatfield); 00067 // s << theta << " rad"; 00068 return std::string(boost::lexical_cast<std::string>(theta) + " rad"); 00069 } 00070 00071 }