Expand description
§Keplerian Orbital Mechanics
This library crate contains logic for Keplerian orbits, similar to the ones you’d find in a game like Kerbal Space Program.
Keplerian orbits are special in that they are more stable and predictable than
Newtonian orbits. In fact, unlike Newtonian orbits, Keplerian orbits don’t use
time steps to calculate the next position of an object. Keplerian orbits use
state vectors to determine the object’s full trajectory at any given time.
This way, you don’t need to worry about lag destabilizing Keplerian orbits.
However, Keplerian orbits are significantly more complex to calculate than just using Newtonian physics. It’s also a two-body simulation, meaning that it doesn’t account for external forces like gravity from other bodies or the engines of a spacecraft.
The way Kerbal Space Program handles this is to have an “on-rails” physics system utilizing Keplerian orbits, and an “active” physics system utilizing Newtonian two-body physics.
§Getting started
This crate provides four main structs:
Orbit: A struct representing an orbit around a celestial body. Each instance of this struct has some cached data to speed up certain calculations, and has a larger memory footprint.CompactOrbit: A struct representing an orbit around a celestial body. This struct has a smaller memory footprint than the regularOrbitstruct, but some calculations may take 2~10x slower because it doesn’t save any cached calculations.
We used to have body, universe, and body_presets modules, however these
were removed from the main library because some programs have different
needs on what to store on each body. The code was moved to the simulate
example file in the repository:
https://github.com/Not-A-Normal-Robot/keplerian-sim/blob/0d60ed756dc6b09c60d779167cfa0e3346e09213/examples/simulate.rs
§Example
use glam::DVec3;
use keplerian_sim::{Orbit, OrbitTrait};
// Create a perfectly circular orbit with a radius of 1 meter
let orbit = Orbit::default();
assert_eq!(orbit.get_position_at_time(0.0), DVec3::new(1.0, 0.0, 0.0));Modules§
- reexports
- Re-exports for dependencies.
Structs§
- Compact
Orbit - A minimal struct representing a Keplerian orbit.
- Compact
Orbit2D - A minimal struct representing a 2D Keplerian orbit.
- Matrix3x2
- A struct representing a 3x2 matrix.
- Orbit
- A struct representing a Keplerian orbit with some cached values.
- Orbit2D
- A struct representing a 2D Keplerian orbit with some cached values.
- State
Vectors - A struct representing a position and velocity at a point in the orbit.
- State
Vectors2D - A struct representing a position and velocity at a point in the orbit.
Enums§
- Apoapsis
Setter Error - An error to describe why setting the periapsis of an orbit failed.
- MuSetter
Mode - A mode to describe how the gravitational parameter setter should behave.
- MuSetter
Mode2D - A mode to describe how the gravitational parameter setter should behave.
Traits§
- Orbit
Trait - A trait that defines the methods that a Keplerian orbit must implement.
- Orbit
Trait2D - A trait that defines the methods that a 2D-constrained Keplerian orbit must implement.
Functions§
- sinhcosh
- Get the hyperbolic sine and cosine of a number.