rust_rewrite #11
@ -11,5 +11,6 @@ clap = { version = "4.5.39", features = ["derive"] }
|
|||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
glam = { version = "0.30.4", features = ["serde"] }
|
glam = { version = "0.30.4", features = ["serde"] }
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
|
once_cell = "1.21.3"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
74
src/types.rs
74
src/types.rs
@ -1,6 +1,80 @@
|
|||||||
use glam::DVec3;
|
use glam::DVec3;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
pub type Position = DVec3;
|
pub type Position = DVec3;
|
||||||
pub type Velocity = DVec3;
|
pub type Velocity = DVec3;
|
||||||
pub type Acceleration = DVec3;
|
pub type Acceleration = DVec3;
|
||||||
pub type Mass = f64;
|
pub type Mass = f64;
|
||||||
|
pub type Time = f64;
|
||||||
|
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const EARTH_RADIUS: f64 = 6.378e6; //meters
|
||||||
|
const EARTH_MASS: f64 = 5.972e24; //kg
|
||||||
|
const EARTH_ORBITAL_VELOCITY: f64 = 2.9780e4; //m/s
|
||||||
|
const AU: f64 = 1.49597870700e11; //meters
|
||||||
|
|
||||||
|
const MOON_MASS: Mass = 7.34767309e22; // kg
|
||||||
|
const MOON_ORBITAL_VELOCITY: f64 = 1.022e3; //m/s relative to earth
|
||||||
|
|
||||||
|
const SUN_MASS: f64 = 1.989e30; //kg
|
||||||
|
const SUN_RADIUS: f64 = 6.957e8; //meters
|
||||||
|
|
||||||
|
const G: f64 = 6.67430e-11;
|
||||||
|
const r_0: f64 = EARTH_RADIUS;
|
||||||
|
const m_0: f64 = EARTH_MASS;
|
||||||
|
|
||||||
|
static t_0: Lazy<f64> = Lazy::new(|| {
|
||||||
|
(r_0.powf(3.0) / (G * m_0)).sqrt()
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn norm_pos(pos: Position) -> Position {
|
||||||
|
pos / r_0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn real_pos(pos: Position) -> Position {
|
||||||
|
pos * r_0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn norm_mass(mass: Mass) -> Mass {
|
||||||
|
mass / m_0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn real_mass(mass: Mass) -> Mass {
|
||||||
|
mass * m_0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn norm_time(time: Time) -> Time {
|
||||||
|
time / *t_0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn real_time(time: Time) -> Time {
|
||||||
|
time * *t_0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn norm_vel(vel: Velocity) -> Velocity {
|
||||||
|
vel / (r_0 / *t_0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn real_vel(vel: Velocity) -> Velocity {
|
||||||
|
vel * (r_0 / *t_0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn norm_acc(acc: Acceleration) -> Acceleration {
|
||||||
|
acc / (r_0 / (*t_0 * *t_0))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn real_acc(acc: Acceleration) -> Acceleration {
|
||||||
|
acc * (r_0 / (*t_0 * *t_0))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user