astro Rust Library

repository·master·Indexed 43 days ago

https://github.com/saurvs/astro-rust

A library of advanced astronomical algorithms for the Rust programming language, version 2.0.0. It provides high-precision calculations for planetary, lunar, and satellite positioning, including Julian and Julian Ephemeris day calculations, geocentric ecliptic positions for the Sun and Moon, and heliocentric positions for planets including Pluto. The library also features tools for geodesic distance on Earth, coordinate conversions between equatorial, ecliptic, and galactic systems, nutation corrections, and binary star orbital calculations.

Tokens
12.4K
Snippets
70
Records
79
Agent score
55%

What's inside astro

  1. Convert equatorial to galactic coordinates

    master

    Use the gal_frm_eq! macro to convert equatorial coordinates to galactic coordinates. Coordinates can be prepared using angle::deg_frm_hms (Hours, Minutes, Seconds) or angle::deg_frm_dms (Degrees, Minutes, Seconds).

    // equatorial coordinates of the Nova Serpentis 1978
    
    let right_ascension = angle::deg_frm_hms(17, 48, 59.74).to_radians();
    let declination = angle::deg_frm_dms(-14, 43, 8.2).to_radians();
    
    // convert to galactic coordinates
    
    let (gal_long, gal_lat) = gal_frm_eq!(right_ascension, declination);
  2. Calculate Julian days and Ephemeris days

    master

    The library uses Julian days as the primary time reference. You can construct a time::Date and time::DayOfMonth to calculate the Julian day. For higher accuracy, you can also calculate the Julian Ephemeris day by accounting for $\Delta T$ (the difference between Terrestrial Time and Universal Time).

    // for example, the time of the Apollo 11 moon landing
    
    let day_of_month = time::DayOfMonth{day      : 20,
    							  hr       : 20,
                                          min      : 18,
                                          sec      : 4.0,
                                          time_zone: 0.0};
    
    let date = time::Date{year       : 1969,
                            month      : 7, // July
                            decimal_day: time::decimal_day(&day_of_month),
                            cal_type   : time::CalType::Gregorian};
    
    let julian_day = time::julian_day(&date);
    
    // for higher accuracy in specifying the time of interest,
    // find the Julian Ephemeris day; this slightly differs from
    // the Julian day by ΔT, which is usually a few seconds. you
    // can get a reported value of it from the Astronomical
    // Almanac, or calculate it using the built-in function
    
    let delta_t = time::delta_t(date.year, date.month);
    
    let julian_ephm_day = time::julian_ephemeris_day(julian_day, delta_t);
  3. Correct for nutation

    master

    Calculate nutation corrections using the nutation module. You can obtain nutation in ecliptic longitude and obliquity, or directly in equatorial coordinates.

    // nutation in ecliptic longitude and obliquity of the ecliptic
    let (nut_in_long, nut_in_oblq) = nutation::nutation(julian_day);
    
    // nutation in equatorial coordinates
    let (nut_in_asc, nut_in_dec) = nutation::nutation_in_eq_coords(julian_day);
  4. Find the position of the Sun and Moon

    master

    Use sun::geocent_ecl_pos and lunar::geocent_ecl_pos to find the geocentric ecliptic point and the radius vector for the Sun and Moon relative to Earth.

    // geocentric ecliptic point and radius vector of the Sun
    let (sun_ecl_point, rad_vec_sun) = sun::geocent_ecl_pos(julian_day);
    
    // sun_ecl_point.long    - ecliptic longitude (radians)
    // sun_ecl_point.lat     - ecliptic latitude  (radians)
    // rad_vec_sun - distance between the Sun and the Earth (AU)
    
    // and similarly for the Moon
    let (moon_ecl_point, rad_vec_moon) = lunar::geocent_ecl_pos(julian_day);
  5. Calculate geodesic distance on Earth

    master

    Find the geodesic distance between two coords::GeographPoint locations on Earth using planet::earth::geodesic_dist. Coordinates can be converted from Degrees, Minutes, Seconds (DMS) using angle::deg_frm_dms.

    // geodesic distance between the Observatoire de Paris and
    // the US Naval Observatory at Washington DC
    
    let paris = coords::GeographPoint{long: angle::deg_frm_dms(-2, 20, 14.0).to_radians(),
                                      lat : angle::deg_frm_dms(48, 50, 11.0).to_radians()};
    
    let washington = coords::GeographPoint{long: angle::deg_frm_dms(77,  3, 56.0).to_radians(),
                                           lat : angle::deg_frm_dms(38, 55, 17.0).to_radians()};
    
    // angle::deg_frm_dms() converts degrees expressed in degrees,
    // minutes and seconds into a fractional degree
    
    let distance = planet::earth::geodesic_dist(&paris, &washington); // in meters
  6. Convert equatorial to ecliptic coordinates

    master

    Use the ecl_frm_eq! macro to convert equatorial coordinates (Right Ascension and Declination) to ecliptic coordinates. This requires the mean obliquity of the ecliptic. Note: you must include #[macro_use] before the crate to use macros.

    // equatorial coordinates of the star Pollux
    
    let right_ascension = 116.328942_f64.to_radians();
    let declination = 28.026183_f64.to_radians();
    
    // mean obliquity of the ecliptic
    
    let oblq_eclip = 23.4392911_f64.to_radians();
    
    // you can also get oblq_eclip from ecliptic::mn_oblq_IAU(julian_day)
    // for the Julian day on which the coordinates of the star
    // were observed
    
    // also make sure to type #[macro_use] before including the crate
    // to use macros
    
    // now, convert equatorial coordinates to ecliptic coordinates
    
    let (ecl_long, ecl_lat) = ecl_frm_eq!(right_ascension, declination, oblq_eclip);
  7. Find the position of a planet relative to the Sun

    master

    Calculate the heliocentric position and radius vector for specific planets using planet::heliocent_pos. Supported planets include Jupiter, Neptune, and Pluto (via the pluto module).

    // the heliocentric point and radius vector of a planet, like Jupiter
    let (jup_long, jup_lat, rad_vec) = planet::heliocent_pos(&planet::Planet::Jupiter, julian_day);
    
    // or neptune
    let (nep_long, nep_lat, rad_vec) = planet::heliocent_pos(&planet::Planet::Neptune, julian_day);
    
    // positioning for all the eight planets (and (the dwarf planet) Pluto) is supported
    let (plut_long, plut_lat, rad_vec) = pluto::heliocent_pos(julian_day);
  8. Convert DMS to decimal degrees with `deg_frm_dms`

    master

    Converts an angle expressed in Degrees, Arcminutes, and Arcseconds (DMS) into a single decimal degree value.

    • deg: Degrees (i64)
    • min: Arcminutes (i64)
    • sec: Arcseconds (f64)

    Returns the angle in decimal degrees (f64). Note that if the degree value is negative, the minutes and seconds are treated as negative components.

    let decimal_deg = deg_frm_dms(34, 12, 45.5);
  9. Normalize angles with `limit_to_360` and `limit_to_two_PI`

    master

    Use these functions to wrap an angle into a standard range.

    • limit_to_360(angl: f64): Takes an angle in degrees and returns the equivalent angle in the range [0, 360).
    • limit_to_two_PI(angl: f64): Takes an angle in radians and returns the equivalent angle in the range [0, 2π).
    let deg = limit_to_360(400.0); // returns 40.0
    let rad = limit_to_two_PI(7.0); // returns value in [0, 2π)
  10. Compute Mars's north pole ecliptic coordinates

    master

    Use north_pol_ecl_coords to compute the ecliptic coordinates of Mars's north pole referred to the mean equinox of the date.

    Arguments:

    • JC: Julian (Ephemeris) century (f64).

    Returns:

    • coords::EclPoint containing longitude (long) and latitude (lat) in radians.
    let jc = 12.345; // Example Julian century
    let ecl_coords = north_pol_ecl_coords(jc);