use crate::config::parameters::G;
use std::f64::consts::PI;
pub struct PlanetaryGravity {
pub mass: f64,
pub radius: f64,
}
impl PlanetaryGravity {
pub fn new(mass: f64, radius: f64) -> Self {
Self { mass, radius }
}
pub fn surface_acceleration(&self) -> f64 {
G * self.mass / (self.radius * self.radius)
}
pub fn potential(&self, r: f64) -> f64 {
-G * self.mass / r
}
pub fn escape_velocity(&self) -> f64 {
(2.0 * G * self.mass / self.radius).sqrt()
}
pub fn orbital_velocity(&self, r: f64) -> f64 {
(G * self.mass / r).sqrt()
}
pub fn orbital_period(&self, r: f64) -> f64 {
2.0 * PI * r / self.orbital_velocity(r)
}
pub fn tidal_acceleration(&self, r: f64, dr: f64) -> f64 {
2.0 * G * self.mass * dr / (r * r * r)
}
pub fn sphere_of_influence(&self, distance: f64, host_mass: f64) -> f64 {
distance * (self.mass / host_mass).powf(2.0 / 5.0)
}
pub fn synchronous_orbit_radius(&self, rotation_period: f64) -> f64 {
let mu = G * self.mass;
(mu * (rotation_period / (2.0 * PI)).powi(2)).cbrt()
}
}
pub fn two_body_force(m1: f64, m2: f64, r: f64) -> f64 {
G * m1 * m2 / (r * r)
}
pub fn hill_sphere(semi_major: f64, mass: f64, host_mass: f64) -> f64 {
semi_major * (mass / (3.0 * host_mass)).cbrt()
}
pub fn roche_limit(r_primary: f64, rho_primary: f64, rho_secondary: f64) -> f64 {
2.456 * r_primary * (rho_primary / rho_secondary).cbrt()
}
pub fn tisserand_parameter(a: f64, a_j: f64, e: f64, i: f64) -> f64 {
a_j / a + 2.0 * (a / a_j * (1.0 - e * e)).sqrt() * i.cos()
}
pub fn laplace_radius(mass: f64, j2: f64, radius: f64, semi_major: f64, star_mass: f64) -> f64 {
let ratio = 2.0 * j2 * mass * radius * radius / (star_mass * semi_major.powi(3));
semi_major * ratio.powf(2.0 / 7.0)
}