# Creating a celestial simulation

This topic is 4620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to create a simulation in 3d space. A number of "objects"(think planets or stars) which are all spheres are given a mass, radius, initial position and initial velocity. I want to let the simulation run for a period of time and see how the objects interact. The only forces involved will be the gravitational forces the objects exert on each other. Newtons equations will do fine, I'm not planning to use any relativistic physics. So given the equation for the gravitational force between 2 objects F = (G*m1*m2)/(r^2) where F = force in Newtons G = Gravitattional Constant(6.673 E -11) m1 = Mass of 1st object m2 = Mass of 2nd object r = distance between objects and F=MA How can I calculate the postition and velocity of an object after a given time. The formula above only gives the instanteanous force on an object which will be changing since the object is moving so r will not be constant. Any help would be much appreciated. Thanks.

##### Share on other sites
The key formula you're missing is Newton's Second Law:

Sum of forces = mass * acceleration.

So, your gravitational force equation will give you a force VECTOR. For each object, compute each force vector acting on that object, then sum them together to get the resultant vector. Now, you know that object's mass, and so you can now easily compute the acceleration vector. Now, we use the standard kinematic laws:

x = (1/2)*a*t^2 + v0*t + x0, where vf = vi + a * t, t is time, a is that acceleration vector, x is your current position, and v0 is the initial velocity.

Good luck! Sounds like an interesting project!

EDIT: Error in x equation, updated once ury discovered it

[Edited by - mnansgar on October 22, 2005 8:31:27 PM]

##### Share on other sites
I was going to say if you need to find "r", then just use the Pythagoreous therom and work from there.

##### Share on other sites
pbbm2000, there are really easier ways to simulate trajectories of the planets.

It can be proven that the trajectory of a body under the influence of an "inverse square" force, is a conic section. In the case of an orbiting planet, it's an ellipse.

http://en.wikipedia.org/wiki/Orbit
http://nssdc.gsfc.nasa.gov/planetary/planetfact.html

mnansgar, what you are saying only works when the force is constant, this is hardly the case with planets.

##### Share on other sites
Quote:
 Original post by urymnansgar, what you are saying only works when the force is constant, this is hardly the case with planets.

I guess I should also clarify that with the formulas I gave, you are basically approximating a differential equation using Euler's Law. Hence, you want to iterate through the position and velocity equations with very small time steps (eg make t as small as possible), and update your v0 with each "frame" of motion, recalculating the forces each frame as well. This will give you an approximation of the correct values, more accurate with the smaller your timestep.

##### Share on other sites
Even then it would look like:
x = 1/2*a*t2 + v0*t + x0

##### Share on other sites
Quote:
 Original post by uryEven then it would look like:x = 1/2*a*t2 + v0*t + x0

That's correct -- my mistake, I wrote it rather quickly. I've updated my original quote with credit to you for the find!

##### Share on other sites
Quote:
 Original post by urypbbm2000, there are really easier ways to simulate trajectories of the planets.It can be proven that the trajectory of a body under the influence of an "inverse square" force, is a conic section. In the case of an orbiting planet, it's an ellipse.Please read the following links for more information:http://en.wikipedia.org/wiki/Orbithttp://nssdc.gsfc.nasa.gov/planetary/planetfact.htmlmnansgar, what you are saying only works when the force is constant, this is hardly the case with planets.
And what you are proposing is only true with a single source of gravity. like the sun acting on planets individually. That fine if you want to ignore the erects of gravity between planets however. If there are other sources of gravity it gets much more complex. I'd imagine you need to get in to calculus and RK4 integrators to get the best results here.

##### Share on other sites
Grain, of course you are right. All sources of gravitational forces affect the trajectory of a planet. In fact, a reason why some scientists refused to accept Pluto as a planet was that it was affected too much by the gravitational force of Neptune.

Still, using the model that I proposed is very common. It's used for almost 400 hundred year now and still gives pretty much accurate results. Because this approach is only an approximation, the ellipse constants have to be updated every once in a while, to reflect the current state of the solar system.

Altough an approximation, the given error is very small and can't be possibly seen by a naked eye. IMHO, this approach is perfect for a game.

By the way, the NASA site contains pretty much everything you need to know to set up both of the experiments.

##### Share on other sites
Quote:
 Original post by uryAltough an approximation, the given error is very small and can't be possibly seen by a naked eye. IMHO, this approach is perfect for a game.
This is true of our solar system, because the majority of the mass is in one point at the center. But I think the OP wanted to do more than that. If for example he wants to model a galaxy or a twin star system or a star system with very massive gas giants, a conic approach will be insufficient.

• 38
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631362
• Total Posts
2999577
×