cometsfactory 0.0.3

Comet factory — classify, build and catalogue comets of any type: short-period, long-period, Halley-type, sungrazer, interstellar, main-belt comet, centaur-transition, and extinct.
Documentation
pub use sciforge::hub::prelude::constants::{C, G, K_B, SOLAR_MASS};

pub const PI: f64 = std::f64::consts::PI;
pub const AU: f64 = 1.496e11;
pub const YEAR: f64 = 365.25 * 86400.0;
pub const SOLAR_LUMINOSITY: f64 = 3.828e26;
pub const EARTH_MASS: f64 = 5.972e24;
pub const STEFAN_BOLTZMANN: f64 = 5.6704e-8;

/// Water ice sublimation temperature (K)
pub const ICE_SUBLIMATION_TEMP: f64 = 170.0;
/// Latent heat of sublimation for water ice (J/kg)
pub const LATENT_HEAT_WATER: f64 = 2.83e6;
/// Water molecule mass (kg)
pub const WATER_MOLECULE_MASS: f64 = 2.99e-26;
/// Snow line distance (AU)
pub const SNOW_LINE_AU: f64 = 2.7;
/// Typical cometary nucleus density (kg/m^3)
pub const COMET_NUCLEUS_DENSITY: f64 = 500.0;
/// Typical cometary albedo
pub const COMET_ALBEDO: f64 = 0.04;

pub fn sphere_volume(radius: f64) -> f64 {
    (4.0 / 3.0) * PI * radius.powi(3)
}

pub fn sphere_mass(radius: f64, density: f64) -> f64 {
    sphere_volume(radius) * density
}

pub fn surface_gravity(mass: f64, radius: f64) -> f64 {
    if radius < 1.0 {
        return 0.0;
    }
    G * mass / (radius * radius)
}

pub fn escape_velocity(mass: f64, radius: f64) -> f64 {
    if radius < 1.0 {
        return 0.0;
    }
    (2.0 * G * mass / radius).sqrt()
}

pub fn orbital_period(semi_major_au: f64, central_mass: f64) -> f64 {
    let a = semi_major_au * AU;
    2.0 * PI * (a.powi(3) / (G * central_mass)).sqrt()
}

pub fn vis_viva(central_mass: f64, r: f64, a: f64) -> f64 {
    (G * central_mass * (2.0 / r - 1.0 / a)).sqrt()
}

pub fn hill_sphere(a: f64, m_body: f64, m_central: f64) -> f64 {
    a * (m_body / (3.0 * m_central)).powf(1.0 / 3.0)
}

/// Equilibrium temperature at distance r (m) from the Sun
pub fn equilibrium_temperature(r_m: f64, albedo: f64) -> f64 {
    (SOLAR_LUMINOSITY * (1.0 - albedo) / (16.0 * PI * STEFAN_BOLTZMANN * r_m * r_m)).powf(0.25)
}

/// Perihelion distance from semi-major axis and eccentricity (AU)
pub fn perihelion_au(semi_major_au: f64, eccentricity: f64) -> f64 {
    semi_major_au * (1.0 - eccentricity)
}

/// Aphelion distance from semi-major axis and eccentricity (AU)
pub fn aphelion_au(semi_major_au: f64, eccentricity: f64) -> f64 {
    semi_major_au * (1.0 + eccentricity)
}