Angle.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: Angle class
00018  * Author: Nate Koenig
00019  * Date: 18 Aug 2008
00020  */
00021 
00022 #ifndef ANGLE_HH
00023 #define ANGLE_HH
00024 
00025 #include <iostream>
00026 #include <math.h>
00027 
00028 // Convert radians to degrees
00029 #define GZ_RTOD(r) ((r) * 180 / M_PI)
00030 
00031 // Convert degrees to radians
00032 #define GZ_DTOR(d) ((d) * M_PI / 180)
00033 
00034 // Normalize an angle in the range -Pi to Pi
00035 #define GZ_NORMALIZE(a) (atan2(sin(a), cos(a)))
00036 
00037 namespace gazebo
00038 {
00039 
00042   namespace math
00043   {
00044 
00049   
00051   class Angle
00052   {
00054     public: Angle();
00055 
00058     public: Angle(double _radian);
00059 
00062     public: Angle(const Angle &angle);
00063   
00065     public: virtual ~Angle();
00066   
00069     public: void SetFromRadian( double _radian );
00070   
00073     public: void SetFromDegree( double degree );
00074   
00077     public: double GetAsRadian() const;
00078   
00081     public: double GetAsDegree() const;
00082 
00084     public: void Normalize();
00085 
00088     public: inline double operator*() const { return value; }
00089 
00093     public: Angle operator-(const Angle &_angle) const;
00094 
00098     public: Angle operator+(const Angle &_angle) const;
00099 
00103     public: Angle operator*(const Angle &_angle) const;
00104 
00108     public: Angle operator/(const Angle &_angle) const;
00109 
00113     public: Angle operator-=(const Angle &_angle);
00114 
00118     public: Angle operator+=(const Angle &_angle);
00119 
00123     public: Angle operator*=(const Angle &_angle);
00124 
00128     public: Angle operator/=(const Angle &_angle);
00129 
00133     public: bool operator==(const Angle &_angle) const;
00134 
00138     public: bool operator!=(const Angle &_angle) const;
00139 
00143     public: bool operator<(const Angle &_angle) const;
00144 
00148     public: bool operator<=(const Angle &_angle) const;
00149 
00153     public: bool operator>(const Angle &_angle) const;
00154 
00158     public: bool operator>=(const Angle &_angle) const;
00159 
00164     public: friend std::ostream &operator<<( std::ostream &out, const gazebo::math::Angle &a )
00165     {
00166       out << a.GetAsRadian();
00167       return out;
00168     }
00169   
00174     public: friend std::istream &operator>>( std::istream &in, gazebo::math::Angle &a )
00175     {
00176       // Skip white spaces
00177       in.setf( std::ios_base::skipws );
00178       in >> a.value;
00179       return in;
00180     }
00181   
00183     private: double value;
00184   };
00185     
00187   }
00188 }
00189 
00190 #endif