CppEphem
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
CEAngle Class Reference

The CEAngle class defines an angle. It can be constructed either from: double: representing degrees or radians string: representing HH:MM:SS or DD:MM:SS

Methods are also provided to allow the user to retrieve the angle in whatever format they prefer

Definition at line 38 of file CEAngle.h.

Public Member Functions

 CEAngle ()
 Default constructor. More...
 
 CEAngle (const CEAngle &other)
 Construct from another CEAngle object. More...
 
 CEAngle (const double &angle)
 Construct from an angle in radians. More...
 
double Deg (void) const
 Return angle in degrees as a double. More...
 
std::string DmsStr (const char &delim=':') const
 Return string representing the angle in DD:MM:SS. More...
 
std::vector< double > DmsVect (void) const
 Return vector of doubles representing the {degrees, arcmin, arcsec, arcsec-fraction}. More...
 
std::string HmsStr (const char &delim=':') const
 Return string representing the angle in HH:MM:SS. More...
 
std::vector< double > HmsVect (void) const
 Return vector of doubles representing the {hours, min, sec, sec-fraction}. More...
 
 operator double ()
 Return a double object representing the angle in radians. More...
 
 operator double () const
 Return a double object representing the angle in radians. More...
 
CEAngleoperator= (const CEAngle &other)
 Copy assignment operator. More...
 
CEAngleoperator= (const double &other)
 Copy assignment operator from a double. More...
 
double Rad (void) const
 Return angle in radians as a double. More...
 
void SetAngle (const char *angle_str, const CEAngleType &angle_type, const char &delim=0)
 Set the angle from a string representing either HMS or DMS angles. More...
 
void SetAngle (const double &angle, const CEAngleType &angle_type=CEAngleType::RADIANS)
 Set the angle from a double. More...
 
void SetAngle (const std::vector< double > &angle_vec, const CEAngleType &angle_type)
 Set the angle from a vector of doubles representing HMS or DMS format. More...
 
virtual ~CEAngle ()
 Destructor. More...
 

Static Public Member Functions

static CEAngle Deg (const double &angle)
 Return angle (radians) constructed from a degree angle. More...
 
static CEAngle Dms (const char *angle_str, const char &delim=0)
 Return double constructed from a string representing degrees, minutes, seconds. More...
 
static CEAngle Dms (const std::vector< double > &angle_vec)
 Return angle constructed from a string representing degrees, minutes, seconds. More...
 
static CEAngle Hms (const char *angle_str, const char &delim=0)
 Return angle constructed from a string representing hours, minutes, seconds. More...
 
static CEAngle Hms (const std::vector< double > &angle_vec)
 Return angle constructed from a string representing hours, minutes, seconds. More...
 
static CEAngle Rad (const double &angle)
 Return angle constructed from a radians angle. More...
 

Private Member Functions

void copy_members (const CEAngle &other)
 Copy data members from another CEAngle object. More...
 
void free_members (void)
 Free allocated data members. More...
 
void init_members (void)
 Initialize data members. More...
 
void SetAngle_DmsVect (const std::vector< double > &angle)
 Set the angle from a vector of doubles of the form {degrees, arcmin, arcsec}. More...
 
void SetAngle_HmsVect (const std::vector< double > &angle)
 Set the angle from a vector of doubles representing {hours, minutes, seconds}. More...
 

Private Attributes

double angle_
 Angle stored in radians. More...
 

#include <CEAngle.h>

Constructor & Destructor Documentation

◆ CEAngle() [1/3]

CEAngle::CEAngle ( )

Default constructor.

Definition at line 38 of file CEAngle.cpp.

◆ CEAngle() [2/3]

CEAngle::CEAngle ( const double &  angle)

Construct from an angle in radians.

Parameters
[in]angleAngle in radians

The provided angle is assumed to be in units of radians

Definition at line 51 of file CEAngle.cpp.

◆ CEAngle() [3/3]

CEAngle::CEAngle ( const CEAngle other)
explicit

Construct from another CEAngle object.

Parameters
[in]otherCEAngle to copy data members from

Definition at line 63 of file CEAngle.cpp.

◆ ~CEAngle()

CEAngle::~CEAngle ( void  )
virtual

Destructor.

Definition at line 73 of file CEAngle.cpp.

Member Function Documentation

◆ copy_members()

void CEAngle::copy_members ( const CEAngle other)
private

