Compare commits

...

1 Commits

Author SHA1 Message Date
Cat Flynn 6f79458d66 WIP - RESET THIS 2022-09-05 22:14:30 +01:00
5 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,4 @@
public static class IMassiveExtensions
{
public static double U(this IMassive m) => Kepler.U(m.Mass);
}

7
scripts/orbits/IOrbit.cs Normal file
View File

@ -0,0 +1,7 @@
using Vim.Math3d;
public interface IOrbit
{
Ellipse Ellipse { get; }
DVector3 GetPosition(float t);
}

View File

@ -0,0 +1,13 @@
using Vim.Math3d;
using static System.Math;
public static class IOrbitalElementsExtensions
{
/// <summary>
/// Get the Cartesian position on the orbit for a given mean anomaly.
/// </summary>
/// <param name="M">Mean anomaly</param>
/// <returns>Position</returns>
public static DVector2 GetEccentricPosition2D(this OrbitalElements elements, double M) =>
Kepler.GetEccentricPosition2D(elements.e, elements.a, M);
}

View File

@ -2,7 +2,7 @@ using Godot;
using System; using System;
using Vim.Math3d; using Vim.Math3d;
public class Orbit public class Orbit : IOrbit
{ {
// The position of the primary body relative to the ellipse - the // The position of the primary body relative to the ellipse - the
// orbit itself is presented as being centred on the primary, but // orbit itself is presented as being centred on the primary, but

View File

@ -0,0 +1,46 @@
public struct OrbitalElements
{
private Ellipse _ellipse;
/// <summary>
/// Semi-major axis in AU
/// </summary>
public double a => _ellipse.a;
/// <summary>
/// Eccentricity
/// </summary>
public double e => _ellipse.e;
/// <summary>
/// Inclination in degrees
/// </summary>
public double i { get; private set; }
/// <summary>
/// Argument of ascending node in degrees
/// </summary>
public double W { get; private set; }
/// <summary>
/// Argument of periapsis in degrees
/// </summary>
public double p { get; private set; }
/// <summary>
/// Mean anomaly at epoch
/// </summary>
public double M0 { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="a">Semi-major axis in AU</param>
/// <param name="e">eccentricity</param>
/// <param name="i">Inclination in degrees</param>
/// <param name="W">Argument of ascending node in degrees</param>
/// <param name="p">Argument of periapsis in degrees</param>
/// <param name="M0">Mean anomaly at epoch</param>
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;
}
}