<p>The easiest approach is to do a numerical integration of the equation of motion of your system. For that you need to remember that the gravitational force of $a$ on $b$ is $$\vec{F}_{a\rightarrow b} = -G\frac{M_a M_b}{r_{a\rightarrow b}^{3}} \vec{{r_{a\rightarrow b}}}$$
where $\vec{{r_{a\rightarrow b}}} = \vec{x_b} - \vec{x_a}$ and that
$$ M\vec{a} = \sum \vec{F}$$
where $M$ is the mass of your object, $\sum\vec{F}$ is the sum of the forces applied to the object and $\vec{a}$ is the acceleration.</p>

<p>To do the simulation, you then have to follow this numerical scheme</p>

<ol>
<li>set some initial conditions to your problem: initial position $\vec{x_p}$ of the planet and $\vec{x_\star}$ of the star and initial velocities $\vec{v_p}$ and $\vec{v_\star}$.</li>
<li>compute the force $\vec{F}$ of the star on the planet and the accelerations of the planet and the star:
$$ -M_\star \vec{a_\star} = M_p \vec{a_p} = \vec{F_{\star\rightarrow p}}$$</li>
<li>update the speed of the planet and the star using the respective acceleration:
$$ \vec{v}(t+\Delta t) = \vec{v}(t) + \Delta t\times \vec{a} $$</li>
<li>update the positions of the planet and the star using their respective velocity:
$$ \vec{x}(t+\Delta t) = \vec{x}(t) + \Delta t\times \vec{v} $$</li>
<li>recompute the distance between the planet and the star $\vec{r_{{\star\rightarrow p}}} = \vec{x_p} - \vec{x_\star}$ and go back to 2.</li>
</ol>

