Added normalization

This commit is contained in:
Thomas Faour 2025-06-19 16:05:25 -04:00
parent 64bec5af20
commit 63fe3a38b8
2 changed files with 75 additions and 0 deletions

View File

@ -11,5 +11,6 @@ clap = { version = "4.5.39", features = ["derive"] }
env_logger = "0.11.8"
glam = { version = "0.30.4", features = ["serde"] }
log = "0.4.27"
once_cell = "1.21.3"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"

View File

@ -1,6 +1,80 @@
use glam::DVec3;
use once_cell::sync::Lazy;
pub type Position = DVec3;
pub type Velocity = DVec3;
pub type Acceleration = DVec3;
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))
}