dms

Search for usage in LXR

#include <dms.h>

Inheritance diagram for dms:

Public Types

enum  AngleRanges { ZERO_TO_2PI , MINUSPI_TO_PI }
 

Public Member Functions

 dms ()
 
 dms (const double &x)
 
 dms (const int &d, const int &m=0, const int &s=0, const int &ms=0)
 
 dms (const QString &s, bool isDeg=true)
 
virtual ~dms ()=default
 
int arcmin () const
 
int arcsec () const
 
double cos () const
 
int degree () const
 
const double & Degrees () const
 
const dms deltaAngle (dms angle) const
 
int hour () const
 
double Hours () const
 
double HoursHa () const
 
int marcsec () const
 
int minute () const
 
int msecond () const
 
dms operator- ()
 
double radians () const
 
const dms reduce () const
 
void reduceToRange (enum dms::AngleRanges range)
 
int second () const
 
virtual void setD (const double &x)
 
virtual void setD (const int &d, const int &m, const int &s, const int &ms=0)
 
virtual bool setFromString (const QString &s, bool isDeg=true)
 
virtual void setH (const double &x)
 
virtual void setH (const int &h, const int &m, const int &s, const int &ms=0)
 
virtual void setRadians (const double &Rad)
 
double sin () const
 
void SinCos (double &s, double &c) const
 
double tan () const
 
