From 6f79458d6666c3632b339872cc407e0a2743868b Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Mon, 5 Sep 2022 22:13:53 +0100 Subject: [PATCH] WIP - RESET THIS --- scripts/orbits/IMassiveExtensions.cs | 4 ++ scripts/orbits/IOrbit.cs | 7 +++ scripts/orbits/IOrbitalElementsExtensions.cs | 13 ++++++ scripts/orbits/Orbit.cs | 2 +- scripts/orbits/OrbitalElements.cs | 46 ++++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 scripts/orbits/IMassiveExtensions.cs create mode 100644 scripts/orbits/IOrbit.cs create mode 100644 scripts/orbits/IOrbitalElementsExtensions.cs create mode 100644 scripts/orbits/OrbitalElements.cs diff --git a/scripts/orbits/IMassiveExtensions.cs b/scripts/orbits/IMassiveExtensions.cs new file mode 100644 index 0000000..6f4cf1a --- /dev/null +++ b/scripts/orbits/IMassiveExtensions.cs @@ -0,0 +1,4 @@ +public static class IMassiveExtensions +{ + public static double U(this IMassive m) => Kepler.U(m.Mass); +} \ No newline at end of file diff --git a/scripts/orbits/IOrbit.cs b/scripts/orbits/IOrbit.cs new file mode 100644 index 0000000..6bbbb05 --- /dev/null +++ b/scripts/orbits/IOrbit.cs @@ -0,0 +1,7 @@ +using Vim.Math3d; + +public interface IOrbit +{ + Ellipse Ellipse { get; } + DVector3 GetPosition(float t); +} \ No newline at end of file diff --git a/scripts/orbits/IOrbitalElementsExtensions.cs b/scripts/orbits/IOrbitalElementsExtensions.cs new file mode 100644 index 0000000..f8dbda1 --- /dev/null +++ b/scripts/orbits/IOrbitalElementsExtensions.cs @@ -0,0 +1,13 @@ +using Vim.Math3d; +using static System.Math; + +public static class IOrbitalElementsExtensions +{ + /// + /// Get the Cartesian position on the orbit for a given mean anomaly. + /// + /// Mean anomaly + /// Position + public static DVector2 GetEccentricPosition2D(this OrbitalElements elements, double M) => + Kepler.GetEccentricPosition2D(elements.e, elements.a, M); +} \ No newline at end of file diff --git a/scripts/orbits/Orbit.cs b/scripts/orbits/Orbit.cs index 3ebab6c..147aa8f 100644 --- a/scripts/orbits/Orbit.cs +++ b/scripts/orbits/Orbit.cs @@ -2,7 +2,7 @@ using Godot; using System; using Vim.Math3d; -public class Orbit +public class Orbit : IOrbit { // The position of the primary body relative to the ellipse - the // orbit itself is presented as being centred on the primary, but diff --git a/scripts/orbits/OrbitalElements.cs b/scripts/orbits/OrbitalElements.cs new file mode 100644 index 0000000..c501dc8 --- /dev/null +++ b/scripts/orbits/OrbitalElements.cs @@ -0,0 +1,46 @@ +public struct OrbitalElements +{ + private Ellipse _ellipse; + /// + /// Semi-major axis in AU + /// + public double a => _ellipse.a; + /// + /// Eccentricity + /// + public double e => _ellipse.e; + /// + /// Inclination in degrees + /// + public double i { get; private set; } + /// + /// Argument of ascending node in degrees + /// + public double W { get; private set; } + /// + /// Argument of periapsis in degrees + /// + public double p { get; private set; } + /// + /// Mean anomaly at epoch + /// + public double M0 { get; private set; } + + /// + /// + /// + /// Semi-major axis in AU + /// eccentricity + /// Inclination in degrees + /// Argument of ascending node in degrees + /// Argument of periapsis in degrees + /// Mean anomaly at epoch + public OrbitalElements(double a, double e, double i, double W, double p, double M0) + { + _ellipse = new Ellipse(a, e); + this.i = i; + this.W = W; + this.p = p; + this.M0 = M0; + } +} \ No newline at end of file