dms Class Reference
An angle, stored as degrees, but expressible in many ways.
More...
#include <dms.h>
List of all members.
|
Public Member Functions |
const int | arcmin () const |
const int | arcsec () const |
const double & | cos (void) const |
const int | degree () const |
const double & | Degrees () const |
| dms (const QString &s, bool isDeg=true) |
| dms (const double &x) |
| dms (const int &d=0, const int &m=0, const int &s=0, const int &ms=0) |
const int | hour () const |
const double | Hours () const |
const int | marcsec () const |
const int | minute () const |
const int | msecond () const |
const double & | radians (void) const |
const dms | reduce (void) const |
const int | second () const |
void | set (const double &d) |
void | set (const dms &d) |
void | setArcMin (const int &m) |
void | setArcSec (const int &s) |
void | setD (const int &d, const int &m, const int &s, const int &ms=0) |
void | setD (const double &x) |
void | setDeg (const int &d) |
bool | setFromString (const QString &s, bool isDeg=true) |
void | setH (const int &h, const int &m, const int &s, const int &ms=0) |
void | setH (const double &x) |
void | setHMin (const int &m) |
void | setHour (const int &h) |
void | setHSec (const int &s) |
void | setRadians (const double &a) |
const double & | sin (void) const |
void | SinCos (double &s, double &c) const |
const QString | toDMSString (const bool forceSign=false) const |
const QString | toHMSString () const |
| ~dms () |
Static Public Member Functions |
static dms | fromString (QString &s, bool deg) |
Static Public Attributes |
static const double | DegToRad = PI/180.0 |
static const double | PI = M_PI |
Detailed Description
An angle, stored as degrees, but expressible in many ways.
- Author:
- Jason Harris
- Version:
- 1.0
dms encapsulates an angle. The angle is stored as a double, equal to the value of the angle in degrees. Methods are available for setting/getting the angle as a floating-point measured in Degrees or Hours, or as integer triplets (degrees, arcminutes, arcseconds or hours, minutes, seconds). There is also a method to set the angle according to a radian value, and to return the angle expressed in radians. Finally, a
SinCos() method computes the sin and cosine of the angle. Once computed, the sin and cos values are stored, so that subsequent
SinCos() calls will be faster.
Definition at line 46 of file dms.h.
Constructor & Destructor Documentation
dms::dms |
( |
const int & |
d = 0 , |
|
|
const int & |
m = 0 , |
|
|
const int & |
s = 0 , |
|
|
const int & |
ms = 0 | |
|
) |
| | [inline] |
Default Constructor.
Set the floating-point value of the angle according to the four integer arguments.
- Parameters:
-
| d | degree portion of angle (int). Defaults to zero. |
| m | arcminute portion of angle (int). Defaults to zero. |
| s | arcsecond portion of angle (int). Defaults to zero. |
| ms | arcsecond portion of angle (int). Defaults to zero. |
Definition at line 56 of file dms.h.
dms::dms |
( |
const double & |
x |
) |
[inline] |
Construct an angle from a double value.
Creates an angle whose value in Degrees is equal to the argument.
- Parameters:
-
| x | angle expressed as a floating-point number (in degrees) |
Definition at line 63 of file dms.h.
dms::dms |
( |
const QString & |
s, |
|
|
bool |
isDeg = true | |
|
) |
| | [inline] |
Construct an angle from a string representation.
Attempt to create the angle according to the string argument. If the string cannot be parsed as an angle value, the angle is set to zero.
- Warning:
- There is not an unambiguous notification that it failed to parse the string, since the string could have been a valid representation of zero degrees. If this is a concern, use the setFromString() function directly instead.
- Parameters:
-
| s | the string to parse as a dms value. |
| isDeg | if true, value is in degrees; if false, value is in hours. |
- See also:
- setFromString()
Definition at line 78 of file dms.h.
Destructor (empty).
Definition at line 82 of file dms.h.
Member Function Documentation
const int dms::arcmin |
( |
void |
|
) |
const |
- Returns:
- integer arcminutes portion of the angle.
- Note:
- an arcminute is 1/60 degree.
Definition at line 168 of file dms.cpp.
const int dms::arcsec |
( |
void |
|
) |
const |
- Returns:
- integer arcseconds portion of the angle
- Note:
- an arcsecond is 1/60 arcmin, or 1/3600 degree.
Definition at line 176 of file dms.cpp.
const double & dms::cos |
( |
void |
|
) |
const |
Compute the Angle's Cosine.
If the Sine/Cosine values have already been computed, then this function simply returns the stored value. Otherwise, it will compute and store the values first.
- Returns:
- the Cosine of the angle.
- See also:
- sin()
Definition at line 227 of file dms.cpp.
const int dms::degree |
( |
|
) |
const [inline] |
- Returns:
- integer degrees portion of the angle
Definition at line 86 of file dms.h.
const double& dms::Degrees |
( |
|
) |
const [inline] |
- Returns:
- angle in degrees expressed as a double.
Definition at line 105 of file dms.h.
dms dms::fromString |
( |
QString & |
s, |
|
|
bool |
deg | |
|
) |
| | [static] |
Static function to create a DMS object from a QString.
There are several ways to specify the angle:
- Integer numbers ( 5 or -33 )
- Floating-point numbers ( 5.0 or -33.0 )
- colon-delimited integers ( 5:0:0 or -33:0:0 )
- colon-delimited with float seconds ( 5:0:0.0 or -33:0:0.0 )
- colon-delimited with float minutes ( 5:0.0 or -33:0.0 )
- space-delimited ( 5 0 0; -33 0 0 ) or ( 5 0.0 or -33 0.0 )
- space-delimited, with unit labels ( 5h 0m 0s or -33d 0m 0s )
- Parameters:
-
| s | the string to be parsed as an angle value |
| deg | if TRUE, s is expressed in degrees; if FALSE, s is expressed in hours |
- Returns:
- a dms object whose value is parsed from the string argument
Definition at line 302 of file dms.cpp.
const int dms::hour |
( |
|
) |
const [inline] |
- Returns:
- integer hours portion of the angle
- Note:
- an angle can be measured in degrees/arcminutes/arcseconds or hours/minutes/seconds. An hour is equal to 15 degrees.
Definition at line 111 of file dms.h.
const double dms::Hours |
( |
|
) |
const [inline] |
- Returns:
- angle in hours expressed as a double.
- Note:
- an angle can be measured in degrees/arcminutes/arcseconds or hours/minutes/seconds. An hour is equal to 15 degrees.
Definition at line 132 of file dms.h.
const int dms::marcsec |
( |
void |
|
) |
const |
- Returns:
- integer milliarcseconds portion of the angle
- Note:
- a milliarcsecond is 1/1000 arcsecond.
Definition at line 185 of file dms.cpp.
const int dms::minute |
( |
void |
|
) |
const |
- Returns:
- integer minutes portion of the angle
- Note:
- a minute is 1/60 hour (not the same as an arcminute)
Definition at line 194 of file dms.cpp.
const int dms::msecond |
( |
void |
|
) |
const |
- Returns:
- integer milliseconds portion of the angle
- Note:
- a millisecond is 1/1000 second (not the same as a milliarcsecond)
Definition at line 210 of file dms.cpp.
const double & dms::radians |
( |
void |
|
) |
const |
Express the angle in radians.
The computed Radians value is stored internally. On subsequent calls, the stored value is returned directly (unless the angle's value has changed).
- Returns:
- the angle in radians (double)
Definition at line 264 of file dms.cpp.
const dms dms::reduce |
( |
void |
|
) |
const |
return the equivalent angle between 0 and 360 degrees.
- Warning:
- does not change the value of the parent angle itself.
Definition at line 273 of file dms.cpp.
const int dms::second |
( |
void |
|
) |
const |
- Returns:
- integer seconds portion of the angle
- Note:
- a second is 1/3600 hour (not the same as an arcsecond)
Definition at line 202 of file dms.cpp.
void dms::set |
( |
const double & |
d |
) |
[inline] |
Copy value of another dms angle.
Differs from above function only in argument type. Identical to setD(double d).
- Parameters:
-
| d | set angle according to this double value |
- See also:
- setD()
Definition at line 227 of file dms.h.
void dms::set |
( |
const dms & |
d |
) |
[inline] |
Copy value of another dms angle.
- Parameters:
-
| d | set angle according to this dms object |
Definition at line 220 of file dms.h.
void dms::setArcMin |
( |
const int & |
m |
) |
[inline] |
Sets integer arcminutes portion of angle, leaving the degrees and arcsecond values intact.
- Parameters:
-
| m | new integer arcminutes value |
Definition at line 144 of file dms.h.
void dms::setArcSec |
( |
const int & |
s |
) |
[inline] |
Sets integer arcseconds portion of angle, leaving the degrees and arcminute values intact.
- Parameters:
-
| s | new integer arcseconds value |
Definition at line 150 of file dms.h.
void dms::setD |
( |
const int & |
d, |
|
|
const int & |
m, |
|
|
const int & |
s, |
|
|
const int & |
ms = 0 | |
|
) |
| | |
Sets floating-point value of angle, in degrees.
This is an overloaded member function; it behaves essentially like the above function. The floating-point value of the angle (D) is determined from the following formulae:

- Parameters:
-
| d | integer degrees portion of angle |
| m | integer arcminutes portion of angle |
| s | integer arcseconds portion of angle |
| ms | integer arcseconds portion of angle |
Definition at line 31 of file dms.cpp.
void dms::setD |
( |
const double & |
x |
) |
|
Sets floating-point value of angle, in degrees.
- Parameters:
-
Definition at line 25 of file dms.cpp.
void dms::setDeg |
( |
const int & |
d |
) |
[inline] |
Sets integer degrees portion of angle, leaving the arcminute and arcsecond values intact.
- Parameters:
-
| d | new integer degrees value |
Definition at line 138 of file dms.h.
bool dms::setFromString |
( |
const QString & |
s, |
|
|
bool |
isDeg = true | |
|
) |
| | |
Attempt to parse the string argument as a dms value, and set the dms object accordingly.
- Parameters:
-
| s | the string to be parsed as a dms value. The string can be an int or floating-point value, or a triplet of values (d/h, m, s) separated by spaces or colons. |
| isDeg | if true, the value is in degrees. Otherwise, it is in hours. |
- Returns:
- true if sting was parsed successfully. Otherwise, set the dms value to 0.0 and return false.
Definition at line 54 of file dms.cpp.
void dms::setH |
( |
const int & |
h, |
|
|
const int & |
m, |
|
|
const int & |
s, |
|
|
const int & |
ms = 0 | |
|
) |
| | |
Sets floating-point value of angle, in hours.
Converts argument values from hours to degrees, then sets floating-point value of angle, in degrees. This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
- Parameters:
-
| h | integer hours portion of angle |
| m | integer minutes portion of angle |
| s | integer seconds portion of angle |
| ms | integer milliseconds portion of angle |
- See also:
- setD()
Definition at line 42 of file dms.cpp.
void dms::setH |
( |
const double & |
x |
) |
|
Sets floating-point value of angle, in hours.
Converts argument from hours to degrees, then sets floating-point value of angle, in degrees.
- Parameters:
-
| x | new angle, in hours (double) |
- See also:
- setD()
Definition at line 38 of file dms.cpp.
void dms::setHMin |
( |
const int & |
m |
) |
[inline] |
Sets integer minutes portion of angle, leaving the hours and seconds values intact.
- Parameters:
-
| m | new integer minutes value |
- See also:
- setArcMin()
Definition at line 185 of file dms.h.
void dms::setHour |
( |
const int & |
h |
) |
[inline] |
Sets integer hours portion of angle, leaving the minutes and seconds values intact.
- Parameters:
-
| h | new integer hours value |
- See also:
- setH() setDeg()
Definition at line 178 of file dms.h.
void dms::setHSec |
( |
const int & |
s |
) |
[inline] |
Sets integer seconds portion of angle, leaving the hours and minutes values intact.
- Parameters:
-
| s | new integer seconds value |
- See also:
- setArcSec()
Definition at line 192 of file dms.h.
void dms::setRadians |
( |
const double & |
a |
) |
|
Set angle according to the argument, in radians.
This function converts the argument to degrees, then sets the angle with setD().
- Parameters:
-
Definition at line 49 of file dms.cpp.
const double & dms::sin |
( |
void |
|
) |
const |
Compute the Angle's Sine.
If the Sine/Cosine values have already been computed, then this function simply returns the stored value. Otherwise, it will compute and store the values first.
- Returns:
- the Sine of the angle.
- See also:
- cos()
Definition at line 218 of file dms.cpp.
void dms::SinCos |
( |
double & |
s, |
|
|
double & |
c | |
|
) |
| | const |
Addition operator.
Add two dms objects.
- Parameters:
-
- Returns:
- sum of two angles, in a dms object Subtraction operator. Subtract two dms objects.
- Parameters:
-
| d | subtract from current angle |
- Returns:
- difference of two angles, in a dms object Assignment operator. Assign value of argument to current angle. I wanted to pass the argument by reference, but I couldn't figure out a good way to do it without generating an error or warning message.
- Parameters:
-
| a | dms object to get angle value from |
- Returns:
- dms object, copy of argument. Assignment operator. Assign value of argument to current angle.
- Parameters:
-
| d | floating-point number to get angle value from |
- Returns:
- dms object, same value as argument.Compute Sine and Cosine of the angle simultaneously. On machines using glibc >= 2.1, calling SinCos() is somewhat faster than calling sin() and cos() separately. The values are returned through the arguments (passed by reference). The Sin and Cos values are stored internally; on subsequent calls to SinCos(), the stored values are returned directly (unless the angle's value has changed).
- Parameters:
-
| s | Sine of the angle |
| c | Cosine of the angle |
- See also:
- sin() cos()
We have two versions of this function. One is ANSI standard, but slower. The other is faster, but is GNU only. Using the __GLIBC_ and __GLIBC_MINOR_ constants to determine if the GNU extension sincos() is defined.
Definition at line 236 of file dms.cpp.
const QString dms::toDMSString |
( |
const bool |
forceSign = false |
) |
const |
- Returns:
- a nicely-formatted string representation of the angle in degrees, arcminutes, and arcseconds.
Definition at line 280 of file dms.cpp.
const QString dms::toHMSString |
( |
|
) |
const |
- Returns:
- a nicely-formatted string representation of the angle in hours, minutes, and seconds.
Definition at line 297 of file dms.cpp.
Member Data Documentation
DegToRad is a const static member equal to the number of radians in one degree (dms::PI/180.0).
Definition at line 338 of file dms.h.
const double dms::PI = M_PI [static] |
PI is a const static member; it's public so that it can be used anywhere, as long as dms.h is included.
Definition at line 333 of file dms.h.
The documentation for this class was generated from the following files: