From 81f239e088dcc471e7530853dda8a61665180ba9 Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Thu, 15 Aug 2024 09:58:19 +0200 Subject: [PATCH 1/7] frame.rs: add two new methods Signed-off-by: Guillaume W. Bres --- anise/src/frames/frame.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/anise/src/frames/frame.rs b/anise/src/frames/frame.rs index 76ee22e9..df32b10e 100644 --- a/anise/src/frames/frame.rs +++ b/anise/src/frames/frame.rs @@ -77,6 +77,18 @@ impl Frame { Ok(Self::new(ephemeris_id, orientation_id)) } + + /// Define Ellipsoid shape and return a new [Frame] + pub fn with_ellipsoid(&self, shape: Ellipsoid) -> Self { + let mut s = self.clone(); + s.shape = Some(shape); + s + } + + /// Define Ellipsoid shape with mutable access + pub fn set_ellipsoid(&mut self, shape: Ellipsoid) { + self.shape = Some(shape); + } } #[cfg_attr(feature = "python", pymethods)] From a7b9d9f5268c3ec7e88ef94787b47df2a81d5d29 Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Thu, 15 Aug 2024 09:58:39 +0200 Subject: [PATCH 2/7] Define WGS84 and CGCS20 Ellipsoid shapes Signed-off-by: Guillaume W. Bres --- .../src/structure/planetocentric/ellipsoid.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/anise/src/structure/planetocentric/ellipsoid.rs b/anise/src/structure/planetocentric/ellipsoid.rs index abf039f4..2a4e4384 100644 --- a/anise/src/structure/planetocentric/ellipsoid.rs +++ b/anise/src/structure/planetocentric/ellipsoid.rs @@ -58,6 +58,40 @@ impl Ellipsoid { polar_radius_km, } } + + /// Builds new WGS84 Ellipsoid shape, used by all GPS vehicles. + /// + pub const fn gps_wgs84() -> Self { + const FLATTENING: f64 = 1.0 / 298.257223563_f64; + const SEMI_MAJOR_EQUATORIAL_RADIUS_KM: f64 = 6378.137_f64; + const SEMI_MINOR_EQUATORIAL_RADIUS_KM: f64 = 6356.7523142_f64; + // mean equatorial radius R = (M+m)/2 + const R: f64 = (SEMI_MAJOR_EQUATORIAL_RADIUS_KM + SEMI_MINOR_EQUATORIAL_RADIUS_KM) / 2.0; + // flattening = (R - p)/R + const POLAR_RADIUS_KM: f64 = R - FLATTENING * R; + Self { + polar_radius_km: POLAR_RADIUS_KM, + semi_major_equatorial_radius_km: SEMI_MAJOR_EQUATORIAL_RADIUS_KM, + semi_minor_equatorial_radius_km: SEMI_MINOR_EQUATORIAL_RADIUS_KM, + } + } + + /// Builds new BDC (CGCS20) Ellipsoid shape, used by all BeiDou vehicles. + /// + pub fn beidou_cgcs20() -> Self { + const FLATTENING: f64 = 1.0 / 298.257222101; + const SEMI_MAJOR_EQUATORIAL_RADIUS_KM: f64 = 6378.137_f64; + const SEMI_MINOR_EQUATORIAL_RADIUS_KM: f64 = 6356.7523141_f64; + // mean equatorial radius R = (M+m)/2 + const R: f64 = (SEMI_MAJOR_EQUATORIAL_RADIUS_KM + SEMI_MINOR_EQUATORIAL_RADIUS_KM) / 2.0; + // flattening = (R - p)/R + const POLAR_RADIUS_KM: f64 = R - FLATTENING * R; + Self { + polar_radius_km: POLAR_RADIUS_KM, + semi_major_equatorial_radius_km: SEMI_MAJOR_EQUATORIAL_RADIUS_KM, + semi_minor_equatorial_radius_km: SEMI_MINOR_EQUATORIAL_RADIUS_KM, + } + } } #[cfg_attr(feature = "python", pymethods)] From 8af7c8a06dc519adb74e0fae49a693670ac7d09a Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Thu, 15 Aug 2024 10:17:46 +0200 Subject: [PATCH 3/7] Add macros to build Orbits with shapes directly Signed-off-by: Guillaume W. Bres --- anise/src/math/cartesian.rs | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/anise/src/math/cartesian.rs b/anise/src/math/cartesian.rs index d50ddd04..2d744f53 100644 --- a/anise/src/math/cartesian.rs +++ b/anise/src/math/cartesian.rs @@ -14,6 +14,7 @@ use crate::{ constants::SPEED_OF_LIGHT_KM_S, errors::{EpochMismatchSnafu, FrameMismatchSnafu, PhysicsError}, prelude::Frame, + structure::planetocentric::ellipsoid::Ellipsoid, }; use core::fmt; @@ -123,6 +124,52 @@ impl CartesianState { ) } + /// Creates a new [CartesianState] for a GPS vehicle position, + /// expressed in proposed [Frame] that we augment with appropriate + /// [Ellipsoid] shape. + /// + /// **Units:** km, km, km + pub fn from_gps_position(x_km: f64, y_km: f64, z_km: f64, epoch: Epoch, frame: Frame) -> Self { + let wgs84 = frame.with_ellipsoid(Ellipsoid::gps_wgs84()); + Self::new(x_km, y_km, z_km, 0.0, 0.0, 0.0, epoch, wgs84) + } + + /// Creates a new [CartesianState] from a GPS state vector, in the proposed [Frame] to which we apply the appropriate [Ellipsoid] shape. + /// + /// **Units:** position data must be in kilometers, velocity data must be in kilometers per second. + pub fn from_gps_pos_vel(pos_vel: Vector6, epoch: Epoch, frame: Frame) -> Self { + let wgs84 = frame.with_ellipsoid(Ellipsoid::gps_wgs84()); + Self::new( + pos_vel[0], pos_vel[1], pos_vel[2], pos_vel[3], pos_vel[4], pos_vel[5], epoch, wgs84, + ) + } + + /// Creates a new [CartesianState] for BeiDou (BDS) vehicle, + /// expressed in proposed [Frame] that we augment with appropriate + /// [Ellipsoid] shape. + /// + /// **Units:** km, km, km + pub fn from_beidou_position( + x_km: f64, + y_km: f64, + z_km: f64, + epoch: Epoch, + frame: Frame, + ) -> Self { + let cgcs20 = frame.with_ellipsoid(Ellipsoid::beidou_cgcs20()); + Self::new(x_km, y_km, z_km, 0.0, 0.0, 0.0, epoch, cgcs20) + } + + /// Creates a new [CartesianState] from a BDS state vector, in the proposed [Frame] to which we apply the appropriate [Ellipsoid] shape. + /// + /// **Units:** position data must be in kilometers, velocity data must be in kilometers per second. + pub fn from_beidou_pos_vel(pos_vel: Vector6, epoch: Epoch, frame: Frame) -> Self { + let cgcs20 = frame.with_ellipsoid(Ellipsoid::beidou_cgcs20()); + Self::new( + pos_vel[0], pos_vel[1], pos_vel[2], pos_vel[3], pos_vel[4], pos_vel[5], epoch, cgcs20, + ) + } + /// Returns a copy of the state with a new radius pub fn with_radius_km(self, new_radius_km: Vector3) -> Self { let mut me = self; From b2dff2a8f3c9a4d6262e0abe0de32537a95635ba Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Wed, 21 Aug 2024 08:07:34 +0200 Subject: [PATCH 4/7] Remove set_ellipsoid Signed-off-by: Guillaume W. Bres --- anise/src/frames/frame.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/anise/src/frames/frame.rs b/anise/src/frames/frame.rs index df32b10e..9bd1ae60 100644 --- a/anise/src/frames/frame.rs +++ b/anise/src/frames/frame.rs @@ -84,11 +84,6 @@ impl Frame { s.shape = Some(shape); s } - - /// Define Ellipsoid shape with mutable access - pub fn set_ellipsoid(&mut self, shape: Ellipsoid) { - self.shape = Some(shape); - } } #[cfg_attr(feature = "python", pymethods)] From 6710f5bb7d0b7a82fdd96d9100fcf7576cfbd83b Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Wed, 21 Aug 2024 13:43:54 +0200 Subject: [PATCH 5/7] Remove frame definitions: moved to gnss lib Signed-off-by: Guillaume W. Bres --- anise/src/math/cartesian.rs | 46 ------------------- .../src/structure/planetocentric/ellipsoid.rs | 34 -------------- 2 files changed, 80 deletions(-) diff --git a/anise/src/math/cartesian.rs b/anise/src/math/cartesian.rs index 2d744f53..e72eb5f9 100644 --- a/anise/src/math/cartesian.rs +++ b/anise/src/math/cartesian.rs @@ -124,52 +124,6 @@ impl CartesianState { ) } - /// Creates a new [CartesianState] for a GPS vehicle position, - /// expressed in proposed [Frame] that we augment with appropriate - /// [Ellipsoid] shape. - /// - /// **Units:** km, km, km - pub fn from_gps_position(x_km: f64, y_km: f64, z_km: f64, epoch: Epoch, frame: Frame) -> Self { - let wgs84 = frame.with_ellipsoid(Ellipsoid::gps_wgs84()); - Self::new(x_km, y_km, z_km, 0.0, 0.0, 0.0, epoch, wgs84) - } - - /// Creates a new [CartesianState] from a GPS state vector, in the proposed [Frame] to which we apply the appropriate [Ellipsoid] shape. - /// - /// **Units:** position data must be in kilometers, velocity data must be in kilometers per second. - pub fn from_gps_pos_vel(pos_vel: Vector6, epoch: Epoch, frame: Frame) -> Self { - let wgs84 = frame.with_ellipsoid(Ellipsoid::gps_wgs84()); - Self::new( - pos_vel[0], pos_vel[1], pos_vel[2], pos_vel[3], pos_vel[4], pos_vel[5], epoch, wgs84, - ) - } - - /// Creates a new [CartesianState] for BeiDou (BDS) vehicle, - /// expressed in proposed [Frame] that we augment with appropriate - /// [Ellipsoid] shape. - /// - /// **Units:** km, km, km - pub fn from_beidou_position( - x_km: f64, - y_km: f64, - z_km: f64, - epoch: Epoch, - frame: Frame, - ) -> Self { - let cgcs20 = frame.with_ellipsoid(Ellipsoid::beidou_cgcs20()); - Self::new(x_km, y_km, z_km, 0.0, 0.0, 0.0, epoch, cgcs20) - } - - /// Creates a new [CartesianState] from a BDS state vector, in the proposed [Frame] to which we apply the appropriate [Ellipsoid] shape. - /// - /// **Units:** position data must be in kilometers, velocity data must be in kilometers per second. - pub fn from_beidou_pos_vel(pos_vel: Vector6, epoch: Epoch, frame: Frame) -> Self { - let cgcs20 = frame.with_ellipsoid(Ellipsoid::beidou_cgcs20()); - Self::new( - pos_vel[0], pos_vel[1], pos_vel[2], pos_vel[3], pos_vel[4], pos_vel[5], epoch, cgcs20, - ) - } - /// Returns a copy of the state with a new radius pub fn with_radius_km(self, new_radius_km: Vector3) -> Self { let mut me = self; diff --git a/anise/src/structure/planetocentric/ellipsoid.rs b/anise/src/structure/planetocentric/ellipsoid.rs index 2a4e4384..abf039f4 100644 --- a/anise/src/structure/planetocentric/ellipsoid.rs +++ b/anise/src/structure/planetocentric/ellipsoid.rs @@ -58,40 +58,6 @@ impl Ellipsoid { polar_radius_km, } } - - /// Builds new WGS84 Ellipsoid shape, used by all GPS vehicles. - /// - pub const fn gps_wgs84() -> Self { - const FLATTENING: f64 = 1.0 / 298.257223563_f64; - const SEMI_MAJOR_EQUATORIAL_RADIUS_KM: f64 = 6378.137_f64; - const SEMI_MINOR_EQUATORIAL_RADIUS_KM: f64 = 6356.7523142_f64; - // mean equatorial radius R = (M+m)/2 - const R: f64 = (SEMI_MAJOR_EQUATORIAL_RADIUS_KM + SEMI_MINOR_EQUATORIAL_RADIUS_KM) / 2.0; - // flattening = (R - p)/R - const POLAR_RADIUS_KM: f64 = R - FLATTENING * R; - Self { - polar_radius_km: POLAR_RADIUS_KM, - semi_major_equatorial_radius_km: SEMI_MAJOR_EQUATORIAL_RADIUS_KM, - semi_minor_equatorial_radius_km: SEMI_MINOR_EQUATORIAL_RADIUS_KM, - } - } - - /// Builds new BDC (CGCS20) Ellipsoid shape, used by all BeiDou vehicles. - /// - pub fn beidou_cgcs20() -> Self { - const FLATTENING: f64 = 1.0 / 298.257222101; - const SEMI_MAJOR_EQUATORIAL_RADIUS_KM: f64 = 6378.137_f64; - const SEMI_MINOR_EQUATORIAL_RADIUS_KM: f64 = 6356.7523141_f64; - // mean equatorial radius R = (M+m)/2 - const R: f64 = (SEMI_MAJOR_EQUATORIAL_RADIUS_KM + SEMI_MINOR_EQUATORIAL_RADIUS_KM) / 2.0; - // flattening = (R - p)/R - const POLAR_RADIUS_KM: f64 = R - FLATTENING * R; - Self { - polar_radius_km: POLAR_RADIUS_KM, - semi_major_equatorial_radius_km: SEMI_MAJOR_EQUATORIAL_RADIUS_KM, - semi_minor_equatorial_radius_km: SEMI_MINOR_EQUATORIAL_RADIUS_KM, - } - } } #[cfg_attr(feature = "python", pymethods)] From 6e27fef7747a4a2da319db48b69522cef6f54cdd Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Wed, 21 Aug 2024 13:44:25 +0200 Subject: [PATCH 6/7] Remove frame definitions: moved to gnss lib Signed-off-by: Guillaume W. Bres --- anise/src/math/cartesian.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/anise/src/math/cartesian.rs b/anise/src/math/cartesian.rs index e72eb5f9..d50ddd04 100644 --- a/anise/src/math/cartesian.rs +++ b/anise/src/math/cartesian.rs @@ -14,7 +14,6 @@ use crate::{ constants::SPEED_OF_LIGHT_KM_S, errors::{EpochMismatchSnafu, FrameMismatchSnafu, PhysicsError}, prelude::Frame, - structure::planetocentric::ellipsoid::Ellipsoid, }; use core::fmt; From 003c92bb2c1368badaf531f69da57ca4db3ea591 Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Wed, 21 Aug 2024 16:35:27 +0200 Subject: [PATCH 7/7] Frame is copyable Signed-off-by: Guillaume W. Bres --- anise/src/frames/frame.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/anise/src/frames/frame.rs b/anise/src/frames/frame.rs index 9bd1ae60..d31c8fa9 100644 --- a/anise/src/frames/frame.rs +++ b/anise/src/frames/frame.rs @@ -79,10 +79,9 @@ impl Frame { } /// Define Ellipsoid shape and return a new [Frame] - pub fn with_ellipsoid(&self, shape: Ellipsoid) -> Self { - let mut s = self.clone(); - s.shape = Some(shape); - s + pub fn with_ellipsoid(mut self, shape: Ellipsoid) -> Self { + self.shape = Some(shape); + self } }