Compare commits
No commits in common. "acfd70841fb0dca2f91d8a7645a2aa16ba16b412" and "bc28d4d1726b4f258101cba3e13fa6c1215ab2e5" have entirely different histories.
acfd70841f
...
bc28d4d172
|
@ -1,7 +0,0 @@
|
||||||
using Vim.Math3d;
|
|
||||||
|
|
||||||
public interface IOrbit
|
|
||||||
{
|
|
||||||
DVector3 GetPosition(double t);
|
|
||||||
IEllipse Ellipse { get; set; }
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
using Godot;
|
|
||||||
|
|
||||||
public static class IOrbitExtensions
|
|
||||||
{
|
|
||||||
public static void Draw(this IOrbit orbit, ImmediateGeometry geo)
|
|
||||||
{
|
|
||||||
geo.Clear();
|
|
||||||
geo.Begin(Mesh.PrimitiveType.LineLoop);
|
|
||||||
geo.SetColor(new Color(1, 0, 0));
|
|
||||||
|
|
||||||
int steps = 100;
|
|
||||||
var ellipse = orbit.Ellipse;
|
|
||||||
|
|
||||||
for (int i = 0; i < steps; i++)
|
|
||||||
{
|
|
||||||
float t = i / (float)steps;
|
|
||||||
float a = t * Mathf.Tau;
|
|
||||||
|
|
||||||
var v2 = ellipse.Foci[0] + ellipse.GetPosition(a);
|
|
||||||
|
|
||||||
geo.AddVertex(new Godot.Vector3
|
|
||||||
{
|
|
||||||
x = (float)v2.X,
|
|
||||||
z = (float)v2.Y
|
|
||||||
});
|
|
||||||
}
|
|
||||||
geo.End();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@ using Godot;
|
||||||
using System;
|
using System;
|
||||||
using Vim.Math3d;
|
using Vim.Math3d;
|
||||||
|
|
||||||
public struct Ellipse : IEllipse
|
public struct Ellipse
|
||||||
{
|
{
|
||||||
public Ellipse(double a = 1, double e = 0)
|
public Ellipse(double a = 1, double e = 0)
|
||||||
{
|
{
|
||||||
|
@ -12,16 +12,6 @@ public struct Ellipse : IEllipse
|
||||||
// TODO: this is an immutable struct, so initialise everything else
|
// TODO: this is an immutable struct, so initialise everything else
|
||||||
// in the constructor to avoid recalculating properties whenever
|
// in the constructor to avoid recalculating properties whenever
|
||||||
// they are accessed
|
// they are accessed
|
||||||
|
|
||||||
Apisides = new Apisides(a, e);
|
|
||||||
b = Math.Sqrt(Apisides.max * Apisides.min);
|
|
||||||
|
|
||||||
var d = Math.Sqrt(a * a - b * b);
|
|
||||||
Foci = new DVector2[]
|
|
||||||
{
|
|
||||||
new DVector2(-d, 0),
|
|
||||||
new DVector2(d, 0)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -39,7 +29,8 @@ public struct Ellipse : IEllipse
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Semi-minor axis
|
/// Semi-minor axis
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double b { get; }
|
public double b => SemiMinorAxis;
|
||||||
|
public double SemiMinorAxis => Math.Sqrt(Apisides.max * Apisides.min);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a position on the auxiliary circle
|
/// Get a position on the auxiliary circle
|
||||||
|
@ -49,10 +40,13 @@ public struct Ellipse : IEllipse
|
||||||
public DVector2 GetAuxiliaryPosition2D(double t = 0) =>
|
public DVector2 GetAuxiliaryPosition2D(double t = 0) =>
|
||||||
new DVector2(Math.Cos(t), Math.Sin(t)) * a;
|
new DVector2(Math.Cos(t), Math.Sin(t)) * a;
|
||||||
|
|
||||||
private Apisides Apisides { get; }
|
private Apisides Apisides => new Apisides(a, e);
|
||||||
|
|
||||||
public DVector2[] Foci { get; }
|
public DVector2 GetPosition(double t) =>
|
||||||
|
new DVector2(Math.Cos(t) * a, Math.Sin(t) * b);
|
||||||
|
|
||||||
|
public DVector2 Focus0 => new DVector2(-GetFocusDistance(), 0);
|
||||||
|
public DVector2 Focus1 => new DVector2(GetFocusDistance(), 0);
|
||||||
private double GetFocusDistance() => Math.Sqrt(a * a - b * b);
|
private double GetFocusDistance() => Math.Sqrt(a * a - b * b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
using Godot;
|
|
||||||
using System;
|
|
||||||
using Vim.Math3d;
|
|
||||||
|
|
||||||
public interface IEllipse
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Semi-major axis
|
|
||||||
/// </summary>
|
|
||||||
double a { get; }
|
|
||||||
double b { get; }
|
|
||||||
/// <summary>
|
|
||||||
/// Eccentricity
|
|
||||||
/// </summary>
|
|
||||||
double e { get; }
|
|
||||||
/// <summary>
|
|
||||||
/// Positions of the two foci of the ellipse
|
|
||||||
/// </summary>
|
|
||||||
DVector2[] Foci { get; }
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
using Vim.Math3d;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
public static class IEllipseExtensions
|
|
||||||
{
|
|
||||||
public static DVector2 GetPosition(this IEllipse e, double t) =>
|
|
||||||
new DVector2(Math.Cos(t) * e.a, Math.Sin(t) * e.b);
|
|
||||||
}
|
|
Loading…
Reference in New Issue