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!

Extrapolating pos., vel. given initial pos., vel. and constant acc.

  1. Aug 12, 2009 #1
    Hi there!

    I'm working (programming) on a little project where I want to be able to get the position of an object at any point in time assuming its acceleration doesn't change. The object has an initial position and velocity.

    It's very easy to extrapolate the position after x time given a constant velocity, but now the velocity will be changing over time as well, which is where I'm having problems. Would anyone be so kind and point me in the right direction? =)

    If my question wasn't clear, here's an example that describes it more practically: I have a ship in space (far out, practically unaffected by gravity) and it's floating in one direction and pointing in another. Now I start the forward thrusters which accelerate the ship constantly. From this point on, I want to be able to get the position and velocity of the ship at any time forward.

    Also, does this ship ever reach a maximum speed (assuming its thrusters do not exert any force stronger than what we have today)? Or will it slowly creep up in speed until it is disintegrated (assuming the ship has unlimited fuel and a constant mass)? The second case seems unlikely to me, but I've never had a physics class so what do I know? =)

    If the first case is true, how do I implement this into the formula (if possible)?
     
  2. jcsd
  3. Aug 12, 2009 #2

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

  4. Aug 12, 2009 #3
    Yeah, I've implemented Verlet into my projects many times (see http://blixt.org/js [Broken] for a web browser demonstration =)

    The problem I'm describing is very easy to solve with any step-by-step solution:

    step:
    velocity = velocity + acceleration
    position = position + velocity
    repeat step

    I need a solution where I can say, "I knew the position and velocity at time x, now I need to know the position and velocity at time (x + 1234 milliseconds)" which is hard to solve efficiently (and accurately) with step-by-step methods.
     
    Last edited by a moderator: May 4, 2017
  5. Aug 12, 2009 #4

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

    If you asking for a closed form solution given a constant acceleration then that is simple calculus.

    [tex] a(t)=a[/tex]
    [tex] v(t)=\int_0^t a(t') dt' = at + v_0[/tex]
    [tex] x(t)=\int_0^t v(t') dt' = \frac{1}{2}at^2+v_0t+x_0[/tex]

    Since your velocity is time dependent then you will either need to find a closed form equation for the velocity or acceleration and apply the appropriate integrations. It appears that you intend constant acceleration so then the above equations should be enough.
     
  6. Aug 12, 2009 #5
    See, now you lost me a bit =) I quit school for work at the age of 15 and never got around to learning calculus. Being a web developer I've never come across the need for calculus, and therefore I quite frankly suck at it. So would you mind explaining the formulas in less LaTeX-ish forms? =)

    This is how I interpret them, in my programming terms:

    function getVelocity(initialVelocity, acceleration, time):
    return initialVelocity + acceleration * time

    function getPosition(initialPosition, initialVelocity, acceleration, time):
    return 0.5 * acceleration * time * time + initialVelocity * time + initialPosition

    Is that right?
     
  7. Aug 12, 2009 #6
    I made a test case to get a more visual look on the whole thing. It looks like this: http://blixt.org/js/extrapolate.html [Broken]

    My step-by-step method appears to differ slightly from the formula. I'm not sure why, any ideas? The difference is too great to be floating point inaccuracy. I'm using the formulas I wrote in my previous post. (The velocities match, so the difference is in how I calculate the position step-by-step and what getPosition returns.)

    Also, one thing I'd love to implement into the formula is the limit on the velocity vector (check the checkbox.) Is this possible at all?
     
    Last edited by a moderator: May 4, 2017
  8. Aug 12, 2009 #7

    rcgldr

    User Avatar
    Homework Helper

    The position part is the problem, you need average velocity to determine it:

    step:
    velocity_previous = velocity
    velocity = velocity+acceleration
    position = position + .5* (velocity_previous + velocity)
    repeate step

    This will result in an exact result, limited by the precision of numbers on your computer. Since acceleration is constant, there's no point in averaging new and previous accelerations. This step process is a form of numerical integration. The step process you showed above would be called "Euler", the step process I show where averaging is done, is called "trapezoidal".
     
    Last edited: Aug 12, 2009
  9. Aug 12, 2009 #8

    jtbell

    User Avatar

    Staff: Mentor

    You don't need calculus or numerical integration for this.

    You can use the standard equations for motion with constant acceleration, but since the acceleration and initial velocity aren't in the same direction, you need to use the vector versions:

    [tex]\vec v = {\vec v}_0 + \vec a t[/tex]

    [tex]\vec r = {\vec r}_0 + {\vec v}_0 t + \frac{1}{2} \vec a t^2[/tex]

    These simply represent similar pairs of equations for the x, y and z components of the motion:

    [tex]v_x = v_{0x} + a_x t[/tex]

    [tex]v_y = v_{0y} + a_y t[/tex]

    [tex]v_z = v_{0z} + a_z t[/tex]

    [tex]x = x_0 + v_{0x} t + \frac{1}{2} a_x t^2[/tex]

    [tex]y = y_0 + v_{0y} t + \frac{1}{2} a_y t^2[/tex]

    [tex]z = z_0 + v_{0z} t + \frac{1}{2} a_z t^2[/tex]

    You have to specify the initial position of the ship ([itex]x_0, y_0, z_0[/itex]), the initial velocity components ([itex]v_{0x}, v_{0y}, v_{0z}[/itex]) and the acceleration components ([itex]a_x, a_y, a_z[/itex]). Then you can use the equations above to calculate the position (x, y, z) and velocity components ([itex]v_x, v_y, v_z[/itex]) at any time t.

    This is the exact solution for constant acceleration. A stepwise procedure which calculates each point based on the one preceding it (instead of always basing it on the initial point) will usually give you only an approximation. This can be because of one or both of (1) accumulated roundoff error (2) intrinsic limitations in whatever step-by-step approximation you're using, which of course depend on the particular method.
     
    Last edited: Aug 12, 2009
  10. Aug 12, 2009 #9

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

    Like Jeff has stated, are you using an Euler or Verlet integrator? If you are, reduce the time step and see how they match up. The Verlet integrator should give you an error on the order of the square of the time step, the Euler integrator is on the order of the time step. So reducing the time step should help improve your global positioning error.

    EDIT: As for limiting the velocity, that would just be a programming problem. Given an acceleration solve the amount of time it will take for your velocity to reach the limit. Then, use the standard equations for any time t less than the limit, above the limit keep the velocity constant. jtbell's post is usefull because up to now I have neglected discussing anything other than a one-dimensional problem. I would note though that for vectors,

    [tex]v = \sqrt{v_x^2+v_y^2+v_z^2}[/tex]

    If you want to find the magnitude, you need to use the above formula like I have to find the total speed.
     
  11. Aug 12, 2009 #10

    rcgldr

    User Avatar
    Homework Helper

    For constant acceleration the trapezoidal integrator algorithm is exact (since velocity changes linearly, then a linear approximation can be exact), but the repeated additions will involve floating point truncation errors. If the step size is the full time period you end up with the standard equation for distance versus time and acceleration.

    t = Δt = t1 - t0

    v1 = v0 + a t

    x1 = x0 + 1/2 (v0 + v1) t
    x1 = x0 + 1/2 (v0 + (v0 + a t)) t
    x1 = x0 + 1/2 (2 v0 + a t) t
    x1 = x0 + v0 t + 1/2 a t2
     
    Last edited: Aug 12, 2009
  12. Aug 12, 2009 #11
    Hmmm... What if the max velocity magnitude is 100, and the initial velocity is (100, 0), and the acceleration (0, -100)? It'll be at max velocity already at t=0.0, but I want the path to curve until the velocity eventually (at infinity, I guess, if dealing with exact numbers) reaches (0, -100) unless the acceleration changes. Have a look at how it behaves in my example.

    The way I do it in my step-by-step solution is that I normalize the current velocity vector if its magnitude/length/norm is above the limit and then create a new vector that's been weighed by the acceleration, slowly turning in the direction of the acceleration while maintaining its magnitude.
     
  13. Aug 12, 2009 #12

    rcgldr

    User Avatar
    Homework Helper

    By definition, no, you've stated that acceleration is constant, so there is no maximum velocity. (constant acceleration would conflict with relativistic properties where the speed of light is the limit). There is a minimum velocity, zero, at the point when the ship changes direction.

    You can use the step by step method with averaged velocity as I've shown, or you can just use the formulas given above (the formulas wouldn't be affected by truncation).
     
  14. Aug 12, 2009 #13
    I see. What if this was a "real" situation where we had a spaceship with some kind of propulsion method that could output a force for a very long period of time. Would the acceleration of the ship stay relatively constant? Just curious =)

    In most space movies, spaceships going on "full thrust" appear to reach some kind of max speed (I'm basing this on that a spaceship can follow an already accelerating [equivalent] spaceship, even when starting from a low velocity.)

    Oh, and I updated my step-by-step code to use the trapezoidal method, and now it shows the same results as the formula =) I'm still pretty stuck on how to give the formula the "norm limit" functionality that my step-by-step method has (See my previous post.)
     
  15. Aug 12, 2009 #14

    rcgldr

    User Avatar
    Homework Helper

    If you ignore relativistic effect, then there is no max speed. If relativistic effects apply, then any object with mass as observed from the rocket would always travel below the speed of light.

    This is not realistic.
     
  16. Aug 12, 2009 #15

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

    Actually, the acceleration would not be constant because in a real situation the mass of the rocket is changing with time. Force is the time derivative of the momentum, mass times velocity. Normally, most systems have constant mass and so F=ma. However, in a rocket, the mass of the rocket decreases as the fuel is spent, and so you have to take that into account. Thus, F=ma+v*dm/dt, so for a constant force we would have a changing acceleration.
     
  17. Aug 13, 2009 #16
    Yup, I saw that one coming (which is why I defined my imaginary ship in my first post to have a constant mass =)

    Anyways, to get back to the question in this thread: Is there a way to make the same formula we have now to calculate velocity and position for any time, but with the addition of terminal velocity? I hope the term "terminal velocity" doesn't confuse, because in this case the force moving the object isn't gravity, but an acceleration in any direction. And let's say the restraining force causing the terminal velocity is some unseen matter (because in the application I'm programming, it's not feasible to have the objects approach the speed of light =)

    Basically, I'm looking for the equivalent of constantly adding the acceleration to the velocity, followed by forcing the magnitude of the velocity to be a certain amount, but (and here's the really tricky part) only if the velocity exceeds a certain limit. The effect will be that even once the velocity hits max, the direction of the velocity will still be changing (it's being influenced by the acceleration.)

    I understand this is a hard nut to crack, and I'll take any solution even if it's not exactly what I described above. The only requirements are that it looks good on the screen (the velocity starting in one direction, then slowly changing to be in the direction of the acceleration, constantly accelerating as well, but not beyond the max velocity) and that it's deterministic given the initial parameters (position, velocity, acceleration.)
     
  18. Aug 13, 2009 #17

    rcgldr

    User Avatar
    Homework Helper

    In order to limit the velocity, you'd need to choose from a variety of functions that would have such a limit. For example, y = 100 - 1 / xn is a family of curves with 100 as the limit. A similar family of equations would be y = 100 - 1 / ax.
     
  19. Aug 13, 2009 #18

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

    That will not be a problem if you implement it as I suggested. You can just use algebra to solve for the time when your velocity will meet your desired limit. Then, you can just use a conditional to implement the ideal equations for any time less than this limit and then set the velocity to the limit velocity and acceleration to zero for your equations for any times greater or equal to the limit. But treat the time limit point as the starting point for new equations. That is, just use (t-t_0) as your time and set your initial v and x as the points at the time limit.

    If you are looking to cap the speed but still apply an acceleration, then I do not know off-hand how you will get this easily, in closed-form, a priori.
     
    Last edited: Aug 13, 2009
  20. Aug 13, 2009 #19
    Ah, but consider it again. Velocity is (100, 0) and acceleration is (0, -100). Max velocity is 100. Now I calculate the time the velocity reaches 100, which gives me t=0. So now I use the first formula from time 0 to 0 (i.e., it won't affect the end result), then I apply the second formula for the remaining time. This will result in the object moving in a straight line along the x-axis.

    What I want is for the object to move along a curve which is slowly changing its direction just like it does without this limit, but at any point in time the magnitude of the velocity must not exceed 100. After a certain amount of time, the object will be moving mostly along the y-axis.

    Edit:
    Ah, I see now in your last paragraph that you mention what I'm after. I've been looking all over the web for something similar and haven't found it. I've even tried curve fitting to make approximations of the curve, but I haven't gotten any good results from that either. I'm considering just using steps after all and only allowing times on which a step occur. Since I will be using cubic splines to visualize the positions, the inaccuracies this will cause will be hidden from the client, but unfortunately this will increase the CPU usage quite a bit for the server.
     
  21. Aug 13, 2009 #20

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

    Velocity and speed are different. If you want to stop accelerating upon reaching a desired velocity, it would be fine (provided that the acceleration can achieve your desired velocity). Capping at a specified speed but allowing for acceleration is a different problem. If you said the initial velocity was (100,0) and you wanted to stop accelerating at V = (-100,0) with an acceleration of (-100,0), then that can be solved as I stated above. The time would be 2. If you had an acceleration of (0,-100), then you could not achieve the desired velocity and you would not be able to solve it. This is the difference between limiting the velocity and limiting the speed.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook