Jvinniec / CppEphem

CppEphem is a self-contained ephemeris package written in C++. It allows computation of celestial coordinate and date conversions and planet ephemerides by leveraging the Standards of Fundamental Astronomy (SOFA) software (included in the repo). It is C++11 compatible.
2 stars 2 forks source link

Add CEAngle class #26

Closed Jvinniec closed 5 years ago

Jvinniec commented 5 years ago

This PR adds the CEAngle class, resolving issue #24.

Overview of CEAngle

The CEAngle class makes it possible to construct an angle object from either a degree, radian, string, or vector representing {hours, minutes, seconds} or {degrees, arcmin, arcsec}. It stores the angle in radians and can be directly interpreted as an angle in radians. This allows it to be internally passed directly to SOFA methods, which typically use radians for angles.

Methods are also provided for returning the angle in various formats:

CEAngle angle = CEAngle::Deg(22.0145);
std::vector<double> hms_vect = angle.HmsVect();  // {1,28,3,0.48}
std::vector<double> dms_vect = angle.DmsVect();  // {22,0,52,0.2}
std::string hms_str = angle.HmsStr();    // "01:28:03.48000000"
std::string dms_str = angle.DmsStr('_'); // "22_00_52.20000000"

Implications for the CECoordinates

The CECoordinates class now takes CEAngle objects in its constructors and in the AngularSeparation method. It can still be constructed from doubles representing the angles in radians or by using the static CEAngle methods Deg, Rad, Hms, or Dms that return a CEAngle object derived from an appropriately formatted angle. For example, to construct an angle from HMS, DMS strings you would call (note the CEAngleType is no longer required):

// Crab nebula in RA,Dec as degrees ...
CECoordinates crab1(CEAngle::Deg(83.633), CEAngle::Deg(22.0145), CECoordinateType::ICRS);
// ... or RA, Dec in hours:minutes:sec and deg:arcmin:arcsec format
std::string hms("5:34:31.94");
std::string dms("22:0:52.2");
CECoordinates crab2(CEAngle::Hms(hms), CEAngle::Dms(dms), CECoordinateType::ICRS);

Note that the string format can also have a user defined delimiter:

// Crab Nebula RA, Dec in hours:minutes:sec and deg:arcmin:arcsec format
std::string hms("5,34,31.94"); 
std::string dms("22,0,52.2");
CECoordinates coord(CEAngle::Hms(hms, ','), CEAngle::Dms(dms, ','), CECoordinateType::ICRS);

The x,y coordinates are also stored as CEAngle objects and CECoordinates::XCoord and CECoordinates::YCoord return these angles as CEAngles allowing direct use of the CEAngle methods for extracting the angle in your preferred format.