CARMA C++
Angle.h
Go to the documentation of this file.
1 // $Id: Angle.h,v 1.26 2007/07/06 14:26:39 abeard Exp $
2 
14 #ifndef CARMA_SERVICES_ANGLE_H
15 #define CARMA_SERVICES_ANGLE_H
16 
18 #include <string>
19 #include <cmath>
20 
21 namespace carma {
22  namespace services {
38  class Angle : public ConformableQuantity {
39  public:
40 
45  explicit Angle( );
46 
52  explicit Angle(double value, const std::string& units);
53 
55  virtual ~Angle();
56 
65  double radians(bool modulo = true) const;
66 
75  double hours(bool modulo = true) const;
76 
85  double degrees(bool modulo = false) const;
86 
96  double arcMinutes(bool modulo = false) const;
97 
107  double arcSeconds(bool modulo = false) const;
108 
117  std::string dms(bool modulo = true, int precision = 0) const;
118 
124  inline void setRadians(double radians)
125  {
126  reset(radians,"radians");
127  }
134  const Angle operator+(const Angle& angle) const;
135 
142  const Angle operator-(const Angle& angle) const;
143 
147  friend const Angle operator*(double left, const Angle & right );
148  friend const Angle operator*(const Angle & left, double right );
149 
153  const Angle operator/(double scalar) const;
154 
161  Angle& operator+=(const Angle& angle);
162 
169  Angle& operator-=(const Angle& angle);
170 
174  Angle & operator*=(double scalar);
175 
179  Angle & operator/=(double scalar);
180 
184  bool operator<( const Angle & right ) const;
185 
189  bool operator>( const Angle & right ) const;
190 
194  bool operator<=( const Angle & right ) const;
195 
199  bool operator>=( const Angle & right ) const;
200 
206  static inline std::string getString(double angle, int precision=0)
207  {
208  return getAngleString(angle, precision, true, true);
209  }
210 
211  protected:
216  static const double twoPi_ = 2 * M_PIl;
217 
218  /*
219  * helper for Angle and HourAngle
220  * @return (+/-) hh:mm:ss or dd:mm:ss, value will be leading zero-filled.
221  * @param angle in radians
222  * @param precision number of digits after the decimal point
223  * @param dms true of dms, false is hms
224  * @param use the leading sign if positive
225  *
226  */
227  static std::string getAngleString(double a,
228  int precision=0,
229  bool dms=true,
230  bool useSign = false);
231 
232  public:
233 
238  static const std::string RADIANS_STR;
239 
244  static const std::string DEGREES_STR;
245 
250  static const std::string HOURS_STR;
251 
256  static const std::string ARCMIN_STR;
257 
262  static const std::string ARCSEC_STR;
263 
264  private:
265 
269  const Angle moduloTwoPi(double value) const;
270 
274  double moduloTwoPiDouble(double value) const;
275 
276  };
277 
281  std::ostream& operator<<(std::ostream& os,
282  const carma::services::Angle& angle);
283 
284 
285  const Angle operator*(double left, const Angle & right );
286  const Angle operator*(const Angle & left, double right );
287  }
288 }
289 
290 
291 #endif //CARMA_SERVICES_ANGLE_H
The ConformableQuantity class can represent any quantity that can be expressed in many units...
std::string dms(bool modulo=true, int precision=0) const
Angle & operator+=(const Angle &angle)
Add Angle.
const Angle operator-(const Angle &angle) const
Subtract two Angles.
bool operator<(const Angle &right) const
Less than comparison.
static std::string getString(double angle, int precision=0)
Return a zero filled string +/-ddd:mm:ss.s.
Definition: Angle.h:206
static const std::string RADIANS_STR
A const string that may be used for unit conversion.
Definition: Angle.h:238
double degrees(bool modulo=false) const
Convenience method that returns the value of this angle in degrees.
double arcMinutes(bool modulo=false) const
Convenience method that returns the value of this angle in arcminutes.
static const std::string ARCMIN_STR
A const string that may be used for unit conversion.
Definition: Angle.h:256
friend const Angle operator*(double left, const Angle &right)
Multiply an angle by a scalar.
bool operator<=(const Angle &right) const
Less than or equal comparison.
const Angle operator/(double scalar) const
Divide an angle by a scalar.
Angle & operator/=(double scalar)
Divide by a scalar.
void setRadians(double radians)
Set the value of this angle in radians.
Definition: Angle.h:124
Angle & operator-=(const Angle &angle)
Subtract Angle.
static const double twoPi_
Two pi.
Definition: Angle.h:216
const Angle operator+(const Angle &angle) const
Add two Angles.
Angle()
Default constructor.
static const std::string ARCSEC_STR
A const string that may be used for unit conversion.
Definition: Angle.h:262
The Angle class can represent any angle in any units.
Definition: Angle.h:38
Angle & operator*=(double scalar)
Multiply an angle by a scalar.
double arcSeconds(bool modulo=false) const
Convenience method that returns the value of this angle in arcseconds.
static const std::string DEGREES_STR
A const string that may be used for unit conversion.
Definition: Angle.h:244
static const std::string HOURS_STR
A const string that may be used for unit conversion.
Definition: Angle.h:250
Parent class for representations of quantities that can have conformable units, e.g.
std::ostream & operator<<(std::ostream &os, const carma::services::Angle &angle)
Define the &lt;&lt; operator to allow, e.g.
virtual ~Angle()
Destructor.
virtual void reset(double value, const std::string &units)
Reset method to change value and/or units.
bool operator>(const Angle &right) const
Greater than comparison.
double hours(bool modulo=true) const
Convenience method that returns the value of this angle in hours.
double radians(bool modulo=true) const
Convenience method that returns the value of this angle in radians.
bool operator>=(const Angle &right) const
Greater than or equal comparison.