Isis 3.0 Programmer Reference
Back | Home
Angle.cpp
Go to the documentation of this file.
1 
22 #include "Angle.h"
23 
24 #include <cmath>
25 
26 #include <QDebug>
27 
28 #include "Constants.h"
29 #include "IString.h"
30 #include "IException.h"
31 #include "SpecialPixel.h"
32 
33 namespace Isis {
39  m_radians = Null;
40  }
41 
48  Angle::Angle(double angle, Units unit) {
49  setAngle(angle, unit);
50  }
51 
52 
58  Angle::Angle(const Angle& fromAngle) {
59  m_radians = fromAngle.m_radians;
60  }
61 
62 
69  Angle::Angle(QString angle) {
70  QString::SectionFlag flag = QString::SectionSkipEmpty;
71  bool degreesSucceeded, minutesSucceeded, secondsSucceeded;
72 
73  double degrees = angle.section(' ', 0, 0, flag).toDouble(&degreesSucceeded);
74  double minutes = angle.section(' ', 1, 1, flag).toDouble(&minutesSucceeded);
75  double seconds = angle.section(' ', 2, 2, flag).toDouble(&secondsSucceeded);
76 
77  if (!(degreesSucceeded && minutesSucceeded && secondsSucceeded) ) {
78  QString msg = QObject::tr("[%1] is not a vaid input to Angle. It needs to be of the form: "
79  "\"dd mm ss.ss\"").arg(angle);
81  }
82 
83  //if the first digit is '-', everything should be negative
84  if (degrees < 0) {
85  minutes = -minutes;
86  seconds = -seconds;
87  }
88 
89  double decimalDegrees = degrees + minutes/60.0 + seconds/3600.0;
90  setAngle(decimalDegrees, Angle::Degrees);
91  }
92 
93 
99  // Help prevent any accidental reuse of an Angle object
100  m_radians = Null;
101  }
102 
103 
110  bool Angle::isValid() const {
111  return m_radians != Isis::Null; // returns false if the value is Null or any other special value
112 // return IsValidPixel(m_radians); // returns false if the value is Null or any other special value
113  }
114 
115 
122  return Angle(360, Degrees);
123  }
124 
125 
133  Angle Angle::operator+(const Angle& angle2) const {
134  if(!isValid() || !angle2.isValid()) return Angle();
135 
136  double ourAngle = radians();
137  double otherAngle = angle2.radians();
138 
139  return Angle(ourAngle + otherAngle, Radians);
140  }
141 
142 
151  Angle Angle::operator-(const Angle& angle2) const {
152  if(!isValid() || !angle2.isValid()) return Angle();
153 
154  double ourAngle = radians();
155  double otherAngle = angle2.radians();
156 
157  return Angle(ourAngle - otherAngle, Radians);
158  }
159 
160 
169  Angle Angle::operator*(double value) const {
170  if(!isValid()) return Angle();
171 
172  return Angle(radians() * value, Radians);
173  }
174 
175 
185  Angle operator *(double mult, Angle angle) {
186  return angle * mult;
187  }
188 
189 
196  Angle Angle::operator/(double value) const {
197  if(!isValid()) return Angle();
198 
199  return Angle(radians() / value, Radians);
200  }
201 
202 
209  double Angle::operator/(Angle value) const {
210  if(!isValid() || !value.isValid()) return Null;
211 
212  return radians() / value.radians();
213  }
214 
215 
223  bool Angle::operator<(const Angle& angle2) const {
224  if(!isValid() || !angle2.isValid()) {
225  IString msg = "Cannot compare a invalid angles with the < operator";
227  }
228 
229  return (angle(Radians) < angle2.angle(Radians)) && *this != angle2;
230  }
231 
232 
240  bool Angle::operator>(const Angle& angle2) const {
241  if(!isValid() || !angle2.isValid()) {
242  IString msg = "Cannot compare a invalid angles with the > operator";
244  }
245 
246  return (angle(Radians) > angle2.angle(Radians)) && *this != angle2;
247  }
248 
249 
256  QString Angle::toString(bool includeUnits) const {
257  QString textResult = "";
258 
259  if (isValid()) {
260  textResult = Isis::toString(degrees());
261 
262  if (includeUnits)
263  textResult += " degrees";
264  }
265 
266  return textResult;
267  }
268 
269 
279  double Angle::unitWrapValue(const Units& unit) const {
280  switch (unit) {
281  case Radians:
282  return PI * 2.;
283  break;
284 
285  case Degrees:
286  return 360.;
287  break;
288  }
289 
290  IString msg = "Angle can not interpret the enumerated value [" +
291  IString(unit) + "] as a unit";
293  }
294 
295 
302  double Angle::angle(const Units& unit) const {
303  // Don't do math on special pixels
304  if(m_radians == Null) {
305  return Null;
306  }
307 
308  double angleValue = Null;
309 
310  switch (unit) {
311  case Radians:
312  angleValue = m_radians;
313  break;
314 
315  case Degrees:
316  angleValue = m_radians * RAD2DEG;
317  break;
318  }
319 
320  if(angleValue == Null) {
321  IString msg = "Angle can not interpret the enumerated value [" +
322  IString(unit) + "] as a unit";
324  }
325 
326  return angleValue;
327  }
328 
329 
336  void Angle::setAngle(const double &angle,const Units& unit) {
337  // Don't allow non-Null special pixels, Null means no value
338  if (IsSpecial(angle) && angle != Null) {
339  IString msg = "Angle cannot be a non-Null special pixel";
341  }
342 
343  // Don't do math on special pixels
344  if(angle == Null) {
345  m_radians = Null;
346  return;
347  }
348 
349  switch (unit) {
350  case Radians:
351  m_radians = angle;
352  break;
353 
354  case Degrees:
355  m_radians = angle * DEG2RAD;
356  break;
357 
358  default:
359  IString msg = "Angle can not interpret the enumerated value [" +
360  IString(unit) + "] as a unit";
362  }
363  }
364 
365 }
366 
367 
379 QDebug operator<<(QDebug dbg, const Isis::Angle &angleToPrint) {
380  dbg.nospace() << angleToPrint.radians() << " <radians> ("
381  << angleToPrint.degrees() << " <degrees>)";
382 
383  return dbg.space();
384 }
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:109
Units
The set of usable angle measurement units.
Definition: Angle.h:62
Angle operator-(const Angle &angle2) const
Subtract angle value from another and return the resulting angle.
Definition: Angle.cpp:151
double degrees() const
Get the angle in units of Degrees.
Definition: Angle.h:245
double radians() const
Convert an angle to a double.
Definition: Angle.h:239
virtual void setAngle(const double &angle, const Units &unit)
Set angle value in desired units.
Definition: Angle.cpp:336
const double PI(3.14159265358979323846)
The mathematical constant PI.
const double DEG2RAD(0.017453292519943295769237)
Multiplier for converting from degrees to radians.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
Angle operator*(double mult, Angle angle)
Multiply this angle by a double and return the resulting angle.
Definition: Angle.cpp:185
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
QDebug operator<<(QDebug dbg, const Isis::Angle &angleToPrint)
Display an Angle for a debugging statement.
Definition: Angle.cpp:379
Angle operator/(double value) const
Divide this angle by a double.
Definition: Angle.cpp:196
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Definition: Angle.h:69
virtual QString toString(bool includeUnits=true) const
Get the angle in human-readable form.
Definition: Angle.cpp:256
Angle()
Constructs a blank angle object which needs a value to be set in order to do any calculations.
Definition: Angle.cpp:38
Angle operator*(double value) const
Multiply this angle by a double and return the resulting angle.
Definition: Angle.cpp:169
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
Angle operator+(const Angle &angle2) const
Add angle value to another.
Definition: Angle.cpp:133
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:199
bool isValid() const
This indicates whether we have a legitimate angle stored or are in an unset, or invalid, state.
Definition: Angle.cpp:110
static Angle fullRotation()
Makes an angle to represent a full rotation (0-360 or 0-2pi).
Definition: Angle.cpp:121
double unitWrapValue(const Units &unit) const
Return wrap value in desired units.
Definition: Angle.cpp:279
Defines an angle and provides unit conversions.
Definition: Angle.h:58
bool operator<(const Angle &angle2) const
Test if the other angle is less than the current angle.
Definition: Angle.cpp:223
virtual ~Angle()
Destroys the angle object.
Definition: Angle.cpp:98
Isis exception class.
Definition: IException.h:99
Adds specific functionality to C++ strings.
Definition: IString.h:179
bool operator>(const Angle &angle2) const
Test if the other angle is greater than the current angle.
Definition: Angle.cpp:240
Radians are generally used in mathematical equations, 0-2*PI is one circle, however these are more di...
Definition: Angle.h:76
virtual double angle(const Units &unit) const
Return angle value in desired units.
Definition: Angle.cpp:302
const double RAD2DEG(57.29577951308232087679815481)
Multiplier for converting from radians to degrees.
double m_radians
The angle measure, always stored in radians.
Definition: Angle.h:273

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:14:11