diff --git a/src/earth.h b/src/earth.h index 68e4d01..1b58d1f 100644 --- a/src/earth.h +++ b/src/earth.h @@ -6,10 +6,20 @@ #include #include +const double PI = 3.14159265365358979323; +/** +* Earth constants... +*/ +const double EQ_RADIUS = 6378.14; +const double FLATTENING = 1.0 / 298.257; +const double POL_RADIUS = 6356.755; +const double RAD_RATIO = 1 - FLATTENING; +const double MERID_ECC = 0.08181922; /** * @struct * A representation of the Earth * with some geometrical properties +* @todo Useless? */ struct Earth { double a; /*!< The Earth's equatorial radius in km */ @@ -17,16 +27,15 @@ struct Earth { double b; /*!< The Earth's polar radius in km */ double e; /*!< The eccentricity of Earth's meridian */ }; - /** * @struct * Representation of geographical * latitude */ struct Latitude { - short degrees; - short arcmins; - double arcsecs; + short degrees; /*!< Latitude degrees as an integer */ + short arcmins; /*!< Latitude arc minutes as an integer */ + double arcsecs; /*!< Latitude arc seconds as decimal */ }; /** * @struct @@ -36,27 +45,26 @@ struct Latitude { struct Location { struct Latitude lat; /*!< The location's geographical latitude */ double h; /*!< Observer's height above sea level in m */ - double r_sin_phi_p; /*!< Earth's radius times sin(geocentric latitude) */ - double r_cos_phi_p; /*!< Earth's radius times cos(geocentric latitude) */ + double r_sin_phi_p; /*!< Earth's radius times sin(geocentric_latitude) */ + double r_cos_phi_p; /*!< Earth's radius times cos(geocentric_latitude) */ }; -struct Earth set_earth_values(struct Earth * earth); +void set_earth_values(struct Earth * earth); double lat_to_dec(struct Latitude lat); +double r_sin_phi(double h, double decimal_lat); struct Latitude dec_to_lat(double dec_lat); struct Location set_location_params(struct Location * loc); + /** * @fn * Initializes an Earth structure -* @param *earth The Earth struct pointer +* @todo Even more useless?? */ -struct Earth set_earth_values(struct Earth * earth) { - earth->a = 6378.14; - earth->f = 1 / 298.257; - double f = earth->f; - earth->b = earth->a * (1 - earth->f); - earth->e = sqrt(2*f - f*f); - - return *earth; +void set_earth_values(struct Earth * earth) { + earth->a = EQ_RADIUS; + earth->f = FLATTENING; + earth->b = POL_RADIUS; + earth->e = MERID_ECC; } /** * @fn @@ -70,4 +78,53 @@ double lat_to_dec(struct Latitude lat) { return lat.degrees + dec_minutes + dec_seconds; } +/** +* @fn +* Calculates $\rho \sin{\phi}$ for +* a location +* @param h The location's height in meters +* @param decimal_lat The location's decimal latitude in deg +*/ +double rho_sin_phi(double h, double decimal_lat) { + // Convert lat from deg to radians + double lat_rad = decimal_lat * (PI / 180.); + double tan_u = RAD_RATIO * tan(lat_rad); + double u = atan(tan_u); + double rho_sin_phi = RAD_RATIO * sin(u) + (h / 6378140.) * sin(lat_rad); + + return rho_sin_phi; +} +/** +* @fn +* Calculates $\rho \sin{\phi}$ for +* a location +* @param h The location's height in meters +* @param decimal_lat The location's decimal latitude +*/ +double rho_cos_phi(double h, double decimal_lat) { + // Convert lat from deg to radians + double lat_rad = decimal_lat * (PI / 180.); + double tan_u = RAD_RATIO * tan(lat_rad); + double u = atan(tan_u); + + double rho_cos_phi = cos(u) + (h / 6378140) * cos(lat_rad); + + return rho_cos_phi; +} +/** +* @fn +* Calculates and sets geographical parameters +* related to a location +* @param loc The Location to set +* @param lat The location's Latitude +* @param h The location's height in meters +*/ +struct Location set_location_params(struct Location * loc) { + double decimal_lat = lat_to_dec(loc->lat); + + loc->r_sin_phi_p = rho_sin_phi(loc->h, decimal_lat); + loc->r_cos_phi_p = rho_cos_phi(loc->h, decimal_lat); + + return *loc; +}