Copy data members from another CEAngle object.

Parameters
[in]otherCEAngle object to copy from

Definition at line 593 of file CEAngle.cpp.

◆ Deg() [1/2]

CEAngle CEAngle::Deg ( const double &  angle)
static

Return angle (radians) constructed from a degree angle.

Parameters
[in]angleAngle in degrees
Returns
CEAngle object

Definition at line 317 of file CEAngle.cpp.

◆ Deg() [2/2]

double CEAngle::Deg ( void  ) const

Return angle in degrees as a double.

Returns
Angle in degrees as a double

Definition at line 328 of file CEAngle.cpp.

◆ Dms() [1/2]

CEAngle CEAngle::Dms ( const char *  angle_str,
const char &  delim = 0 
)
static

Return double constructed from a string representing degrees, minutes, seconds.

Parameters
[in]angle_strAngle representing degrees, arcmins, arcsecs
[in]delimDelimiter, by default all methods will be tested

The following values for delim are special cases:

  • 0 (int) = tests all following possible values for delimiter
  • ':' = 'DD:MM:SS'
  • ' ' = 'DD MM SS'
  • <any char>=""> = The DD, MM, SS is separated by a user defined char

Definition at line 234 of file CEAngle.cpp.

◆ Dms() [2/2]

CEAngle CEAngle::Dms ( const std::vector< double > &  angle_vec)
static

Return angle constructed from a string representing degrees, minutes, seconds.

Parameters
[in]angle_vecAngle representing degrees, minutes, seconds
Returns
Angle in radians

The input angle is represented in the following manner [0] = degrees [1] = minutes [2] = seconds [3] = (optional) seconds fraction The index [3] is optional if index [2] contains the whole seconds portion

Definition at line 256 of file CEAngle.cpp.

◆ DmsStr()

std::string CEAngle::DmsStr ( const char &  delim = ':') const

Return string representing the angle in DD:MM:SS.

Parameters
[in]delimDelimiter to use in output string
Returns
Angle formatted as a string DD:MM:SS

Definition at line 270 of file CEAngle.cpp.

◆ DmsVect()

std::vector< double > CEAngle::DmsVect ( void  ) const

Return vector of doubles representing the {degrees, arcmin, arcsec, arcsec-fraction}.

Returns
Vector of doubles representing {degrees, arcmin, arcsec, arcsec-fraction}

The returned vector has the following elements [0] = degrees [1] = arcminutes [2] = arcseconds [3] = arcseconds fraction

Definition at line 291 of file CEAngle.cpp.

◆ free_members()

void CEAngle::free_members ( void  )
private

Free allocated data members.

Definition at line 581 of file CEAngle.cpp.

◆ Hms() [1/2]

CEAngle CEAngle::Hms ( const char *  angle_str,
const char &  delim = 0 
)
static

Return angle constructed from a string representing hours, minutes, seconds.

Parameters
[in]angle_strAngle representing hours, minutes, seconds
[in]delimDelimiter, by default all methods will be tested
Returns
Angle in radians

The following values for delim are special cases:

  • 0 (int) = tests all following possible values for delimiter
  • ':' = 'HH:MM:SS'
  • ' ' = 'HH MM SS'
  • <any char>=""> = The DD, MM, SS is separated by a user defined char

Definition at line 142 of file CEAngle.cpp.

◆ Hms() [2/2]

CEAngle CEAngle::Hms ( const std::vector< double > &  angle_vec)
static

Return angle constructed from a string representing hours, minutes, seconds.

Parameters
[in]angle_vecAngle representing hours, minutes, seconds
Returns
Angle in radians

The input angle is represented in the following manner [0] = hours [1] = minutes [2] = seconds [3] = (optional) seconds fraction The index [3] is optional if index [2] contains the whole seconds portion

Definition at line 164 of file CEAngle.cpp.

◆ HmsStr()

std::string CEAngle::HmsStr ( const char &  delim = ':') const

Return string representing the angle in HH:MM:SS.

Parameters
[in]delimDelimiter to use in output string
Returns
Angle formatted as a string HH:MM:SS

Definition at line 178 of file CEAngle.cpp.

◆ HmsVect()

std::vector< double > CEAngle::HmsVect ( void  ) const

Return vector of doubles representing the {hours, min, sec, sec-fraction}.

Returns
Vector of doubles representing {hours, min, sec, sec-fraction}

