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

In summary, the conversation is about programming a 2D solar system simulation for a game. The main topic is how to calculate the location of planets in each point in time, taking into account their mass, initial velocity, and the location of a fixed star at the center of the solar system. The conversation also touches on the possibility of a ship that can manipulate its orbit and the use of Newton's laws of gravitation in the simulation. The participants also discuss the complexity of solving differential equations and the importance of calculating positions relative to planets for more accurate results.
  • #1
avpx
12
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
  • #2
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.
 
  • #3
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?
 
  • #4
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.
 
  • #5
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):

[tex]\frac{d^2 \vec{r}}{dt^2} = \frac{GM}{r^2} \hat{r}[/tex]

where [itex]r[/itex] is the distance from the planet to the star, [itex]M[/itex] is the mass of the star, and [itex]G[/itex] 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.
 
  • #6
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.
 
  • #7
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 ;).
 
  • #8
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.
 

What is planet trajectory?

Planet trajectory refers to the path or orbit that a planet takes around a star or other celestial body.

How is planet trajectory calculated?

Planet trajectory is calculated using mathematical equations and models based on the laws of gravity and motion. These calculations take into account factors such as the mass and velocity of the planet, as well as the gravitational pull of other objects in the solar system.

Why is calculating planet trajectory important?

Calculating planet trajectory allows us to predict the movement and positions of planets in our solar system, which is crucial for space exploration and the study of our universe. It also helps us understand the forces that govern the motion of celestial bodies.

Can planet trajectory change over time?

Yes, planet trajectory can change over time due to various factors such as the gravitational pull of other planets, asteroids, and comets, as well as the effects of solar wind and other space weather events. These changes can be predicted and accounted for in trajectory calculations.

Are there any limitations to calculating planet trajectory?

Calculating planet trajectory is based on mathematical models and assumptions, so there may be limitations or uncertainties in the predictions. Additionally, unexpected events or external forces may also affect the accuracy of trajectory calculations.

Similar threads

  • Astronomy and Astrophysics
Replies
15
Views
1K
  • Astronomy and Astrophysics
Replies
1
Views
2K
  • Astronomy and Astrophysics
Replies
1
Views
2K
  • Astronomy and Astrophysics
Replies
7
Views
4K
  • Introductory Physics Homework Help
Replies
18
Views
1K
  • Astronomy and Astrophysics
Replies
3
Views
2K
Replies
17
Views
2K
  • Astronomy and Astrophysics
Replies
12
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Classical Physics
Replies
7
Views
807
Back
Top