Original idea by elplanetaerrante.
First prototype
Seccond prototype
Current version
- Change the color of the barycenter to better differentiate it from the stars.
- Add mention to elplanetaerrante
- Add tool tips with explanation on what is each variable.
- Add a bit of space on top.
- Make sliders bigger for mobile.
- Change github link to repo link.
- Fix orbital period
The process of simulating the two body problem in real time with the mass ratio, excentricity and semi-major axis as parameters was not an easy task. Fortunatelly I was able to come with a solution to do this, that works well enough to give an aqurate representation of the orbits in real time.
The orbit of the blue planet is created based on it’s excentricity and semi-mayor axis. It’s right foci is centered in the canvas. This foci will become the baricenter later.
While the orbit itself is easy to create, ensuring that the planet moves at the right speed at each time is not. For this we need the funtion
A line that connects a planet to the sun sweeps out equal areas in equal times.
Adapting it to a two body problem where the center is not the sun but the baricenter. With this we know that
Since we know the position based on an angle:
If we can get the angle based on an area ($\theta(A)$) then we’ll have our
To calculate this we first can get
Since getting the inverse of
With
With this we can calculate the position of the blue planet for any given area swept, now we just animate the area going from 0% of the elipse to 100% in a linear manner and we get a proportional movement for the planet.
With the position of the blue planet, we can get the position of the red planet by simply using the fact that the center of mass of both will stay at the baricenter.
Thanks to that we can know the position of the two planets at any time based on the semi mayor axis and the eccentricity. The mass ratio between the planets comes into play because it dictates the semi mayor axis of the orbit used to calculate the orbital period.