The returned vector has the following elements [0] = hours [1] = minutes [2] = seconds [3] = seconds fraction

Definition at line 199 of file CEAngle.cpp.

◆ init_members()

void CEAngle::init_members ( void  )
private

Initialize data members.

Definition at line 602 of file CEAngle.cpp.

◆ operator double() [1/2]

CEAngle::operator double ( )

Return a double object representing the angle in radians.

Definition at line 114 of file CEAngle.cpp.

◆ operator double() [2/2]

CEAngle::operator double ( ) const

Return a double object representing the angle in radians.

Definition at line 123 of file CEAngle.cpp.

◆ operator=() [1/2]

CEAngle & CEAngle::operator= ( const CEAngle other)

Copy assignment operator.

Parameters
[in]otherCEAngle object to copy objects from
Returns
CEAngle object constructed from other

Definition at line 85 of file CEAngle.cpp.

◆ operator=() [2/2]

CEAngle & CEAngle::operator= ( const double &  other)

Copy assignment operator from a double.

Parameters
[in]otherdouble angle (radians)
Returns
CEAngle object constructed from other

Definition at line 102 of file CEAngle.cpp.

◆ Rad() [1/2]

CEAngle CEAngle::Rad ( const double &  angle)
static

Return angle constructed from a radians angle.

Parameters
[in]angleAngle in radians
Returns
Angle constructed from a 'radians' object

Definition at line 340 of file CEAngle.cpp.

◆ Rad() [2/2]

double CEAngle::Rad ( void  ) const

Return angle in radians as a double.

Returns
Angle in radians as a double

Definition at line 351 of file CEAngle.cpp.

◆ SetAngle() [1/3]

void CEAngle::SetAngle ( const char *  angle_str,
const CEAngleType angle_type,
const char &  delim = 0 
)

Set the angle from a string representing either HMS or DMS angles.

Parameters
[in]angleAngle represented by a HMS or DMS string
[in]angle_typeCEAngleType (only HMS or DMS are accepted)
[in]delimDelimiter used to separate different components in angle

An exception is thrown if angle_type is neither HMS or DMS

Definition at line 400 of file CEAngle.cpp.

◆ SetAngle() [2/3]

void CEAngle::SetAngle ( const double &  angle,
const CEAngleType angle_type = CEAngleType::RADIANS 
)

Set the angle from a double.

Parameters
[in]angleAngle value
[in]angle_typeCEAngleType (only DEGREES or RADIANS are accepted)
Exceptions
CEException::invalid_valueangle_type is neither DEGREES nor RADIANS

This method calls the SOFA function iauAnp to ensure the angle is in the range [0, 2pi).

Definition at line 369 of file CEAngle.cpp.

◆ SetAngle() [3/3]

void CEAngle::SetAngle ( const std::vector< double > &  angle_vec,
const CEAngleType angle_type 
)

Set the angle from a vector of doubles representing HMS or DMS format.

Parameters
[in]angle_vecAngle as a vector of doubles
[in]angle_typeAngle type of angle_vec

An exception is thrown if angle_type is neither HMS or DMS

Definition at line 466 of file CEAngle.cpp.

◆ SetAngle_DmsVect()

void CEAngle::SetAngle_DmsVect ( const std::vector< double > &  angle)
private

Set the angle from a vector of doubles of the form {degrees, arcmin, arcsec}.

Parameters
[in]angleAngle as a vector of doubles

The angle parameter should contain degrees and arcmins as whole numbers, as they will be be cast to integers. The arcsecs parameter is assumed to be at index [2], or split across index [2] and [3] if "angle.size() == 4". This allows dividing the seconds across two indices.

Definition at line 541 of file CEAngle.cpp.

◆ SetAngle_HmsVect()

void CEAngle::SetAngle_HmsVect ( const std::vector< double > &  angle)
private

Set the angle from a vector of doubles representing {hours, minutes, seconds}.

Parameters
[in]angleAngle as a vector of doubles

The angle parameter should contain hours and minutes as whole numbers, as they will be be cast to integers. The seconds parameter is assumed to be at index [2], or split across index [2] and [3] if "angle.size() == 4". This allows dividing the seconds across two indices.

Definition at line 496 of file CEAngle.cpp.

Member Data Documentation

◆ angle_

double CEAngle::angle_
mutableprivate

Angle stored in radians.

Definition at line 93 of file CEAngle.h.


The documentation for this class was generated from the following files: