I seem to be missing something basic.

I've been trying to get a simple orbital simulation working, and my two objects are Earth around the Sun.

My problem is this. I placed the Earth at 93M miles away from the Sun, or 155M km.

As I understand it, the orbital velocity of something at 155M km from the Sun is:

$$v = \sqrt{\frac{GM}{r}}$$

Plugging in the numbers for the Sun, I get a velocity of:

$$29261 \frac{\mathrm{m}}{\mathrm{s}}$$

However, if I want to get the acceleration that the Sun has upon the earth, I use:

$$g = \frac{GM}{r^2}$$

For the Sun, and 155M km, I get an acceleration of:


Now, I start with a simple body at the proper radius out along the X axis and give it a simply vector of 29261 m/s along the Y axis, then I start applying the 0.0055 m/s^2 acceleration to it. And the acceleration of the Sun is simply not enough to hold the Earth.

If the Earth starts with a vector of (0, 29261 m/s), and after and I add the acceleration vector of (-0.0055 m/s, 0) to it, you can see that after a single second, it doesn't move a whole lot. If I chunk things to days, 86400 seconds, then the acceleration vector is only, roughly, -477 m/day, but the velocity vector is:

$$2,325,974,400 \frac{\mathrm{m}}{\mathrm{day}} = 29,261 \frac{\mathrm{m}}{\mathrm{s}} \times 86,400 \frac{\mathrm{s}}{\mathrm{day}}$$

As you can imagine, the -477 isn't going to move that much towards the Sun.

I understand that better simulations use better techniques than simply adding basic vectors together, but that's not what this is. I seem to be missing something fundamental. I had assumed that given the correct velocity, that the pull of the Sun should keep the Earth in orbit, but the "pull" that I'm using doesn't seem to be having the desired effect.

So, I'm curious what basic "D'oh" thing I'm missing here.

Edit for Luboš Motl answer.

Perhaps there's something more fundamental I'm missing here. I understand you point, but .0055 m/s * 86,400 is -477. I was doing that math fine.

Simply, I have an object with a velocity vector. Then I apply an acceleration at a right angle. I do that for N seconds to come up with a new, right angle velocity vector. I then add that to the original vector to come up with the objects new vector. I then take that vector, apply to the current position of the object, and arrive at a new position.

Clearly there is a granularity issue which makes some amount of seconds a better choice for a model than others, but this is high school level simple mechanics, so there's going to be some stepping. I chose one day so that my little dot of a planet on my screen would move. If I update every 1/10th of a second "real time", and each update is a day, then I should get a rough orbit that's really a 365ish polygon in a little over 30s real time.

If I choose a step size of 1 second, then my acceleration (0.0055 m/s^2) * 1 s = a right angle velocity vector that's -0.0055 in magnitude. That vector is added to the original vector of 29261 (at right angles), giving me a new vector of (-0.0055, 29261). That's after one second. That's not much of a bump. It's barely a blip. If I apply one days full of acceleration, "all at once", I am obligated to not only multiply the acceleration by 86,400, but also the original vector (since it's 29261 m/s, and we have 86,400 s), thus giving me, proportionally, the same vector, just longer. And it's still just a bump.

So, I'm mis-applying something somewhere here, as I think the numbers are fine. I'm simply "doing it wrong". Trying to figure out what that wrong part is.

Edit 2, responding to Platypus Lover

Thank you very much for the simple code you posted. It showed me my error.

My confusion was conflating updating of the vector with the calculation of the velocity vector. I felt that I had to multiply both the original vector AND the acceleration amount by the time step, which would give me the silly results.

It was just confused in my head.

  • $\begingroup$ You wrote "acceleration vector of (-0.0055 m/s, 0)" but that's actually a velocity vector, judging by the units. Was that a typo? $\endgroup$ – David Z Feb 27 '11 at 6:44
  • $\begingroup$ 1) Unfortunately, you can't just "chunk things to days". 2) The acceleration vector changes as to always be at right angles to the velocity vector. $g_x v_x + g_y v_y = 0$ $\endgroup$ – Eelvex Feb 27 '11 at 6:49
  • $\begingroup$ @David: actually he treats this as "velocity vector per second" so it should be ok. $\endgroup$ – Eelvex Feb 27 '11 at 6:50
  • $\begingroup$ @Will: I don't understand why you think something is wrong in your calculation. $\endgroup$ – timur Feb 27 '11 at 17:36
  • $\begingroup$ @timur I thought something was wrong with my calculation when my simple animation showed "the Earth" flying off and away instead of in a circle like it should have. $\endgroup$ – Will Hartung Feb 27 '11 at 21:30

I suspect there is something wrong in the way you are adding the acceleration vector to the velocity vector after the first timestep. The simplest way to check you are doing things correctly is to write down your scheme in cartesian coordinates.

To point you in the right direction, I wrote a sample orbit integrator for you here: Simplest orbit integrator, which should be at a level appropriate for a high school student. This is probably simplest integrator you can possibly write. With your code, you should get a nice circle for an x-y plot, and a nice sinusoid for the position and velocity components:

x-y plot t-x plot

Notice that it uses Euler's method:

$\vec{v}(t+\Delta t) = \vec{v}(t) + \Delta t \ \vec{a}(t)$

$\vec{x}(t+\Delta t) = \vec{x}(t) + \Delta t \ \vec{v}(t)$

which is probably what you have been doing so far without realizing. This is the most inaccurate method to use when integrating, and once you introduce elliptical orbits, this method will give you wrong results after a few orbits. There are many simple recommendations I can give you on how to further improve your code once it is fixed (normalizing units, a better integration scheme, etc.).

  • $\begingroup$ I added to the original post what my issue was, thank you. I'd be very interested in your recommendations. I know that this technique is fraught with problems, but the basic premise was to test that my simple gravity model and animation was being applied properly, which would demonstrate itself if the Earth ran in a circle. $\endgroup$ – Will Hartung Feb 27 '11 at 21:34
  • $\begingroup$ Two big improvements are very easy to implement: (1) move to a symplectic integrator. The leapfrog method (en.wikipedia.org/wiki/Leapfrog_integration) is a simple extension to what you already have, and it improves accuracy by leaps and bounds (slight pun!). It will also perform miles better for longer integration and with eccentric orbits. (2) Rescale your equations to the most natural units: in your case, for instance, AUs, years and solar masses. $\endgroup$ – Platypus Lover Feb 27 '11 at 22:26
  • 1
    $\begingroup$ Oh, and this is a cute online book about the two-body problem for high schoolers: artcompsci.org/kali/pub/msa/title.html, written by Piet Hut and Jun Makino, two giants in the field of stellar dynamics. $\endgroup$ – Platypus Lover Feb 27 '11 at 22:34

Dear Will, your error is that you think that the acceleration $a$ adds distances $s$ linearly in time $t$. In reality, it adds them quadratically via the formula $$ s = \frac{1}{2} at^2 $$ Many kids know this formula: it's the time $t$ multiplied by the average speed during the interval which is $(v_{initial}+v_{final})/2=at/2$. The graph of the motion is a parabola, a good approximation whenever the acceleration is approximately constant during the short enough time interval. In other words, you have increased the velocity during the first second, but you forgot to increase the velocity by the same amount during the remaining $86,399$ seconds of the first day.

After the first second, the velocity changes by $0.0055 m/s$ and the total distance the Earth travels during the first second is $0.0055/2 = 0.00275 m$. However, if you study how this distance changes if you increase 1 second to 86,400 seconds, the total distance doesn't jump 86,400 times. Instead, it jumps $(86,400)^2$ times, to $$0.0275 \times 86,400^2 = 20,528,000 m.$$ You may check that 20,000 kilometers is approximately - within the errors that you introduced - the right amount to keep the Earth on a quasi-circular orbit because $$\frac{155\times 10^9 m}{2}\left(\frac{2\pi}{365.25}\right)^2 = 20,000,000 m$$ or so. In the equation above, I calculated the angle of the rotation around the Sun, squared it, divided by two (that's the approximation of $1-\cos\phi$), and multiplied by the radius.

After 86,400 seconds, the final speed in the transverse direction is not $0.0055 m/s$ as you assumed but $86,400\times 0.0055 m/s$.


Your units are wrong. Your acceleration of 0.0055 is m/s^2, and when you multiply by 86400 s/day, you get m/s/day, and not m/day^2, which is what you think you're getting. That's what confused you.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.