In my current game project, I'm developing a primary user interface that displays the solar system from a top-down perspective (with Earth's north pole as 'up'). One of the challenges I faced was creating a semi-realistic path for an object traveling between planets. To tackle this, I've been using Lambert's problem to calculate the initial velocity vector for the object, and the results have been promising for the game.
After spending a few weeks on this issue, I even turned to ChatGPT-4 for assistance with the complex math involved. While I made progress at times, I struggled to arrive at the correct solution consistently.
One recurring issue I encountered was obtaining negative values for the a
parameter (semi-major-axis of the ellipse), which shouldn't be the case.
I suspected one reason for this discrepancy could be the disparity in coordinate systems used in my game (left-handed) versus traditional mathematical calculations (right-handed). In order to address this, I inverted the y-values during vector calculations and ensured proper inversion for screen display. I also experimented with reversing the entire coordinate system, but the outcomes were similar.
Below is the TypeScript implementation of the logic responsible for generating the current elliptical path:
Following multiple iterations of custom Lambert problem solvers and aided by AI, I opted to utilize the lambert-orbit package, which provided the functionality I required along with additional useful features.
Furthermore, here is an excerpt from my vector class implementation:
For instance, when passing the given parameters to the generatePath
method, the resulting data includes a velocity vector and various calculated values like the semi-major axis and the second foci point.
A visual representation of the computed ellipse shows discrepancies in intersecting the designated locations correctly, prompting reflections on possible causes and adjustments needed.
The journey to achieving accurate orbital paths continues as ongoing tests and observations shed light on potential solutions to refine the game's trajectory simulation.