How can I calculate planet trajectory for a 2d solar system simulation?

  • Context: Undergrad 
  • Thread starter Thread starter avpx
  • Start date Start date
  • Tags Tags
    Planet Trajectory
Click For Summary

Discussion Overview

The discussion revolves around calculating the trajectory of planets and ships in a 2D solar system simulation. Participants explore various methods for modeling gravitational interactions and orbital mechanics, addressing both theoretical and practical aspects of the simulation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks assistance in calculating the positions of planets given their mass, initial velocity, and location.
  • Another participant inquires whether the planets are orbiting each other or a fixed star, noting that the latter is simpler.
  • A participant expresses interest in both scenarios and asks how to represent a ship's ability to manipulate its orbit, questioning if a single formula can encompass both escape and crash scenarios.
  • It is noted that a star system involves n-body problems rather than just two-body problems, especially when considering gravitational interactions between multiple bodies.
  • A formula based on Newton's laws is proposed for modeling planetary motion, with a suggestion to solve differential equations for each planet independently.
  • One participant mentions the challenge of speeding up time in the simulation and the need for accurate calculations of acceleration, velocity, and position.
  • Another participant suggests that larger time jumps complicate the calculations, particularly for ships influenced by multiple gravitational forces.
  • One participant proposes simplifying calculations by considering only the strongest gravitational influence on the ship at any given time.
  • It is discussed that approximations can be made for orbits close to a planet or far from planets, with a recommendation to calculate positions relative to the planet for better accuracy.

Areas of Agreement / Disagreement

Participants express various viewpoints on the complexity of gravitational interactions and the methods for calculating trajectories. There is no consensus on a single approach, and multiple competing views remain regarding the best way to handle the simulation's calculations.

Contextual Notes

Participants acknowledge limitations in their approaches, such as the need to ignore other planets' gravitational effects to conserve processing power and the challenges of accurately simulating time jumps in the system.

avpx
Messages
12
Reaction score
0
Hello. I am programming a 2d solar system simulation for a game. All went fine until I got to this part. Tried learning it in the past 3 days but could not understand most of it. Hoped to find help hhere.
I have the location of both planets, their mass, their initial velocity and that's it. How do i calculate their location in each point in time? Thanks.
 
Astronomy news on Phys.org
Are these planets orbiting each other, or are they both orbiting a fixed star at the center of the solar system? The latter is a bit simpler but both are possible to do.
 
they all orbit they same star. but i'd be happy if you can explain me both.
Also, what if i have a ship that can manipulate its orbit, escaping it with an escape velocity and/or crushing on a planet, how would i represent this in one single formula? Is it possible? Or will i have to make 2 different functikns that will switch between them depending on the velocity?
 
Depends on how much accuracy you want. A star system isn't multiple two-body problems (especially when big planets are invovled), they are n-body problems. Let's say 3 for your case, Star, P1, P2. The main force of change will be the Star-P1 and Star-P2 reactions, but the P1-P2 forces will have an influence as well.

If you're just working in 2D it simplifies things, and there's a lot out there on simulating orbits.

Do you mean a ship that can change a planets orbit? You'll have to work in some nice programming if you want to incorporate that.
 
Fortunately, there's basically only one formula that you need to model the motion of the planets: Newton's second law, coupled with Newton's law of gravitation. This says (in Cartesian coordinates, or spherical coordinates if you want):

\frac{d^2 \vec{r}}{dt^2} = \frac{GM}{r^2} \hat{r}

where r is the distance from the planet to the star, M is the mass of the star, and G is the gravitational constant. This equation can be solved for an explicit formula if it's something simple like a planet orbiting a star, but that's not possible if you want something more complicated like a spaceship orbiting a planet. So my first recommendation is for you to solve this differential equation as a function of time for both planets independently. These are not incredibly difficult to solve in a code but if you've never done it before, it will require a little background reading. See Euler's method and then the Runge-Kutta method.
 
Thank you very much for the reply. My system is 2d system. there is a star, orbiting planets and small objects such as ships and sats that can manipulate their trajectory with some thrust. Their trajectory can be around a planet, aka orbiting, escaping the system with an escape velocity or just crushing down on a planet.
In my simulation, I plan to ignore other planet's gravity on each other to avoid using too much calculations, thus valueable processing power. Also, although my solar system is an imaginery one, I do not plan to change planet orbits. They will stay the same, at least in this version of the sim.

To the second reply. I first tried to implement the gravity law and all went well until i got to the part when i want to speed the time. The trick would work if every meter in game calculation is made and acceleration, velocity and position all updated. But if i want to jump, say 20 min later, it wouldn't work.
Thank you for the formula, I will try that.
 
If you want to make larger jumps without calculating the orbits in small time steps, things become a bit more complicated. While it is possible for the positions of the planets (the follow ellipses around the sun and you can calculate an expression which gives you the position for each planet for arbitrary times), it will not work with the small ships in the general case, as they might be influenced by the sun and a planet at the same time.

For ships in an orbit very close to a planet or with a position far away from the planets, you can use ellipses again.

However, this is all a bit more tricky then just 20 small steps of a minute each ;).
 
I understand. My idea was that I the ship will succumb to only one gravity at a time, depending on its strength.
For example, instead of calculating every gravity field that each and every planet generates on this ship, It will calculate only the significant one, the strongest one. I'll see how to fix that in later versions.
 
  • #11
avpx said:
For example, instead of calculating every gravity field that each and every planet generates on this ship, It will calculate only the significant one, the strongest one. I'll see how to fix that in later versions.
As mentioned before, this is a good approximation for orbits close to the planet (orbits around the planet) or orbits far away from planets (orbits around the sun).

However, in the former case, you should calculate the position relative to the planet. This is easier and will make errors small enough to calculate even large time steps (something comparable to a month on earth).
 
  • #12
mfb said:
As mentioned before, this is a good approximation for orbits close to the planet (orbits around the planet) or orbits far away from planets (orbits around the sun).

However, in the former case, you should calculate the position relative to the planet. This is easier and will make errors small enough to calculate even large time steps (something comparable to a month on earth).

Note taken.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
5K
Replies
18
Views
3K