1 /*****************************************************************************\ 2 * AstroOps 3 * 4 * Astro defines misc. handy constants & fns 5 * ObsInfo holds latitude, longitude and TZ for an observing location 6 * AstroOps is a 'catch-all' class that performs odd handy calculations 7 * 8 * author: mark huss (mark@mhuss.com) 9 * Based on Bill Gray's open-source code at projectpluto.com 10 * 11 \*****************************************************************************/ 12 13 #if !defined( ASTRO_OPS__H ) 14 #define ASTRO_OPS__H 15 16 // * * * * * Generic Handy Constants and Conversions * * * * * 17 18 #define PI_DEF 3.14159265358979323846 19 20 struct Astro { 21 // these are initialized in AstroOps.cpp 22 23 static const double PI; 24 static const double TWO_PI; 25 static const double PI_OVER_TWO; 26 static const double TWO_OVER_PI; 27 static const double DEG_PER_CIRCLE; 28 static const double MINUTES_PER_DEGREE; 29 static const double SECONDS_PER_DEGREE; 30 31 static const double TO_RADS; 32 static const double TO_CENTURIES; 33 34 static const double HOURS_PER_DAY; 35 static const int IHOURS_PER_DAY; 36 37 static const double J2000; 38 39 // convert degrees to radians toRadiansAstro40 static double toRadians( double deg ) { return deg * TO_RADS; } 41 42 // convert radians to degrees toDegreesAstro43 static double toDegrees( double rad ) { return rad / TO_RADS; } 44 45 // convert hour to decimal day, e.g., 12h -> .5d toDaysAstro46 static double toDays( int hours ) { return (double)hours / HOURS_PER_DAY; } 47 48 // convert a JD to Julian Millenia referenced to epoch J2000 toMilleniaAstro49 static double toMillenia( double jd ) { return ( jd - J2000 ) / TO_CENTURIES; } 50 }; 51 52 // * * * * * Handy Type Definitions * * * * * 53 54 typedef double AstroVector[3]; 55 typedef double AstroMatrix[9]; 56 57 // * * * * * Observer's Location Info * * * * * 58 59 class ObsInfo { 60 public: 61 // c'tor: lon & lat are passed in DEGREES 62 ObsInfo( double lon = 0, double lat = 0, int tz = 0 ) : m_longitude(Astro::toRadians (lon))63 m_longitude( Astro::toRadians(lon) ), 64 m_latitude( Astro::toRadians(lat) ), 65 m_timeZone( tz ) 66 {} 67 longitude()68 double longitude() const { return m_longitude; } degLatitude()69 double degLatitude() const { return Astro::toDegrees(m_latitude); } 70 // set: lon passed in DEGREES setLongitude(double lon)71 void setLongitude(double lon) { m_longitude = Astro::toRadians(lon); } 72 latitude()73 double latitude() const { return m_latitude; } degLongitude()74 double degLongitude() const { return Astro::toDegrees(m_longitude); } 75 // set: lat passed in DEGREES setLatitude(double lat)76 void setLatitude(double lat) { m_latitude = Astro::toRadians(lat); } 77 timeZone()78 int timeZone() const { return m_timeZone; } setTimeZone(int tz)79 void setTimeZone(int tz) { m_timeZone = tz; } 80 81 private: 82 double m_longitude; // in radians, N positive 83 double m_latitude; // in radians, E positive 84 int m_timeZone; // +/- 12 viz. UT 85 }; 86 87 // * * * * * Handy functions that didn't fit anywhere else * * * * * 88 89 class AstroOps { 90 public: 91 static double meanObliquity( double t ); 92 static void nutation( double t, double* d_lon, double* d_obliq ); 93 static double greenwichSiderealTime( double jd ); 94 95 static double normalizeDegrees( double d); 96 static double normalizeRadians( double d); 97 }; 98 99 #endif /* #if !defined( ASTRO_OPS__H ) */ 100 101 102