diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-10 13:29:56 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-10 13:29:56 -0400 |
| commit | 7f63ec5c10eb7e8dd4edaabd1a6a437328911d39 (patch) | |
| tree | 36bd3d75ebc0c25256413c21a7cb28c9296953f5 /src/solar_system/orbit.rs | |
| parent | c9041e2e6fe59d6127bb1085b874e8e3cda8000e (diff) | |
| download | systemic4x-7f63ec5c10eb7e8dd4edaabd1a6a437328911d39.tar.gz systemic4x-7f63ec5c10eb7e8dd4edaabd1a6a437328911d39.tar.bz2 systemic4x-7f63ec5c10eb7e8dd4edaabd1a6a437328911d39.zip | |
fleets
Diffstat (limited to 'src/solar_system/orbit.rs')
| -rw-r--r-- | src/solar_system/orbit.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/solar_system/orbit.rs b/src/solar_system/orbit.rs index 3a1d129..f5a564c 100644 --- a/src/solar_system/orbit.rs +++ b/src/solar_system/orbit.rs @@ -1,4 +1,4 @@ -use crate::solar_system::{Angle, BodyId, Kilometers, OrbitalBody, Percentage, SolarSystem}; +use crate::solar_system::{Angle, BodyId, Kilometers, OrbitalBody, Percentage}; use crate::timeman::{Second}; pub struct StaticOrbit @@ -13,6 +13,12 @@ pub struct StaticOrbit semi_major_axis: Kilometers, } +pub trait StaticOrbiter +{ + fn orbit(&self) -> Option<&StaticOrbit>; + fn sgp(&self) -> f64; +} + impl StaticOrbit { pub fn new( @@ -51,9 +57,9 @@ impl StaticOrbit } } - pub fn period( + pub fn period<T: StaticOrbiter>( &self, - this_body: &OrbitalBody) + this_body: &T) -> Second { ((self.semi_major_axis.powf(3.0) / this_body.sgp()).sqrt() * std::f64::consts::TAU) as Second @@ -65,9 +71,9 @@ impl StaticOrbit pub fn sma(&self) -> Kilometers { self.semi_major_axis } - pub fn calculate_position_at( + pub fn calculate_position_at<T: StaticOrbiter>( &self, - sgp: f64, + this_body: &T, time: Second) -> cgmath::Vector3<f64> { @@ -77,7 +83,7 @@ impl StaticOrbit let arg_periaps = self.long_periapsis - long_asc_node; let sma_cubed = self.semi_major_axis.powf(3.0); - let mean_motion = (sgp / sma_cubed).sqrt(); + let mean_motion = (this_body.sgp() / sma_cubed).sqrt(); let mean_anomaly_epoch = self.mean_long - self.long_periapsis; let mean_anomaly = mean_anomaly_epoch + (mean_motion * time as f64); |