CC BY-SA 3.0
2016-09-20T12:59:20.933Z
This is the way physics simulations work. Of course, you can always get more involved and use "smarter" math. What is presented here is a simple [Euler method](https://en.wikipedia.org/wiki/Euler_method) for approximating the future evolution of something. As you get more into this, you might look up more robust methods like [Runge-Kutta](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods). Depending on your language, there's likely an implementation of the math behind these methods already set up so you just plug and play.
zephyr
CC BY-SA 3.0
2016-09-20T21:52:27.380Z
Oh, but a simple method is exactly what I need.  Will take the time to fully understand this, as I should have been able to figure this out alone, but maybe next time.  Thanks for the help with this (site isn't letting me up vote anything).  Language is Java.
User
CC BY-SA 3.0
2016-09-23T16:28:31.170Z
There is no need to do this, as **planets move in circles**; and the above math would be beyond the requirement.  The OP is simply showing **a diagram representation** of a planet going around a star.  There is no "simulation" involved whatsoever.  (It's inconceivable the OP wants to start doing finite element analysis, or the like!)
Fattie
CC BY-SA 3.0
2016-09-23T16:34:22.133Z
Note that I have boldly removed the word "simulation" from the question, using an edit suggestion, since that is absolutely no what the OP wants.  Perhaps it will help clarify the situation.
Fattie
CC BY-SA 3.0
2016-09-20T09:41:26.417Z
2016-09-20T09:41:26.417Z
cphyc
<p>Addendum - be sure to click here: <a href="http://www.sankara.net/mom.html" rel="nofollow noreferrer">http://www.sankara.net/mom.html</a></p>

<p>(choose "Helios" button, top right)</p>

<p>As an "incredibly rhetorical" question, heh, can you see any ellipse-ness in the planets orbits?  Your ultimate game result would, I imagine, look something like that webapp.  The pink/orange lines showing the transfer of the two (real) spacecraft Earth to Mars would I guess be something like in your game. </p>

<p>I would just reiterate that literally for a game, or any conceivable "display of a planet system", all you have to do is "draw a circle" and "put a dot on it which moves around in a circle". Making game-like displays of planet system is <strong>remarkably easy</strong> - since the scale is so tremendously large, heh!</p>

<p>(Again you can simply get the year-length from the trivial formulas linked below, remembering you have to drastically alter timescale.)</p>

<p>Hope it helps!</p>

<hr>

<p>Just for the record:</p>

<p>To create a moving diagram showing planet(s) orbiting:</p>

<p>(1) as you say, place them at the desired <strong>distance</strong> and know the <strong>mass</strong>.  (2) calculate the "year" length of <strong>time</strong>.</p>

<p>(It is trivial to do that with, as you say, Kepler's equations. Easily found, example: <a href="http://www.ajdesigner.com/phpgravity/keplers_law_equation_mass.php" rel="nofollow noreferrer">plug-in equations</a>.)</p>

<p>Of course, you'll scale time. (What about 1 Earth-year is one minute?)  (Indeed, you will of course have to radically scale-up the body sizes, or you will simply see absolutely nothing.)</p>

<p>I had a window open so I just did this in a game engine; it takes 7 clicks and 3 lines of code!</p>

<p><a href="https://i.sstatic.net/KadDE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KadDE.png" alt="enter image description here"></a></p>

<p>Note: you mentioned "simulation" in your original question. That term has a specific technical meaning (especially to anyone on this site), and it is utterly unrelated to what you are asking.  Enjoy!</p>

<hr>

<p>FTR I gather from your other question you want to show extreme "video game like" ellipses.  Purely as a matter of interest, for your information the way you literally do that for literally a space-travel-like game (whether app or PC) is either</p>

<p>(a) trivially, just have the planet move in and out (whatever percentage you want) each half-year. (simply use a separate transform, so there's a transform for it going around, and a transform for it going in and out) or</p>

<p>(b) nudge it as outlined for example here, using <a href="https://stackoverflow.com/questions/30827958/unity-5-moving-planets-in-a-circular-or-elliptical-path-orbits">sin and cos</a> (Or, all game engines or graphics/animation apis have a "ping pong" and/or "smoothing-at-ends" call, just use that.)</p>

<p>A reminder that your display will be drastically altered from reality since you will be presenting 10 or 20 months in, say, 10 or 20 seconds.</p>

CC BY-SA 3.0
2016-09-26T20:46:12.000Z
Well hold on now, I agree I didn't phrase the question technically perfectly, but the overall goal is to do what I'd still call a basic simulation.  I didn't elaborate on this aspect, but I do want to "simulate" (in a more technical sense than a simple math plot) space vehicle travel within this system.  Also keep in mind the fantasy element - I might have very eccentric orbits (which might technically be unstable over a long period).  I do want technical terms like perihelion/aphelion to be meaningful too, so this goes a bit more towards "faking it" than I'd like (I do still want ellipses).
User
CC BY-SA 3.0
2016-09-27T03:15:37.173Z
You wouldn't have the computing resources, or the engineering department, to do finite element analysis. By all means use the word "simulation' as you wish but as I typed above: *"That term has a specific technical meaning (especially to anyone on this site), and it is utterly unrelated to what you are asking"*  Enjoy!
Fattie
CC BY-SA 3.0
2016-09-27T03:33:05.253Z
That's why I'm using terms like "crude" simulation (I still think it conveys my intent well enough taken in a casual context); obviously I'm not looking to put JPL out of business. I mean, thanks for the help and suggestions, but I think you're being a little too technically strict with the term to a point that it seems a little unfriendly towards amateurs.  I thought I made it pretty clear that I'm not doing something that requires a team of 20 people and a supercomputer.  I think your suggestion is probably a good solution, but I hoped to support elliptical orbits at least.
User
CC BY-SA 3.0
2016-09-28T09:16:13.177Z
The problem here is that orbits are ellipses, not circles. It takes more than 3 lines of code.
ProfRob
CC BY-SA 3.0
2016-09-28T10:30:24.650Z
For sure - like I mentioned in a comment, as far as you can represent on a monitor it's just a circle (I thought the OP was doing an our-solar-system-like diagram - I hadn't seen the OP's other question showing extreme "arcade game" ellipses.)
Fattie
CC BY-SA 3.0
2016-09-30T13:43:17.927Z
hi @Manius just FWIW try the link (sankara) I added, it's a good one. (It's entirely possible the code there is available, FWIW.)
Fattie
CC BY-SA 3.0
2016-09-30T17:04:38.957Z
Getting off topic here but aren't more extreme orbits quite realistic (in other solar systems in particular, or with planetoids/comets/asteroids)?  That is a pretty cool link.
User
CC BY-SA 3.0
2016-09-30T18:46:10.367Z
hi @Manius regarding adding "extreme ellipse look" in a game context.  I gave the full, total solution in the points labelled (a) and (b).  Note that point (b) literally includes the full mathematical concept, and specifically all code, to do so.  Regarding point (a) I get the impression you have not particularly had a go with a game engine yet (click to download one and try), it's a little hard to explain but what you are asking is utterly built-in to the fundamental concepts ("GameObjects", "Transform") of any game engine; you can just instantly rotate and move-in-and-out stuff.
Fattie
CC BY-SA 3.0
2016-10-01T00:33:07.353Z
lol.. Well, if I didn't have experience with a gaming engine I'd be waaay ahead of myself right now.  Not sure where you're getting that impression, other than the fact that my math knowledge has decayed pretty bad.  It has been 10-15+ years since I've done what I'd consider "real" math.  I already have some 3D development experience (quite a bit more non-3D), but of course some engines "help" you out with common problems, which doesn't help you learn what's going on under the hood.  I think you mean gamedev.net - I've been a member there for years actually, great site.
User
CC BY-SA 3.0
2016-09-23T16:45:26.110Z
2016-09-30T13:42:43.570Z
2017-05-23T12:37:21.700Z
Fattie
<p>You don't <em>need</em> to do a physics simulation to do what you want. Kepler's laws of planetary motion will do just fine and they account for elliptical orbits of course.</p>

<p>You will have to do a bit more Maths if you want your orbits to be elliptical. The Maths you need is summarised <a href="https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion#Position_as_a_function_of_time" rel="nofollow">here</a>. This is a recipe for calculating $r$ and $\theta$ as a function of time, where $r$ is the helio(astro)centric distance and $\theta$ is the true anomaly, which is the agular coordinate at that point of time. In turn you would have to specify the mass of the star (and planet if it was significant), the orbital period (or semi-major axis), the perihelion(astron) position and the position at $t=0$.</p>

<p>The orbital inclination is independent of these calculations, since in this basic scheme there is nothing to alter the angular momentum of the orbit and so there is a fifth parameter defining that.</p>

<p>The calculations are reasonably simple though you will have to do something numerical (like the <a href="http://www.sosmath.com/calculus/diff/der07/der07.html" rel="nofollow">Newton-Raphson method</a>) to get the eccentric anomaly in step 2.</p>

<p>If you wish to start taking 3-body (or more) interactions into account then you <em>will</em> have to think about physics simulations. I think the scheme given by cphyc will work ok so long as you make the time step very small and don't integrate over many orbits. If you are interested in the stability or long term evolution of planetary systems that you setup then you <em>will</em> have to get into <em>much</em> more complex schemes, since the one suggested by cphyc is numerically unstable.</p>

CC BY-SA 3.0
2016-09-29T20:36:07.860Z
Ooo that might be exactly the math I need - "as a function of time" - didn't notice it before!
User
CC BY-SA 3.0
2016-09-28T09:14:06.620Z
2016-09-28T09:14:06.620Z
ProfRob
<p>I'm trying to simulate a virtual/imaginary "solar system" in software--just a hobby project for now. Unfortunately this has made me realize exactly how much math I've forgotten since college.  </p>

<p>Complete accuracy isn't important, and I'm not looking to do anything sophisticated... no need for multi-body calculations, just a star and a planet will do. I just want something that a lightweight simulation or a game might do. </p>

<p>I'll have a configuration file with some basic starting parameters for each planet. At the start of the simulation, time=0 seconds, all planets would be lined up in a row (planning on just placing them on the same axis at their perihelion distance from the star). I'd like the planets to move around their orbits at the correct speed given the parameters supplied. So if I decide to set time = 1e10, I need to be able to calculate the x and y positions of each planet in their orbit at that precise time.</p>

<p>I'm flexible on WHICH parameters need to be provided. So if this becomes easier using some other method of defining the orbit, I'm open to it. Right now I'm thinking perihelion, mass, and time elapsed.  </p>

<p>(Since this is a 3D simulation, eventually I'd also like to work inclination in, but I'm trying to start off simple for now, so inclinations will all be zero.)</p>

<p>Here's some sample parameter data below in case it helps provide a better example.  </p>

<p>Star mass = 2.00e30</p>

<p>Planet mass = 3.30e23</p>

<p>Planet perihelion = 5800000</p>

<p>(Ex. Where would this planet be, in X/Y coordinates, at time=x?)</p>

<p>If someone posts a formula I can just plug in I won't complain. But if I could just be pointed in the right direction for what to learn or refresh my memory on, I'd like to try and figure this out myself. So far I've been looking at Kepler's 3rd Law equations but I'm not sure if that's a good place to start. Feeling a little guilty that I seem to have forgotten virtually <em>all</em> math I learned in college just over a decade ago, and I kind of want to reverse some of that decay.  Hopefully this makes sense!</p>

CC BY-SA 3.0
2016-09-20T06:16:18.243Z
How about [this answer on stack overflow](http://stackoverflow.com/questions/22068178/implementing-newtons-law-of-universal-gravity-in-c-sharp)? The code in there might give you an idea to get started. (Basically a first loop to calculate the total gravitational forces on each object, and a second loop to calculate the change in their positions over the next time slice.)
Andy
CC BY-SA 3.0
2016-09-20T08:26:36.880Z
This article on [wikipedia](https://en.wikipedia.org/wiki/Numerical_model_of_the_Solar_System) gives a few hints on where to start. If you want to add in some complexity, this [course page from Princeton](http://www.cs.princeton.edu/courses/archive/spring11/cos126/assignments/nbody.html) is useful.
Reuben Mallaby
CC BY-SA 3.0
2016-09-20T11:44:10.033Z
Those resources are useful, but in essence, your answer is just links. Consider to flesh it out a little, or make it a comment instead. Oh, and by the way, welcome to this part of the SE network.
SE - stop firing the good guys
CC BY-SA 3.0
2016-09-20T13:02:27.960Z
Not worth a full answer, but just for reference, an orbit requires [6 parameters to uniquely define it](https://en.wikipedia.org/wiki/Orbital_elements). You might want to set up your input file to use all 6 to begin with, but zero out anything you don't need or understand initially. You'll definitely need to start by defining the semi-major axis (in place of perihelion, although perihelion could technically work as well) and the eccentricity (equivalent to defining the energy of your orbit).
zephyr
CC BY-SA 3.0
2016-09-20T17:11:15.013Z
@barrycarter Well, the initial position (akin to defining the semi-major axis) would have to be defined as well as the velocity (akin to defining the ellipticity). Adding a third body shouldn't be a problem for him either since he's not trying to represent a solution in closed from but rather do an explicit numerical simulation.
zephyr
CC BY-SA 3.0
2016-09-20T21:46:52.493Z
Wow, way more helpful suggestions than I expected.  :)  I had noticed the Orbital Elements page on Wiki, and that's an option, but I'm hoping I can simplify a bit by making some assumptions.  And yes the initial position assumption (5800000, 0, 0) is correct.  Got a lot of reading to do now!
User
CC BY-SA 3.0
2016-09-21T09:54:31.190Z
While numerically integrating is very interesting, @Manius explicitly stated he doesn't need n-body interactions, and wants to be able to set the time after epoch explicitly. I'm thinking he'd be better off with a "planets-on-rails" solution, but I don't have the time/knowledge to explain properly...
yatima2975
CC BY-SA 3.0
2016-09-22T02:03:58.010Z
Yeah.  I'm not looking to do a "Universe Sandbox" type simulation where you're messing with large celestials themselves, and I'm not simulating time frames longer than a few hundred/thousand years, so they'll be effectively static orbits.  Goal is to have more of a (still basic) exploration vehicle simulation where I'm basically going to just decide which celestial object is primary and have the "craft" orbit around that. Each object will have a "sphere of gravitational influence" which becomes active as a craft gets close enough.  So I just need a procedural method to move big things around.
User
CC BY-SA 3.0
2016-09-22T02:09:37.417Z
I guess another method (even simpler, although it wouldn't encourage realism) would be to just determine how to plot an arbitrary ellipse in 3D space and use a time variable to determine a location on the ellipse.  Actually, I want to be able to draw lines to outline each object's orbit, so that would probably come in useful anyway.
User
CC BY-SA 3.0
2016-09-23T16:20:46.503Z
**The answer is astoundingly easy.**  Planets travel around a star in a circle.  (You may have heard it's an "ellipse" but you would need a monitor with a resolution of trillions of pixels an inch to represent this: and you couldn't see it anyway.)  You say you're not interested in further effects (such as Mars very slightly pushing around Earth) - and that's sensible as, again, it is totally impossible you could see it.  So, it just could not be simpler.  The planets orbit the star in circles.  Have two parameters for distance and year-length.
Fattie
CC BY-SA 3.0
2016-09-23T16:20:57.470Z
...just type in the known distances and year-lengths.  Easy.
Fattie
CC BY-SA 3.0
2016-09-23T16:25:43.410Z
Yes, you use "Kepler's law" to get from "mass"  / "radius" to "length of year".  Explained everywhere online, http://www.1728.org/kepler3a.htm http://www.astronomynotes.com/gravappl/s8.htm etc.  in your computer "simulation" (it's a "diagram" really), all you need is the radius and time.  Enjoy!
Fattie
CC BY-SA 3.0
2016-09-23T16:26:52.837Z
this gives you every single formula you need (it is trivial), to "plug in" the two values and get the other one.  http://www.ajdesigner.com/phpgravity/keplers_law_equation_mass.php  Hope it helps!
Fattie
CC BY-SA 3.0
2016-09-23T16:33:29.073Z
**Attention** !  I have boldly edited this question.  Manius, you use the term "simulation".  This is a **specific technical term** which has absolutely no connection - in any way, at all - to what you are trying to achieve.  Feel free to use my edit in some way if it helps.  But note that you absolutely do not want to mention "simulation" - unless you specifically want that (it is incredibly unlikely that you want that).
Fattie
CC BY-SA 3.0
2016-09-26T05:50:37.230Z
You might take a look at VSOP87 which compute all planets position at any give time. https://en.wikipedia.org/wiki/VSOP_(planets) and there's a link to generate code: http://neoprogrammics.com/vsop87/
Huy Pham
CC BY-SA 3.0
2016-09-26T20:52:57.043Z
See my other comment, I do want a (probably crude) "simulation" inside this "diagram representation" environment, as you called it.  Updated title to reflect that better.
User
<orbit><celestial-mechanics>
Creating a basic "fixed" solar system to host a 3D space travel simulation
User
# Creating a basic "fixed" solar system to host a 3D space travel simulation

(Asked by: username_0 on 2016-09-20)

I'm trying to simulate a virtual/imaginary "solar system" in software--just a hobby project for now. Unfortunately this has made me realize exactly how much math I've forgotten since college.

Complete accuracy isn't important, and I'm not looking to do anything sophisticated... no need for multi-body calculations, just a star and a planet will do. I just want something that a lightweight simulation or a game might do.

I'll have a configuration file with some basic starting parameters for each planet. At the start of the simulation, time=0 seconds, all planets would be lined up in a row (planning on just placing them on the same axis at their perihelion distance from the star). I'd like the planets to move around their orbits at the correct speed given the parameters supplied. So if I decide to set time = 1e10, I need to be able to calculate the x and y positions of each planet in their orbit at that precise time.

I'm flexible on WHICH parameters need to be provided. So if this becomes easier using some other method of defining the orbit, I'm open to it. Right now I'm thinking perihelion, mass, and time elapsed.

(Since this is a 3D simulation, eventually I'd also like to work inclination in, but I'm trying to start off simple for now, so inclinations will all be zero.)

Here's some sample parameter data below in case it helps provide a better example.

Star mass = 2.00e30

Planet mass = 3.30e23

Planet perihelion = 5800000

(Ex. Where would this planet be, in X/Y coordinates, at time=x?)

If someone posts a formula I can just plug in I won't complain. But if I could just be pointed in the right direction for what to learn or refresh my memory on, I'd like to try and figure this out myself. So far I've been looking at Kepler's 3rd Law equations but I'm not sure if that's a good place to start. Feeling a little guilty that I seem to have forgotten virtually *all* math I learned in college just over a decade ago, and I kind of want to reverse some of that decay. Hopefully this makes sense!

**Tags:** orbit, celestial-mechanics
> **Comments:**
> **username_1**: How about [this answer on stack overflow](http://stackoverflow.com/questions/22068178/implementing-newtons-law-of-universal-gravity-in-c-sharp)? The code in there might give you an idea to get started. (Basically a first loop to calculate the total gravitational forces on each object, and a second loop to calculate the change in their positions over the next time slice.)  
> **username_2**: This article on [wikipedia](https://en.wikipedia.org/wiki/Numerical_model_of_the_Solar_System) gives a few hints on where to start. If you want to add in some complexity, this [course page from Princeton](http://www.cs.princeton.edu/courses/archive/spring11/cos126/assignments/nbody.html) is useful.  
> **username_3**: Those resources are useful, but in essence, your answer is just links. Consider to flesh it out a little, or make it a comment instead. Oh, and by the way, welcome to this part of the SE network.  
> **username_4**: Not worth a full answer, but just for reference, an orbit requires [6 parameters to uniquely define it](https://en.wikipedia.org/wiki/Orbital_elements). You might want to set up your input file to use all 6 to begin with, but zero out anything you don't need or understand initially. You'll definitely need to start by defining the semi-major axis (in place of perihelion, although perihelion could technically work as well) and the eccentricity (equivalent to defining the energy of your orbit).  
> **username_4**: @barrycarter Well, the initial position (akin to defining the semi-major axis) would have to be defined as well as the velocity (akin to defining the ellipticity). Adding a third body shouldn't be a problem for him either since he's not trying to represent a solution in closed from but rather do an explicit numerical simulation.  
> **username_0**: Wow, way more helpful suggestions than I expected.  :)  I had noticed the Orbital Elements page on Wiki, and that's an option, but I'm hoping I can simplify a bit by making some assumptions.  And yes the initial position assumption (5800000, 0, 0) is correct.  Got a lot of reading to do now!  
> **username_5**: While numerically integrating is very interesting, @Manius explicitly stated he doesn't need n-body interactions, and wants to be able to set the time after epoch explicitly. I'm thinking he'd be better off with a "planets-on-rails" solution, but I don't have the time/knowledge to explain properly...  
> **username_0**: Yeah.  I'm not looking to do a "Universe Sandbox" type simulation where you're messing with large celestials themselves, and I'm not simulating time frames longer than a few hundred/thousand years, so they'll be effectively static orbits.  Goal is to have more of a (still basic) exploration vehicle simulation where I'm basically going to just decide which celestial object is primary and have the "craft" orbit around that. Each object will have a "sphere of gravitational influence" which becomes active as a craft gets close enough.  So I just need a procedural method to move big things around.  
> **username_0**: I guess another method (even simpler, although it wouldn't encourage realism) would be to just determine how to plot an arbitrary ellipse in 3D space and use a time variable to determine a location on the ellipse.  Actually, I want to be able to draw lines to outline each object's orbit, so that would probably come in useful anyway.  
> **username_6**: **The answer is astoundingly easy.**  Planets travel around a star in a circle.  (You may have heard it's an "ellipse" but you would need a monitor with a resolution of trillions of pixels an inch to represent this: and you couldn't see it anyway.)  You say you're not interested in further effects (such as Mars very slightly pushing around Earth) - and that's sensible as, again, it is totally impossible you could see it.  So, it just could not be simpler.  The planets orbit the star in circles.  Have two parameters for distance and year-length.  
> **username_6**: ...just type in the known distances and year-lengths.  Easy.  
> **username_6**: Yes, you use "Kepler's law" to get from "mass"  / "radius" to "length of year".  Explained everywhere online, http://www.1728.org/kepler3a.htm http://www.astronomynotes.com/gravappl/s8.htm etc.  in your computer "simulation" (it's a "diagram" really), all you need is the radius and time.  Enjoy!  
> **username_6**: this gives you every single formula you need (it is trivial), to "plug in" the two values and get the other one.  http://www.ajdesigner.com/phpgravity/keplers_law_equation_mass.php  Hope it helps!  
> **username_6**: **Attention** !  I have boldly edited this question.  Manius, you use the term "simulation".  This is a **specific technical term** which has absolutely no connection - in any way, at all - to what you are trying to achieve.  Feel free to use my edit in some way if it helps.  But note that you absolutely do not want to mention "simulation" - unless you specifically want that (it is incredibly unlikely that you want that).  
> **username_7**: You might take a look at VSOP87 which compute all planets position at any give time. https://en.wikipedia.org/wiki/VSOP_(planets) and there's a link to generate code: http://neoprogrammics.com/vsop87/  
> **username_0**: See my other comment, I do want a (probably crude) "simulation" inside this "diagram representation" environment, as you called it.  Updated title to reflect that better.  

---

## 3 answers

### Answer by username_8 on 2016-09-20. Score: 3

The easiest approach is to do a numerical integration of the equation of motion of your system. For that you need to remember that the gravitational force of $a$ on $b$ is $$\vec{F}\_{a\rightarrow b} = -G\frac{M\_a M\_b}{r\_{a\rightarrow b}^{3}} \vec{{r\_{a\rightarrow b}}}$$
where $\vec{{r\_{a\rightarrow b}}} = \vec{x\_b} - \vec{x\_a}$ and that
$$ M\vec{a} = \sum \vec{F}$$
where $M$ is the mass of your object, $\sum\vec{F}$ is the sum of the forces applied to the object and $\vec{a}$ is the acceleration.

To do the simulation, you then have to follow this numerical scheme

1. set some initial conditions to your problem: initial position $\vec{x\_p}$ of the planet and $\vec{x\_\star}$ of the star and initial velocities $\vec{v\_p}$ and $\vec{v\_\star}$.
2. compute the force $\vec{F}$ of the star on the planet and the accelerations of the planet and the star:
   $$ -M\_\star \vec{a\_\star} = M\_p \vec{a\_p} = \vec{F\_{\star\rightarrow p}}$$
3. update the speed of the planet and the star using the respective acceleration:
   $$ \vec{v}(t+\Delta t) = \vec{v}(t) + \Delta t\times \vec{a} $$
4. update the positions of the planet and the star using their respective velocity:
   $$ \vec{x}(t+\Delta t) = \vec{x}(t) + \Delta t\times \vec{v} $$
5. recompute the distance between the planet and the star $\vec{r\_{{\star\rightarrow p}}} = \vec{x\_p} - \vec{x\_\star}$ and go back to 2.

> **Comments:**
> **username_4**: This is the way physics simulations work. Of course, you can always get more involved and use "smarter" math. What is presented here is a simple [Euler method](https://en.wikipedia.org/wiki/Euler_method) for approximating the future evolution of something. As you get more into this, you might look up more robust methods like [Runge-Kutta](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods). Depending on your language, there's likely an implementation of the math behind these methods already set up so you just plug and play.  
> **username_0**: Oh, but a simple method is exactly what I need.  Will take the time to fully understand this, as I should have been able to figure this out alone, but maybe next time.  Thanks for the help with this (site isn't letting me up vote anything).  Language is Java.  
> **username_6**: There is no need to do this, as **planets move in circles**; and the above math would be beyond the requirement.  The OP is simply showing **a diagram representation** of a planet going around a star.  There is no "simulation" involved whatsoever.  (It's inconceivable the OP wants to start doing finite element analysis, or the like!)  
> **username_6**: Note that I have boldly removed the word "simulation" from the question, using an edit suggestion, since that is absolutely no what the OP wants.  Perhaps it will help clarify the situation.  

---

### Answer by username_6 on 2016-09-23. Score: 2

Addendum - be sure to click here: <http://www.sankara.net/mom.html>

(choose "Helios" button, top right)

As an "incredibly rhetorical" question, heh, can you see any ellipse-ness in the planets orbits? Your ultimate game result would, I imagine, look something like that webapp. The pink/orange lines showing the transfer of the two (real) spacecraft Earth to Mars would I guess be something like in your game.

I would just reiterate that literally for a game, or any conceivable "display of a planet system", all you have to do is "draw a circle" and "put a dot on it which moves around in a circle". Making game-like displays of planet system is **remarkably easy** - since the scale is so tremendously large, heh!

(Again you can simply get the year-length from the trivial formulas linked below, remembering you have to drastically alter timescale.)

Hope it helps!

---

Just for the record:

To create a moving diagram showing planet(s) orbiting:

(1) as you say, place them at the desired **distance** and know the **mass**. (2) calculate the "year" length of **time**.

(It is trivial to do that with, as you say, Kepler's equations. Easily found, example: [plug-in equations](http://www.ajdesigner.com/phpgravity/keplers_law_equation_mass.php).)

Of course, you'll scale time. (What about 1 Earth-year is one minute?) (Indeed, you will of course have to radically scale-up the body sizes, or you will simply see absolutely nothing.)

I had a window open so I just did this in a game engine; it takes 7 clicks and 3 lines of code!

[![enter image description here](https://i.sstatic.net/KadDE.png)](https://i.sstatic.net/KadDE.png)

Note: you mentioned "simulation" in your original question. That term has a specific technical meaning (especially to anyone on this site), and it is utterly unrelated to what you are asking. Enjoy!

---

FTR I gather from your other question you want to show extreme "video game like" ellipses. Purely as a matter of interest, for your information the way you literally do that for literally a space-travel-like game (whether app or PC) is either

(a) trivially, just have the planet move in and out (whatever percentage you want) each half-year. (simply use a separate transform, so there's a transform for it going around, and a transform for it going in and out) or

(b) nudge it as outlined for example here, using [sin and cos](https://stackoverflow.com/questions/30827958/unity-5-moving-planets-in-a-circular-or-elliptical-path-orbits) (Or, all game engines or graphics/animation apis have a "ping pong" and/or "smoothing-at-ends" call, just use that.)

A reminder that your display will be drastically altered from reality since you will be presenting 10 or 20 months in, say, 10 or 20 seconds.

> **Comments:**
> **username_0**: Well hold on now, I agree I didn't phrase the question technically perfectly, but the overall goal is to do what I'd still call a basic simulation.  I didn't elaborate on this aspect, but I do want to "simulate" (in a more technical sense than a simple math plot) space vehicle travel within this system.  Also keep in mind the fantasy element - I might have very eccentric orbits (which might technically be unstable over a long period).  I do want technical terms like perihelion/aphelion to be meaningful too, so this goes a bit more towards "faking it" than I'd like (I do still want ellipses).  
> **username_6**: You wouldn't have the computing resources, or the engineering department, to do finite element analysis. By all means use the word "simulation' as you wish but as I typed above: *"That term has a specific technical meaning (especially to anyone on this site), and it is utterly unrelated to what you are asking"*  Enjoy!  
> **username_0**: That's why I'm using terms like "crude" simulation (I still think it conveys my intent well enough taken in a casual context); obviously I'm not looking to put JPL out of business. I mean, thanks for the help and suggestions, but I think you're being a little too technically strict with the term to a point that it seems a little unfriendly towards amateurs.  I thought I made it pretty clear that I'm not doing something that requires a team of 20 people and a supercomputer.  I think your suggestion is probably a good solution, but I hoped to support elliptical orbits at least.  
> **username_9**: The problem here is that orbits are ellipses, not circles. It takes more than 3 lines of code.  
> **username_6**: For sure - like I mentioned in a comment, as far as you can represent on a monitor it's just a circle (I thought the OP was doing an our-solar-system-like diagram - I hadn't seen the OP's other question showing extreme "arcade game" ellipses.)  
> **username_6**: hi @Manius just FWIW try the link (sankara) I added, it's a good one. (It's entirely possible the code there is available, FWIW.)  
> **username_0**: Getting off topic here but aren't more extreme orbits quite realistic (in other solar systems in particular, or with planetoids/comets/asteroids)?  That is a pretty cool link.  
> **username_6**: hi @Manius regarding adding "extreme ellipse look" in a game context.  I gave the full, total solution in the points labelled (a) and (b).  Note that point (b) literally includes the full mathematical concept, and specifically all code, to do so.  Regarding point (a) I get the impression you have not particularly had a go with a game engine yet (click to download one and try), it's a little hard to explain but what you are asking is utterly built-in to the fundamental concepts ("GameObjects", "Transform") of any game engine; you can just instantly rotate and move-in-and-out stuff.  
> **username_0**: lol.. Well, if I didn't have experience with a gaming engine I'd be waaay ahead of myself right now.  Not sure where you're getting that impression, other than the fact that my math knowledge has decayed pretty bad.  It has been 10-15+ years since I've done what I'd consider "real" math.  I already have some 3D development experience (quite a bit more non-3D), but of course some engines "help" you out with common problems, which doesn't help you learn what's going on under the hood.  I think you mean gamedev.net - I've been a member there for years actually, great site.  

---

### Answer by username_9 on 2016-09-28. Score: 1

You don't *need* to do a physics simulation to do what you want. Kepler's laws of planetary motion will do just fine and they account for elliptical orbits of course.

You will have to do a bit more Maths if you want your orbits to be elliptical. The Maths you need is summarised [here](https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion#Position_as_a_function_of_time). This is a recipe for calculating $r$ and $\theta$ as a function of time, where $r$ is the helio(astro)centric distance and $\theta$ is the true anomaly, which is the agular coordinate at that point of time. In turn you would have to specify the mass of the star (and planet if it was significant), the orbital period (or semi-major axis), the perihelion(astron) position and the position at $t=0$.

The orbital inclination is independent of these calculations, since in this basic scheme there is nothing to alter the angular momentum of the orbit and so there is a fifth parameter defining that.

The calculations are reasonably simple though you will have to do something numerical (like the [Newton-Raphson method](http://www.sosmath.com/calculus/diff/der07/der07.html)) to get the eccentric anomaly in step 2.

If you wish to start taking 3-body (or more) interactions into account then you *will* have to think about physics simulations. I think the scheme given by cphyc will work ok so long as you make the time step very small and don't integrate over many orbits. If you are interested in the stability or long term evolution of planetary systems that you setup then you *will* have to get into *much* more complex schemes, since the one suggested by cphyc is numerically unstable.

> **Comments:**
> **username_0**: Ooo that might be exactly the math I need - "as a function of time" - didn't notice it before!  

---

