add nature::orbital_velocity

This commit is contained in:
yuni 2024-06-08 02:57:25 +02:00
parent 159dfe8e19
commit c6750eae46

View file

@ -11,6 +11,7 @@
// This module manages the messy, impure parts of our universe.
use crate::prelude::*;
use bevy::prelude::Vec3;
pub const OXYGEN_USE_KG_PER_S: f32 = 1e-5;
pub const OXY_S: f32 = OXYGEN_USE_KG_PER_S;
@ -168,6 +169,17 @@ pub fn simple_orbital_period(mass: f64, distance: f64) -> f64 {
return 2.0 * PI * (distance.powf(3.0) / (G * mass)).sqrt();
}
/// Calculates the orbital velocity with given parameters, assuming prograde circular orbit.
pub fn orbital_velocity(coords: Vec3, mass: f64) -> Vec3 {
let r = coords.length() as f64;
let speed = (G * mass / r).sqrt() as f32;
// This generates a perpendicular orbital vector in the prograde direction
let perpendicular = Vec3::new(-coords.z, 0.0, -coords.x).normalize();
return perpendicular * speed;
}
pub fn phase_dist_to_coords(phase_radians: f64, distance: f64) -> DVec3 {
return DVec3::new(
distance * phase_radians.cos(),