1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Formula for simulating orbital motion (2D)

  1. Feb 3, 2013 #1
    Hello. I'm new on this forum and I hope I'm posting this in the right place. This is not for a homework assignment but a spare-time project I'm working on.

    1. The problem statement, all variables and given/known data
    The goal with this project is to make a simple program that simulates an object that orbits a single fixed point. This behavior will be drawn on a 2D canvas, for instance in a web browser. The program will draw the object's position for each frame. This program looks somewhat like what I'm trying to accomplish, but it lacks an "algebraic" formula, so the orbit here is unstable. Since I want the orbit to be stable, I can't just keep adding to the speed and acceleration variables, since this would give noticeable rounding errors over time.

    What I need is a formula to find the distance traveled for any given time with only these variables:

    pi - Initial position
    ti - Initial time
    vi - Initial velocity (speed along x and y axis)
    ri - Initial radius (which gives the acceleration)
    tf - Final time

    The problem is that if the orbit is not circular, the radius will change over time, and so will the acceleration. I'll probably need to use derivatives. Once I have this formula working for a one-dimensional scenario (i.e. a vertical drop), I'll be able to solve for horizontal and vertical displacement.

    2. Relevant equations
    I'm trying to keep things simple for now, just so I can understand the concept.
    [itex]F = ma[/itex]. Assuming [itex]m = 1[/itex] gives [itex]F = a[/itex]
    [itex]F = Gm1m2/r^2[/itex] simplifies to [itex]a = 1/r^2[/itex] (assuming G = m1 = m2 = 1).
    [itex]a = Δd/t^2[/itex]
    [itex]Δd = vi*t + at^2/2[/itex]

    3. The attempt at a solution
    I was thinking of just substituting [itex]a[/itex] with [itex]1/r^2[/itex], like this:
    [itex]Δd = vi*t + (1/r^2) * t^2/2 =[/itex]
    [itex]Δd = vi*t + t^2/2r^2[/itex]

    But this somehow feels wrong.

    Another thing that came to mind is that the functions Δd(a) and Δa(r) look very similar. I've been refreshing my calculus skills lately but I feel like I'm in way over my head here. :uhh:

    Any helpful input is much appreciated.
    Last edited: Feb 3, 2013
  2. jcsd
  3. Feb 3, 2013 #2


    User Avatar
    2017 Award

    Staff: Mentor

    You cannot separate the two components.
    This setup is known as Kepler problem, and there are formulas you can use.
  4. Feb 4, 2013 #3
    Thank you for your reply.
    Which components are you referring to? As far as I can see I am only trying to merge two formulas, and it seems very doable. It would help me if you could explain why this will not work.

    I'm making some statements here; if any of them are wrong please tell me:
    - The average velocity of a moving object can tell us how far it has moved in a certain time frame, given constant acceleration.
    - If acceleration is not constant, the average acceleration should give the same result, that is, how far an object has moved (in a time frame).
    - In a scenario with two objects orbiting each other, the acceleration will change with the radius (the distance between their centers of mass, by inverse square law).
    - Given the above, if I know the initial and final radius in a time frame, I could use that to calculate the average acceleration, and with that find the distance moved (either as a vector, or by calculating separately for the x and y axis).

    I read your link on the Kepler problem but I don't see how it directly relates to what I'm trying to do. The formulas presented on the wiki can be tedious to understand. I will look into it though. I want to know how formulas work before I use them in my program.
  5. Feb 4, 2013 #4


    User Avatar
    2017 Award

    Staff: Mentor

    The two coordinates. You cannot solve the motion independently for both (apart from some trivial examples where the motion is 1-dimensional), as the radius (which influences the gravitational acceleration) depends on both at the same time.

    Right. But acceleration in an orbit is not constant.
    This is wrong. Consider two different objects, both start at x=0 and t=0.
    A accelerates with 10m/s^2 for one second, and keeps its velocity of 10m/s for 9 seconds afterwards. Final velocity: 10m/s. Average acceleration: 1m/s^2. Total distance travelled: 95m.
    B keeps motionless for 9 seconds, and accelerates with 10m/s^2 afterwards. Final velocity: 10m/s. Average acceleration: 1m/s^2. Total distance travelled: 5m.
    Not just with the radius, as the direction of acceleration changes as well.
  6. Feb 6, 2013 #5
    Ah. I forgot to mention I will be using the Pythagorean theorem to find the x and y components, since a vector with an angle can also be represented using only its x and y components. Ex: An object moving 5 units with a positive 60 degree angle relative to the x-axis will have moved 4 units in the y-direction and 3 in the x-direction. This concept works for movement and velocity, and it should for acceleration as well.


    You're right, thanks for correcting me. It should be possible, though, to estimate how far an object has moved given varying acceleration as long as it can be expressed as a function. If I were to graph your example with velocity along the y-axis and time along the x-axis, the area between the graph and the x-axis would equal the distance traveled. This concept wouldn't change even if the graph function was exponential (integration is required to find the area though). The relationship between radius and acceleration is fixed, so this should be graphable somehow.

    Imagine this scenario:
    In a 2D coordinate system, a projectile accelerates towards a point (0,0). At time t = 0, its initial position is (2,-10). The initial velocity is (6, 2) units/time in the x- and y-directions respectively. The initial radius is given by the position. The initial acceleration is given by the radius. The direction of the acceleration will change over time, but it will always point towards (0,0). Given these initial conditions, at any final time, there is only one possible position the projectile may be in. So there must exist a formula that correctly graphs this path.
  7. Feb 6, 2013 #6


    User Avatar
    2017 Award

    Staff: Mentor

    If you know the acceleration as function of time, you can calculate the position, sure. But you have no easy way to determine this, as acceleration depends on position, and those influence each other all the time.
    As I posted, there are solutions, but they (and their derivation) are not as easy as you might hope.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook