diff --git a/src/client/screens/launch/orbitPhase.ts b/src/client/screens/launch/orbitPhase.ts index 0d409b3..22c3818 100644 --- a/src/client/screens/launch/orbitPhase.ts +++ b/src/client/screens/launch/orbitPhase.ts @@ -133,6 +133,16 @@ export function enterOrbitPhase(ctx: LaunchContext): void { const curvePts = pts.map( (p) => new THREE.Vector3(p.x * visScale, p.y * visScale, p.z * visScale), ); + const first = curvePts[0]; + const last = curvePts[curvePts.length - 1]; + const gap = first.distanceTo(last); + const orbitSpan = Math.max( + ...curvePts.map((p) => Math.hypot(p.x, p.y, p.z)), + 1, + ); + if (gap > 1e-3 && gap < orbitSpan * 0.08) { + curvePts.push(first.clone()); + } const lineGeo = new THREE.BufferGeometry().setFromPoints(curvePts); const line = new THREE.Line( lineGeo, diff --git a/src/server/gmat_runner.ts b/src/server/gmat_runner.ts index 5750909..0ccff7a 100644 --- a/src/server/gmat_runner.ts +++ b/src/server/gmat_runner.ts @@ -245,7 +245,12 @@ export async function runTrajectory( : baseDef.sma, inc: opts.incDeg ?? baseDef.inc, }; - const durationSec = def.days * 86400; + const orb = orbitForTarget(key, opts); + const durationSec = Math.max(def.days * 86400, orb.period); + const scriptDef = + durationSec > def.days * 86400 + ? { ...def, days: durationSec / 86400 } + : def; const analytic = generateTrajectory(key, durationSec, 280, opts); const consoleBin = resolveGmatConsoleBin(); if (!consoleBin) { @@ -265,20 +270,19 @@ export async function runTrajectory( fs.unlink(logPath, () => {}); }; try { - fs.writeFileSync(scriptPath, buildGmatScript(def)); + fs.writeFileSync(scriptPath, buildGmatScript(scriptDef)); const { stdout } = await execFileAsync( consoleBin, ["-l", logPath, "-r", scriptPath], { cwd: gmatDir, - timeout: 30_000, + timeout: 60_000, maxBuffer: 32 * 1024 * 1024, }, ); cleanup(); const points = parseGmatStdout(stdout); if (points.length > 10) { - const orb = orbitForTarget(key, opts); const enriched = points.map((p, idx) => { const t = (idx / (points.length - 1)) * durationSec; const analyticPt = diff --git a/src/shared/ephemeris.ts b/src/shared/ephemeris.ts index c77cdc5..db48d5a 100644 --- a/src/shared/ephemeris.ts +++ b/src/shared/ephemeris.ts @@ -492,14 +492,7 @@ export function generateTrajectory( opts: { altKm?: number; incDeg?: number; ecc?: number } = {}, ): TrajectoryResult { const orb = orbitForTarget(target, opts); - const totalSec = - durationSec ?? - Math.min( - orb.period, - target === "mars" || target === "jupiter" || target === "solar" - ? 180 * 86400 - : orb.period, - ); + const totalSec = durationSec ?? orb.period; const dt = totalSec / numPoints; const points: TrajectoryPoint[] = []; for (let i = 0; i <= numPoints; i++) {