pub struct Body {
pub name: String,
pub mass: f64,
pub radius: f64,
pub orbit: Option<Orbit>,
pub progress: f64,
}Expand description
A struct representing a celestial body.
Fields§
§name: StringThe name of the celestial body.
mass: f64The mass of the celestial body, in kilograms.
radius: f64The radius of the celestial body, in meters.
orbit: Option<Orbit>The orbit of the celestial body, if it is orbiting one.
progress: f64The orbit progress, between 0 and 1.
Implementations§
Source§impl Body
impl Body
Sourcepub fn new_default() -> Body
pub fn new_default() -> Body
Creates a default Body instance.
Currently, this function returns the Earth.
However, do not rely on this behavior, as it may change in the future.
Sourcepub fn release_from_orbit(&mut self)
pub fn release_from_orbit(&mut self)
Releases the body from its orbit.
Sourcepub fn get_orbital_period(&self, g: f64) -> Option<f64>
pub fn get_orbital_period(&self, g: f64) -> Option<f64>
Get the amount of time it takes for the body to complete one orbit, given a gravitational constant.
Sourcepub fn progress_orbit(&mut self, dt: f64, g: f64) -> Result<(), String>
pub fn progress_orbit(&mut self, dt: f64, g: f64) -> Result<(), String>
Progresses this body’s orbit, given a time step and the gravitational acceleration towards the parent body.
Sourcepub fn get_relative_position(&self) -> (f64, f64, f64)
pub fn get_relative_position(&self) -> (f64, f64, f64)
Gets the relative position of this body, in meters.
The position is relative to the parent body, if there is one.
If the body is not orbiting anything, this function will return
(0, 0, 0).
Each coordinate is in meters.