From e2c706ecb04ea8267c402efc54346e90a1d5017e Mon Sep 17 00:00:00 2001 From: Lucy Date: Thu, 21 May 2026 20:35:17 +0200 Subject: [PATCH] Fix: recompute sun-frame trail and SOI crossings after flyby After SOI exit the asteroid has new orbital elements (gravity assist). Previously the old trail and crossing predictions were never updated, causing three bugs: 1. Old trajectory still drawn after exit 2. Next SOI entry time based on stale orbit 3. Subsequent SOI entries never triggered Now on exit: recompute trail, rescans for future SOI crossings, and resets the crossing index. --- visual_test.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/visual_test.py b/visual_test.py index 8f64164..1388588 100644 --- a/visual_test.py +++ b/visual_test.py @@ -247,15 +247,24 @@ def main() -> None: asteroid_planet = None soi_exit_time = None - # Advance to next crossing - cross_idx += 1 - while cross_idx < len(sun_crossings): - if sun_crossings[cross_idx][0] > sim_time + 0.1: - soi_enter_time = sun_crossings[cross_idx][0] - break - cross_idx += 1 - else: - soi_enter_time = None + # ── Recompute trail from new sun orbit ────── + trail_asteroid_sun = [ + to_screen(x, y) for x, y in + generate_orbit_points(asteroid_sun) + ] + + # ── Recompute future SOI crossings ─────────── + window = SEARCH_ORBITS * max(asteroid_sun.period, PLANET.period) + sun_crossings = find_soi_crossings( + asteroid_sun, PLANET, SOI_RADIUS, + sim_time + 0.1, sim_time + window, n_steps=1000, + ) + print(f" Re-scanned: found {len(sun_crossings)} future crossing(s)") + for i, (enter, _) in enumerate(sun_crossings): + print(f" [{i}] enter={enter:.1f}s") + + cross_idx = 0 + soi_enter_time = sun_crossings[0][0] if sun_crossings else None # ── Compute current positions ────────────────────── px, py = PLANET.position_at(sim_time)