Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Dec 10, 2024
1 parent 5efacc6 commit 9ff20a9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
47 changes: 44 additions & 3 deletions crates/lox-orbits/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::f64::consts::TAU;
use float_eq::float_eq;
use glam::{DMat3, DVec3};

use lox_bodies::PointMass;
use lox_bodies::{Origin, PointMass};
use lox_time::deltas::TimeDelta;
use lox_time::TimeLike;

Expand All @@ -23,7 +23,7 @@ pub trait ToKeplerian<T: TimeLike, O: PointMass> {
}

#[derive(Debug, Clone, PartialEq)]
pub struct Keplerian<T: TimeLike, O: PointMass> {
pub struct Keplerian<T: TimeLike, O: Origin> {
time: T,
origin: O,
semi_major_axis: f64,
Expand All @@ -37,7 +37,7 @@ pub struct Keplerian<T: TimeLike, O: PointMass> {
impl<T, O> Keplerian<T, O>
where
T: TimeLike,
O: PointMass,
O: Origin,
{
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand Down Expand Up @@ -107,7 +107,13 @@ where
self.semi_major_axis * (1.0 - self.eccentricity.powi(2))
}
}
}

impl<T, O> Keplerian<T, O>
where
T: TimeLike,
O: PointMass,
{
pub fn to_perifocal(&self) -> (DVec3, DVec3) {
let grav_param = self.origin.gravitational_parameter();
let semiparameter = self.semiparameter();
Expand Down Expand Up @@ -156,6 +162,41 @@ pub fn is_circular(eccentricity: f64) -> bool {
float_eq!(eccentricity, 0.0, abs <= 1e-8)
}

enum OrbitShape {
SemiMajorAndEccentricity {
semi_major_axis: f64,
eccentricity: f64,
},
Radii {
periapsis_radius: f64,
apoapsis_radius: f64,
},
Altitudes {
periapsis_altitude: f64,
apoapsis_altitude: f64,
},
}

enum Anomaly {
True(f64),
Eccentric(f64),
Mean(f64),
}

impl Default for Anomaly {
fn default() -> Self {
Anomaly::True(0.0)
}
}

pub struct KeplerianBuilder {
shape: OrbitShape,
inclination: Option<f64>,
longitude_of_ascending_node: Option<f64>,
argument_of_periapisis: Option<f64>,
anomaly: Option<Anomaly>,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
20 changes: 10 additions & 10 deletions crates/lox-orbits/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ impl PyKeplerian {
longitude_of_ascending_node: f64,
argument_of_periapsis: f64,
true_anomaly: f64,
origin: Option<&Bound<'_, PyAny>>,
origin: Option<PyOrigin>,
) -> PyResult<Self> {
let origin: PyBody = origin.try_into()?;
let origin = origin.map(|origin| origin.0).unwrap_or_default();
Ok(PyKeplerian(Keplerian::new(
time,
origin,
Expand All @@ -311,8 +311,8 @@ impl PyKeplerian {
self.0.time()
}

fn origin(&self) -> PyObject {
self.0.origin().into()
fn origin(&self) -> PyOrigin {
PyOrigin(self.0.origin())
}

fn semi_major_axis(&self) -> f64 {
Expand Down Expand Up @@ -350,7 +350,7 @@ impl PyKeplerian {

#[pyclass(name = "Trajectory", module = "lox_space", frozen)]
#[derive(Debug, Clone)]
pub struct PyTrajectory(pub Trajectory<PyTime, PyBody, PyFrame>);
pub struct PyTrajectory(pub Trajectory<PyTime, DynOrigin, DynFrame>);

impl From<TrajectoryError> for PyErr {
fn from(err: TrajectoryError) -> Self {
Expand Down Expand Up @@ -637,7 +637,7 @@ impl PyGroundLocation {
}

#[pyclass(name = "GroundPropagator", module = "lox_space", frozen)]
pub struct PyGroundPropagator(GroundPropagator<PyPlanet, PyUt1Provider>);
pub struct PyGroundPropagator(GroundPropagator<DynOrigin, PyUt1Provider>);

impl From<GroundPropagatorError> for PyErr {
fn from(err: GroundPropagatorError) -> Self {
Expand Down Expand Up @@ -739,8 +739,8 @@ impl PySgp4 {
pytime,
s1.position(),
s1.velocity(),
PyBody::Planet(PyPlanet::new("Earth").unwrap()),
PyFrame::Icrf,
DynOrigin::default(),
DynFrame::default(),
)),
)?
.into_any());
Expand All @@ -762,7 +762,7 @@ impl PySgp4 {
PyBody::Planet(PyPlanet::new("Earth").unwrap()),
PyFrame::Icrf,
);
let states: Vec<State<PyTime, PyBody, PyFrame>> = trajectory
let states: Vec<State<PyTime, DynOrigin, DynFrame>> = trajectory
.states()
.iter()
.map(|s| {
Expand Down Expand Up @@ -886,7 +886,7 @@ impl PyElevationMask {
}

#[pyclass(name = "Topocentric", module = "lox_space", frozen)]
pub struct PyTopocentric(pub Topocentric<PyPlanet>);
pub struct PyTopocentric(pub Topocentric<DynOrigin>);

#[pymethods]
impl PyTopocentric {
Expand Down

0 comments on commit 9ff20a9

Please sign in to comment.