Register to reply

Calculating planet trajectory

by avpx
Tags: planet, trajectory
Share this thread:
avpx
#1
Apr25-12, 01:53 PM
P: 9
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 thats it. How do i calculate their location in each point in time? Thanks.
Phys.Org News Partner Astronomy news on Phys.org
Young binary star system may form planets with weird and wild orbits
Evidence of a local hot bubble carved by a supernova
Astronomers measure weight of galaxies, expansion of universe
Steely Dan
#2
Apr25-12, 06:08 PM
P: 317
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.
avpx
#3
Apr26-12, 04:53 AM
P: 9
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?

Travis_King
#4
Apr26-12, 07:39 AM
P: 828
Calculating planet trajectory

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 theres 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.
Steely Dan
#5
Apr26-12, 07:48 AM
P: 317
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.
avpx
#6
Apr26-12, 11:43 AM
P: 9
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 wouldnt work.
Thank you for the formula, I will try that.
mfb
#7
Apr26-12, 05:07 PM
Mentor
P: 11,617
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 ;).
avpx
#8
Apr27-12, 05:31 AM
P: 9
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.
Travis_King
#9
Apr27-12, 07:11 AM
P: 828
There should be enough in here to get you going:

Wiki Page
Orbital Dynamics
OD Basics
Travis_King
#10
Apr27-12, 07:11 AM
P: 828
There should be enough in here to get you going:

Wiki Page
Orbital Dynamics
OD Basics
mfb
#11
Apr27-12, 08:27 AM
Mentor
P: 11,617
Quote Quote by avpx View Post
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).
avpx
#12
Apr28-12, 01:30 PM
P: 9
Quote Quote by mfb View Post
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.


Register to reply

Related Discussions
Calculating the Velocity at the bottom of a Pendulums Trajectory. Introductory Physics Homework 1
Calculating trajectory of spaceship-like object Classical Physics 2
Calculating the trajectory of a projectile Introductory Physics Homework 1
Calculating the highest point of a trajectory Introductory Physics Homework 1
Calculating trajectory by matrix methods Classical Physics 0