You are browsing as a guest. Sign up (or log in) to start making projects!

Lagrange Point Calculator

  • 1 Devlogs
  • 2 Total hours

A calculator that takes the masses and distance of 2 bodies. It then uses this information to calculate the locations of the Lagrange points L1-5.

Ship #1 Changes requested

Dimensionless Lagrange Point Visualizer

The breakthrough - Dimensionless Units
Using units like meters, or kilometers comes with large scaling challenges with the large distances in outer space. To combat this, I pivoted to a dimensionless unit system. This places the star at 0,0 with the Earth (on the sun-earth preset) at 10,0 , exactly 10 units away. this places Lagrange points 1-3 at relatively round numbers compared to the actual values that would've been calculated if meters or kilometers were used. This makes it easier for the user to visualize relative distances between Lagrange points compared to that between the star and planet

The maths engine - how it works
The background script automatically parses information inputted by the user using standard Lagrange point calculations. For points L1–3, the Y-value is always the same as that of the planet or star since they sit on a straight line. For the triangular points, L4 sits 60° ahead of the planet along its orbit, and L5 sits 60° behind it. To work these out, the engine maps perfect equilateral triangles into 2D space using the Star and the Planet as the base vertices. Using standard trigonometric functions, the script is able to plot the 2 nodes onto the plane.

Features
A vector diagram on the right displaying: The star, The planet, The planet's orbital path, Lagrange points L1-5 and whether they are stable or not

A sidebar on the left that has multiple presets and a manual slider mode

A Sun-Earth scenario where the L points of the sun and earth are defined

A Sun-Jupiter scenario where the L points of the sun and Jupiter are defined

An inverse scenario where the planet outweighs it's host star

A Manual slider setting where the masses of the star and planet can be changed and the orbital radius of the planet can be changed.

  • 1 devlog
  • 2h
  • 8.26x multiplier
  • 16 Stardust
Try project → See source code →
Open comments for this post

1h 53m 15s logged

Project Complete: Evolving the Lagrange Calculator from 1D Math to Interactive Web App

Self-reflection note: I got so incredibly locked into solving the math, debugging the terminal environment, and optimizing the graphics that I completely forgot to frequently upload individual devlogs along the way! So, here is my entire multi-day engineering journey packed into one comprehensive project chronicle.

What started as a raw physics equation in a terminal has been fully built out into an interactive browser dashboard! Here is a detailed look at the complete development journey and the engineering hurdles I cleared to make this simulation engine work:

I began by coding the absolute foundations of orbital mechanics in Python. Using the mass parameters of the Sun ($1.989 \times 10^{30}\text{ kg}$) and Earth ($5.972 \times 10^{24}\text{ kg}$), I derived the system mass ratio ($\mu$) and solved the planetary sphere of influence using the Hill Radius calculation:
r_h = R * (mu / 3) ** (1/3)
This successfully output the exact locations of the collinear L1, L2, and L3 points directly to the terminal console.

Text outputs aren’t enough to see space geometry, so I integrated Matplotlib to map the system visually. Using equilateral triangle geometry ($\cos(60^\circ)$ and $\sin(60^\circ)$ rules), I mapped out the stable L4 and L5 points. I applied a clean light-mode interface canvas and resolved a massive coordinate scaling bug by forcing the aspect ratios to stay square so the markers wouldn’t flatten out or disappear.

Next, I tried to calculate a general relativity-inspired mesh grid that bent toward the star and planet. While the vertical line bowing worked beautifully, I discovered a massive cosmic scaling issue: because the real-world mass gaps and distance parameters are so vast ($150\text{ billion meters}$), the planet’s gravity well was a microscopic dot compared to the star, causing lines to collapse and text to overlap.

The Solution: I pivoted to Dimensionless Units. I locked the Sun at (0,0), the planet orbit path at a clean radius of 10, and allowed all Lagrange coordinates to calculate dynamically relative to that fixed 10-unit visual workspace framework.

To turn this into a true interactive app, I migrated the script over to the Streamlit web framework. I built three reactive sidebar sliders allowing anyone to manipulate the Star Mass, Planet Mass, and Orbit Scale dynamically. The browser app crunches the math live, showing metric cards on the left and re-rendering the vector graphic map instantly on the right.

I wrote a preset engine so users can toggle between real-world balances like Sun-Earth, Sun-Jupiter, and a physics-breaking “Inverse Scenario” where the planet completely out-masses the star!


Codebase and full structural system checklist have been officially deployed and pushed to my public GitHub repository!

**Note: The attached image shows the sun-earth system preset

0
0
1

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…