keplerian_sim

Struct Body

Source
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: String

The name of the celestial body.

§mass: f64

The mass of the celestial body, in kilograms.

§radius: f64

The radius of the celestial body, in meters.

§orbit: Option<Orbit>

The orbit of the celestial body, if it is orbiting one.

§progress: f64

The orbit progress, between 0 and 1.

Implementations§

Source§

impl Body

Source

pub fn new(name: String, mass: f64, radius: f64, orbit: Option<Orbit>) -> Body

Creates a new Body instance.

§Arguments
  • name - The name of the celestial body.
  • mass - The mass of the celestial body, in kilograms.
  • radius - The radius of the celestial body, in meters.
  • orbit - An optional orbit for the celestial body.
§Returns

A new Body instance.

Source

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.

Source

pub fn release_from_orbit(&mut self)

Releases the body from its orbit.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Body

Source§

fn clone(&self) -> Body

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Body

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Body

Source§

fn eq(&self, other: &Body) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Body

Auto Trait Implementations§

§

impl Freeze for Body

§

impl RefUnwindSafe for Body

§

impl Send for Body

§

impl Sync for Body

§

impl Unpin for Body

§

impl UnwindSafe for Body

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.