Skip to main content

StateVectors

Struct StateVectors 

Source
pub struct StateVectors {
    pub position: DVec3,
    pub velocity: DVec3,
}
Expand description

A struct representing a position and velocity at a point in the orbit.

The position and velocity vectors are three-dimensional.

The position vector is in meters, while the velocity vector is in meters per second.

State vectors can be used to form an orbit, see to_compact_orbit and to_cached_orbit for more information.

Fields§

§position: DVec3

The 3D position at a point in the orbit, in meters.

§velocity: DVec3

The 3D velocity at a point in the orbit, in meters per second.

Implementations§

Source§

impl StateVectors

Source

pub fn to_compact_orbit(self, mu: f64, time: f64) -> CompactOrbit

Create a new CompactOrbit struct from the state vectors and the given mu and time values.

§Mu

Mu is also known as the gravitational parameter, and is equal to GM, where G is the gravitational constant, and M is the mass of the parent body.
It can be described as how strongly the parent body pulls on the orbiting body.

Learn more about the gravitational parameter: https://en.wikipedia.org/wiki/Standard_gravitational_parameter

§Time

The time passed into the function is measured in seconds.

§Performance

This function is not too performant as it uses several trigonometric operations.

For single conversions, this is faster than the cached orbit converter.
However, consider using the cached orbit instead if you want to use the same orbit for many calculations, as the caching speed benefits should outgrow the small initialization overhead.

§Reference Frame

This function expects a state vector where the position’s origin (0.0, 0.0, 0.0) is the center of the parent body.

§Parabolic Support

This function does not yet support parabolic trajectories. Non-finite values may be returned for such cases.

§Constraints

The position must not be at the origin, and the velocity must not be at zero.
If this constraint is breached, you may get invalid values such as infinities or NaNs.

§Examples

Simple use-case:

use keplerian_sim::{CompactOrbit, OrbitTrait};

let orbit = CompactOrbit::default();
let mu = orbit.get_gravitational_parameter();
let time = 0.0;

let sv = orbit.get_state_vectors_at_time(time);

let new_orbit = sv.to_compact_orbit(mu, time);

assert_eq!(orbit.get_eccentricity(), new_orbit.get_eccentricity());
assert_eq!(orbit.get_periapsis(), new_orbit.get_periapsis());

To simulate an instantaneous 0.1 m/s prograde burn at periapsis:

use keplerian_sim::{CompactOrbit, OrbitTrait, StateVectors};
use glam::DVec3;

let orbit = CompactOrbit::default();
let mu = orbit.get_gravitational_parameter();
let time = 0.0;

let sv = orbit.get_state_vectors_at_time(time);
assert_eq!(
    sv,
    StateVectors {
        position: DVec3::new(1.0, 0.0, 0.0),
        velocity: DVec3::new(0.0, 1.0, 0.0),
    }
);

let new_sv = StateVectors {
    velocity: sv.velocity + DVec3::new(0.0, 0.1, 0.0),
    ..sv
};

let new_orbit = new_sv.to_compact_orbit(mu, time);

assert_eq!(
    new_orbit,
    CompactOrbit::new(
        0.2100000000000002, // eccentricity
        1.0, // periapsis
        0.0, // inclination
        0.0, // argument of periapsis
        0.0, // longitude of ascending node
        0.0, // mean anomaly
        1.0, // gravitational parameter
    )
)
Source

pub fn to_cached_orbit(self, mu: f64, time: f64) -> Orbit

Create a new Orbit struct from the state vectors and a given mu value.

§Mu

Mu is also known as the gravitational parameter, and is equal to GM, where G is the gravitational constant, and M is the mass of the parent body.
It can be described as how strongly the parent body pulls on the orbiting body.

Learn more about the gravitational parameter: https://en.wikipedia.org/wiki/Standard_gravitational_parameter

§Time

The time passed into the function is measured in seconds.

§Performance

This function is not too performant as it uses several trigonometric operations.

For single conversions, this is slower than the compact orbit converter, as there are some extra values that will be calculated and cached.
However, if you’re going to use this same orbit for many calculations, this should be better off in the long run as the caching performance benefits should outgrow the small initialization cost.

§Reference Frame

This function expects a state vector where the position’s origin (0.0, 0.0, 0.0) is the center of the parent body.

§Parabolic Support

This function does not yet support parabolic trajectories. Non-finite values may be returned for such cases.

§Constraints

The position must not be at the origin, and the velocity must not be at zero.
If this constraint is breached, you may get invalid values such as infinities or NaNs.

§Examples

Simple use-case:

use keplerian_sim::{Orbit, OrbitTrait};

let orbit = Orbit::default();
let mu = orbit.get_gravitational_parameter();
let time = 0.0;

let sv = orbit.get_state_vectors_at_time(time);

let new_orbit = sv.to_cached_orbit(mu, time);

assert_eq!(orbit.get_eccentricity(), new_orbit.get_eccentricity());
assert_eq!(orbit.get_periapsis(), new_orbit.get_periapsis());

To simulate an instantaneous 0.1 m/s prograde burn at periapsis:

use keplerian_sim::{Orbit, OrbitTrait, StateVectors};
use glam::DVec3;

let orbit = Orbit::default();
let mu = orbit.get_gravitational_parameter();
let time = 0.0;

let sv = orbit.get_state_vectors_at_time(time);
assert_eq!(
    sv,
    StateVectors {
        position: DVec3::new(1.0, 0.0, 0.0),
        velocity: DVec3::new(0.0, 1.0, 0.0),
    }
);

let new_sv = StateVectors {
    velocity: sv.velocity + DVec3::new(0.0, 0.1, 0.0),
    ..sv
};

let new_orbit = new_sv.to_cached_orbit(mu, time);

assert_eq!(
    new_orbit,
    Orbit::new(
        0.2100000000000002, // eccentricity
        1.0, // periapsis
        0.0, // inclination
        0.0, // argument of periapsis
        0.0, // longitude of ascending node
        0.0, // mean anomaly
        1.0, // gravitational parameter
    )
)
Source

pub fn to_custom_orbit<O>(self, mu: f64, time: f64) -> O

Create a new custom orbit struct from the state vectors and a given mu value.

§Mu

Mu is also known as the gravitational parameter, and is equal to GM, where G is the gravitational constant, and M is the mass of the parent body.
It can be described as how strongly the parent body pulls on the orbiting body.

Learn more about the gravitational parameter: https://en.wikipedia.org/wiki/Standard_gravitational_parameter

§Time

The time passed into the function is measured in seconds.

§Performance

This function is not too performant as it uses several trigonometric operations.

The performance also depends on how fast the specified orbit type can convert between the CompactOrbit form into itself, and so we cannot guarantee any performance behaviors.

§Reference Frame

This function expects a state vector where the position’s origin (0.0, 0.0, 0.0) is the center of the parent body.

§Parabolic Support

This function does not yet support parabolic trajectories. Non-finite values may be returned for such cases.

§Constraints

The position must not be at the origin, and the velocity must not be at zero.
If this constraint is breached, you may get invalid values such as infinities or NaNs.

Trait Implementations§

Source§

impl Clone for StateVectors

Source§

fn clone(&self) -> StateVectors

Returns a duplicate 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 StateVectors

Source§

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

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

impl PartialEq for StateVectors

Source§

fn eq(&self, other: &StateVectors) -> 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 Copy for StateVectors

Source§

impl StructuralPartialEq for StateVectors

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.