const QString toDMSString (const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
 
const QString toHMSString (const bool machineReadable=false, const bool highPrecision=false) const
 

Static Public Member Functions

static dms fromString (const QString &s, bool deg)
 
static double reduce (const double D)
 

Static Public Attributes

static constexpr double DegToRad = { M_PI / 180.0 }
 
static constexpr double PI = { M_PI }
 

Protected Attributes

double D
 

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.

Definition at line 37 of file dms.h.

Member Enumeration Documentation

◆ AngleRanges

an enum defining standard angle ranges

Definition at line 356 of file dms.h.

Constructor & Destructor Documentation

◆ dms() [1/4]

dms::dms ( )
inline

Default constructor.

Definition at line 41 of file dms.h.

◆ ~dms()

virtual dms::~dms ( )
virtualdefault

Empty virtual destructor.

◆ dms() [2/4]

dms::dms ( const int & d,
const int & m = 0,
const int & s = 0,
const int & ms = 0 )
inlineexplicit

Set the floating-point value of the angle according to the four integer arguments.

Parameters
ddegree portion of angle (int). Defaults to zero.
marcminute portion of angle (int). Defaults to zero.
sarcsecond portion of angle (int). Defaults to zero.
msarcsecond portion of angle (int). Defaults to zero.

Definition at line 62 of file dms.h.

◆ dms() [3/4]

dms::dms ( const double & x)
inlineexplicit

Construct an angle from a double value.

Creates an angle whose value in Degrees is equal to the argument.

Parameters
xangle expressed as a floating-point number (in degrees)

Definition at line 78 of file dms.h.

◆ dms() [4/4]

dms::dms ( const QString & s,
bool isDeg = true )
inlineexplicit

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
sthe string to parse as a dms value.
isDegif true, value is in degrees; if false, value is in hours.
See also
setFromString()

Definition at line 103 of file dms.h.

Member Function Documentation

◆ arcmin()

int dms::arcmin ( void ) const
Returns
integer arcminutes portion of the angle.
Note
an arcminute is 1/60 degree.

Definition at line 180 of file dms.cpp.

◆ arcsec()

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 193 of file dms.cpp.

◆ cos()

double dms::cos ( ) const
inline

Compute the Angle's Cosine.

Returns
the Cosine of the angle.
See also
sin()

Definition at line 290 of file dms.h.

◆ degree()

int dms::degree ( ) const
inline
Returns
integer degrees portion of the angle

Definition at line 116 of file dms.h.

◆ Degrees()

const double & dms::Degrees ( ) const
inline
Returns
angle in degrees expressed as a double.

Definition at line 141 of file dms.h.

◆ deltaAngle()

const dms dms::deltaAngle ( dms angle) const

deltaAngle Return the shortest difference (path) between this angle and the supplied angle.

The range is normalized to [-180,+180]

Parameters
angleAngle to subtract from current angle.
Returns
Normalized angle in the range [-180,+180]

Definition at line 267 of file dms.cpp.

◆ fromString()

dms dms::fromString ( const 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
    sthe string to be parsed as an angle value
    degif 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 429 of file dms.cpp.

◆ hour()

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 147 of file dms.h.

◆ Hours()

double dms::Hours ( ) const
inline
Returns
angle in hours expressed as a double in the range 0 to 23.999...
Note
an angle can be measured in degrees/arcminutes/arcseconds or hours/minutes/seconds. An hour is equal to 15 degrees.

Definition at line 168 of file dms.h.

◆ HoursHa()

double dms::HoursHa ( ) const
inline
Returns
angle in hours expressed as a double in the range -11.999 to 0 to 12.0
Note
an angle can be measured in degrees/arcminutes/arcseconds or hours/minutes/seconds. An hour is equal to 15 degrees.

Definition at line 174 of file dms.h.

◆ marcsec()

int dms::marcsec ( void ) const
Returns
integer milliarcseconds portion of the angle
Note
a milliarcsecond is 1/1000 arcsecond.

Definition at line 207 of file dms.cpp.

◆ minute()

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 221 of file dms.cpp.

◆ msecond()

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 241 of file dms.cpp.

◆ operator-()

dms dms::operator- ( )
inline

Definition at line 411 of file dms.h.

◆ radians()

double dms::radians ( ) const
inline

Express the angle in radians.

Returns
the angle in radians (double)

Definition at line 325 of file dms.h.

◆ reduce() [1/2]

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 251 of file dms.cpp.

◆ reduce() [2/2]

double dms::reduce ( const double D)
static

Reduce an angle in degrees expressed as a double.

Definition at line 259 of file dms.cpp.

◆ reduceToRange()

void dms::reduceToRange ( enum dms::AngleRanges range)

Reduce this angle to the given range.

Definition at line 446 of file dms.cpp.

◆ second()

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 231 of file dms.cpp.

◆ setD() [1/2]

virtual void dms::setD ( const double & x)
inlinevirtual

Sets floating-point value of angle, in degrees.

Parameters
xnew angle (double)

Reimplemented in CachingDms.

Definition at line 179 of file dms.h.

◆ setD() [2/2]

void dms::setD ( const int & d,
const int & m,
const int & s,
const int & ms = 0 )
virtual

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:

$ fabs(D) = fabs(d) + \frac{(m + (s/60))}{60} $ $ sgn(D) = sgn(d) $

Parameters
dinteger degrees portion of angle
minteger arcminutes portion of angle
sinteger arcseconds portion of angle
msinteger arcseconds portion of angle

Reimplemented in CachingDms.

Definition at line 24 of file dms.cpp.

◆ setFromString()

bool dms::setFromString ( const QString & s,
bool isDeg = true )
virtual

Attempt to parse the string argument as a dms value, and set the dms object accordingly.

Parameters
sthe 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.
isDegif 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.

Reimplemented in CachingDms.

Definition at line 48 of file dms.cpp.

◆ setH() [1/2]

virtual void dms::setH ( const double & x)
inlinevirtual

Sets floating-point value of angle, in hours.

Converts argument from hours to degrees, then sets floating-point value of angle, in degrees.

Parameters
xnew angle, in hours (double)
See also
setD()

Reimplemented in CachingDms.

Definition at line 210 of file dms.h.

◆ setH() [2/2]

void dms::setH ( const int & h,
const int & m,
const int & s,
const int & ms = 0 )
virtual

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
hinteger hours portion of angle
minteger minutes portion of angle
sinteger seconds portion of angle
msinteger milliseconds portion of angle
See also
setD()

Reimplemented in CachingDms.

Definition at line 36 of file dms.cpp.

◆ setRadians()

virtual void dms::setRadians ( const double & Rad)
inlinevirtual

Set angle according to the argument, in radians.

This function converts the argument to degrees, then sets the angle with setD().

Parameters
Radan angle in radians

Reimplemented in CachingDms.

Definition at line 333 of file dms.h.

◆ sin()

double dms::sin ( ) const
inline

Compute the Angle's Sine.

Returns
the Sine of the angle.
See also
cos()

Definition at line 258 of file dms.h.

◆ SinCos()

void dms::SinCos ( double & s,
double & c ) const
inline

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).

Parameters
sSine of the angle
cCosine of the angle
See also
sin() cos()

Definition at line 447 of file dms.h.

◆ tan()

double dms::tan ( ) const
inline

Convenience method to return tangent of the angle.

Definition at line 320 of file dms.h.

◆ toDMSString()

const QString dms::toDMSString ( const bool forceSign = false,
const bool machineReadable = false,
const bool highPrecision = false ) const
Returns
a nicely-formatted string representation of the angle in degrees, arcminutes, and arcseconds.
Parameters
forceSignif true then adds '+' or '-' to the string
machineReadableuses a colon separator and produces +/-dd:mm:ss format instead
highPrecisionadds milliseconds, if false the seconds will be shown as an integer

Definition at line 287 of file dms.cpp.

◆ toHMSString()

const QString dms::toHMSString ( const bool machineReadable = false,
const bool highPrecision = false ) const
Returns
a nicely-formatted string representation of the angle in hours, minutes, and seconds.
Parameters
machineReadableuses a colon separator and produces hh:mm:ss format instead
highPrecisionadds milliseconds, if false the seconds will be shown as an integer

Definition at line 378 of file dms.cpp.

Member Data Documentation

◆ D

double dms::D
protected

Definition at line 421 of file dms.h.

◆ DegToRad

double dms::DegToRad = { M_PI / 180.0 }
staticconstexpr

DegToRad is a const static member equal to the number of radians in one degree (dms::PI/180.0).

Definition at line 390 of file dms.h.

◆ PI

double dms::PI = { M_PI }
staticconstexpr

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 385 of file dms.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:01:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.