Register to reply 
Calculating planet trajectory 
Share this thread: 
#1
Apr2512, 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. 


#2
Apr2512, 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.



#3
Apr2612, 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? 


#4
Apr2612, 07:39 AM

P: 839

Calculating planet trajectory
Depends on how much accuracy you want. A star system isn't multiple twobody problems (especially when big planets are invovled), they are nbody problems. Let's say 3 for your case, Star, P1, P2. The main force of change will be the StarP1 and StarP2 reactions, but the P1P2 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. 


#5
Apr2612, 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 RungeKutta method. 


#6
Apr2612, 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. 


#7
Apr2612, 05:07 PM

Mentor
P: 11,819

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
Apr2712, 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. 


#9
Apr2712, 07:11 AM

P: 839



#10
Apr2712, 07:11 AM

P: 839



#11
Apr2712, 08:27 AM

Mentor
P: 11,819

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
Apr2812, 01:30 PM

P: 9




Register to reply 
Related Discussions  
Calculating the Velocity at the bottom of a Pendulums Trajectory.  Introductory Physics Homework  1  
Calculating trajectory of spaceshiplike 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 