Added reverse callculation code. Unsure about quality yet.
This commit is contained in:
@@ -97,27 +97,36 @@ public sealed partial class Krakensbane : Node3D
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
ImGui.Begin("Krakensbane");
|
||||
ImGui.Text($"Origin: {originPosition}");
|
||||
ImGui.Text($"Focused vessel: {FocusedVessel?.Name}");
|
||||
|
||||
// Debug the orbit of the focused vessel
|
||||
KeplerianElements? elements = null;
|
||||
if (FocusedVessel != null && FocusedVessel is RigidBody3D rigidBody3D)
|
||||
{
|
||||
var position = GetPositionOf(rigidBody3D);
|
||||
var velocity = rigidBody3D.LinearVelocity.AsVim().AsDouble();
|
||||
var state = new DStateVector(position, velocity);
|
||||
elements = KeplerianElements.FromMotionState(state, celestialBody.Mu);
|
||||
}
|
||||
|
||||
ImGui.Begin("Krakensbane");
|
||||
ImGui.Text($"Origin: {originPosition}");
|
||||
ImGui.Text($"Focused vessel: {FocusedVessel?.Name}");
|
||||
if (elements != null)
|
||||
{
|
||||
var (elements, epoch) = KeplerianElements.FromMotionStateFull(state, celestialBody.Mu);
|
||||
ImGui.Text("Orbit");
|
||||
ImGui.BeginGroup();
|
||||
ImGui.Indent();
|
||||
ImGui.Text($"Ap: {elements.Apoapsis}");
|
||||
ImGui.Text($"Pe: {elements.Periapsis}");
|
||||
ImGui.Text($"Period: {elements.Period(celestialBody.Mu)}");
|
||||
ImGui.EndGroup();
|
||||
ImGui.Text($"Inclination: {elements.IncDegree}deg");
|
||||
ImGui.Text($"Epoch: {epoch}");
|
||||
ImGui.Unindent();
|
||||
|
||||
// Roundtrip test
|
||||
var newState = elements.MotionStateAt(celestialBody.Mu, epoch);
|
||||
ImGui.Text("Roundtrip test");
|
||||
ImGui.Indent();
|
||||
ImGui.Text($"Original position: {position:F6}");
|
||||
ImGui.Text($"New position: {newState.Position:F6}");
|
||||
ImGui.Text($"Original velocity: {velocity:F6}");
|
||||
ImGui.Text($"New velocity: {newState.Velocity:F6}");
|
||||
ImGui.Unindent();
|
||||
}
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user