Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Speed of the knockback is <= 0

  1. Jul 8, 2009 #1
    I can explain them by 2 ways, I am making some sort of a game. I am doing a some sort of a knockback but the unit will be flying.

    Imagine that the knockback ends only when the speed of the knockback is <= 0 and there is decrement & speed which is user specified.

    The unit is moved by a timeframe of 0.03 seconds and gravity = -981. I know it is initially 9.81 but in the game it is calculated as -981.

    Every 0.03 seconds untill speed <= 0, speed is constantly reduced by decrement and how would I go about making the unit perform a parabola from point A (initial position of the unit) to point B(final area).

    I do not really know how to calculate distance with speed and decrement but is it like

    -1 * speed * speed / (2 * -decrement / Timeframe)

    And I want to know how can I get the time of the knockback.

    ???


    In another way I could say it like unit A has 3 vectors. Vector position, acceleration and velocity(They get updated every timeframe). Position stores the position of the unit and acceleration is actually deacceleration as it is negative. Velocity is just initial speed of the unit and gets decreased every timeframe by acceleration.

    Velocity vector adds the acceleration and then Position vector adds the velocity every timeframe. The knockback would end when the dotproduct of velocity and acceleration >= 0.

    Distance used to calculate is the same as the following one above.

    So How would I go about doing a perfect parabola?
     
  2. jcsd
  3. Jul 11, 2009 #2

    jtbell

    User Avatar

    Staff: Mentor

    Re: Parabola

    This is possibly a stupid question, but... what is a "knockback"? :confused:
     
  4. Jul 11, 2009 #3

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    I assume this is like an angled trampoline for a ball. The USA name for this is a pitchback:

    http://www.sportsworldwholesalers.com/2770fs.html [Broken]

    Using parametric equations:

    Position:

    Px(t) = Vx t + Px0
    Py(t) = 1/2 Ay t2 + Vy0 t + Py0

    Velocities:

    Vx(t) = Vx
    Vy(t) = Ay t + Vy0

    Accelerations:

    Ax(t) = 0
    Ay(t) = -981

    In the classical numerical integration case, you only know the equations for acceleration for a given set of velocities and positions, but this is a case where the equations for velocities and position are also known.

    The acceleration equations, combined with initial velocities and positions, are what you need to create a parbola using numerical integration. Since the integrals of acceleration and velocities are known equations, you can use these to confirm your method of numerical integration

    In cases like this one, where acceleration is constant or can be calculated based on time without knowing velocities or position, an averaging method can be used if the steps are small enough:

    Vn+1 = Vn + 1/2 (An+An+1) Δ t

    In this case, since acceleration is a constant, you just end up with the known equations for velocities. Position calculations become:

    Pn+1 = Pn + 1/2 (Vn+Vn+1) Δ t

    Again, because acceleration is a constant, position calculations will also end up as the known equations for positions. Post #8 shows this for Py.

    Numerical_intergration_wiki.htm

    Predictor-corrector_wiki.htm

    Runge_Kutta_wiki.htm

    A more classic example of numerical intergration produces a sine or cosine wave using:

    A = -P

    Along with initial velocity V0 and position P0.
     
    Last edited by a moderator: May 4, 2017
  5. Jul 11, 2009 #4
    Re: Parabola

    is T time or is T timeframe?

    initial position z = the height of the object
    initial acceleration = -981/2

    in the timeframe function itself (TIME = TIMEFRAME)

    velocity.z = GRAVITY + (TIME*TIME) + acceleration.z* TIME
    position.z = position.z + velocity.z
     
  6. Jul 11, 2009 #5

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    T is elapsed time, Δt is time step. I don't know what you mean by time frame.
     
  7. Jul 11, 2009 #6
    Re: Parabola

    I'm doing some sort of programming and I have to move a object by a timeframe which lets say is 0.03.

    velocity.z = velocity.z + acceleration.z * (timeperiod*timeperiod)
    position.z = position.z + velocity.z * timeframe
    timeperiod = timeperiod + timeframe

    Here are my current calculations, are they correct?

    I don't know why did you multiply initial velocity by the timeperiod.
     
  8. Jul 12, 2009 #7

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    first one should be:

    velocity.z = velocity.z + acceleration.z * (timeperiod)

    That's part of the formula for position. (note - I editted my previous post to clean up the names in the formulas.)

    If acceleration is constant:

    Δt = t1 - t0

    initial velocity = Vy0
    final velocity = Vy1= Vy0 + Ay Δt
    average velocity = 1/2 (Vy0 + Vy1) = 1/2 (Vy0 + (Vy0 + Ay Δt)) = Vy0 + 1/2 Ay Δt

    initial position = Py0
    final position = Py0 + (average velocity) Δt = Py0 + (Vy0 + 1/2 Ay Δt) Δt = Py0 + Vy0 Δt + 1/2 Ay Δt2
     
    Last edited: Jul 12, 2009
  9. Jul 15, 2009 #8
    Re: Parabola

    I don't really get some parts understood but I think I got some part of it right.

    Object A

    velocity = vx,vy,vz (any numbers will do)
    acceleration = ax,ay,az ( any number will do except az which is gravity*0.5 like you said)
    distance = the distance covered by the ball
    time = distance/(speed/2) (Finding the distance covered by the ball when thrown)

    Position vector is available but not random numbers.

    Current calculations in the timeframe are as followed

    vx = vx + ax
    vy= vy + ay
    vz = vz + az * timeframe
    px = px + vx * timeframe
    py = py + vy * timeframe
    pz = pz + vz * timeframe

    If you do not know what the variables mean, they are;

    velocity vector = vx,vy,vz
    position vector = px,py,pz
    acceleration vector = ax,ay,az.

    Final velocity are all 0.

    I don't understand much of why are you using average velocity so I posted this. To sum it up, how would I do a parabola if velocity z can be inputted by any number? Setting it higher or lower makes it look stupid.
     
    Last edited: Jul 16, 2009
  10. Jul 16, 2009 #9

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    Say a vehicle is experiencing constant acceleration. At time t0 the vehicle is moving at 30 kph, one second later, at time t1, the vehicle is moving at 50kph. How much distance (position) the vehicle travel during this time?

    To solve this type of problem you use distance = average velocity x time.

    For numerical integration, one simple method is to use linear interpolation for each interval, change in position = "average" velocity x time step, this the equivalent of "trapezoidal" rule (for finding area under a curve).
     
    Last edited: Jul 16, 2009
  11. Jul 17, 2009 #10
    Re: Parabola

    Do I do them for the x y z coordinates or just the z coordinates?

    Which should I use?

    Or

    I am abit confused by those 2 statements.
     
  12. Jul 17, 2009 #11

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    You can do them for all coordinates, but velocity only changes where there is acceleration, and in your example acceleration only occurs on the z axis. Calculating the average velocity when it's not changing still works. If the velocity is 30kph at the start and 30kph at the end, than average velocity = 1/2 (30 + 30) = 30, so might as well be consistent and use the same method for x, y, and z, while noting that acceleration only occurs on the z axis.

    The initial speed of the vehicle is 30 kph, the final speed is 50 kph, the average speed = 1/2 (30 + 50) = 40 kph.

    http://en.wikipedia.org/wiki/Trapezoidal_rule

    In your case, we can calculate velocity based on elapsed time, so given Vz0, Vz1 can be calculated via Vz1 = Vz0 Az x Δt. The "a" used in the wiki article would be Vz0, and the "b" would be Vz1.

    Note that this type of numerical integration only works when acceleration is function of time. If acceleration is a function of velocity and position, then standard numerical integration methods are required. For a simplified aerodyamic drag equation, A = -V2 is a better example, although it's simple enough to integrate directly. I already mentioned A = -P which generates a sine wave as another example.
     
    Last edited: Jul 17, 2009
  13. Jul 17, 2009 #12

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    Here is an example of a crude "predictor corrector" algorithm. To simplify things, I'll use an example that where only one level of integration is required, such as A = -c V2 where c is some constant.

    Initial state V0

    Time step = Δt

    A0 = -c V02

    Make first guess assuming A is constant:
    Ag 1 = A0

    Calculate a velocity guess based on average acceleration
    Vg 1 = V0 + 1/2 (A0 + Ag 1) Δt

    Make a new guess for A based on Vg1
    Ag 2 = A(Vg 1) = -c Vg 12

    Calculate another velocity guess based on average acceleration
    Vg 2 = V0 + 1/2 (A0 + Ag 2) Δt

    If Δt is small enough that an inflection point isn't an issue, this process will converge, so repeat this process:
    Ag n+1 = A(Vg n)
    Vg n+1 = V0 + 1/2 (A0 + Ag n+1) Δt

    Until | Ag n+1 - Ag n | < some tolerance factor.

    You can put a limit on this, if | Ag n+1 - Ag n | is not less than the tolerance factor after some specific number of steps, say 16, then decrease Δt and repeat the step. If convergence occurs in less than say 4 steps, increase Δt.

    Then you start a new step using

    A1 = Ag n+1
    V1 = Vg n+1

    This is a crude process but most of the methods require generating a few initial steps before the iteration (looping) process can be eliminated. This iterative process could also be used with the better algorithms listed in the links above for each step.
     
    Last edited: Jul 17, 2009
  14. Jul 18, 2009 #13
    Re: Parabola

    I tried to use this one on your post above

    But it ended up backfiring.

    initialization before throwing
    s = speed

    Inside Timeframe function

    set position.z = position.z + s*time+0.5*GRAVITY*(time*time)
    set time = time - timeframe
     
  15. Jul 18, 2009 #14

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    s = initial speed.z

    set position.z = position.z + s*timeframe+0.5*gravity*(timeframe*timeframe)
    set time = time + timeframe
     
  16. Jul 18, 2009 #15
    Re: Parabola

    Yep, s is initial speed z, I probably didn't get it clear for you sorry.

    time is actually the full time for the thrown ball but now edited to be 0 at start.

    position.z = position.z + s*timeframe+0.5*GRAVITY*(timeframe*timeframe)
    time = time + timeframe

    So how can time fit in now? I followed your example above and objects launched in the air never gets down.
     
  17. Jul 19, 2009 #16

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    Note that gravity is negative. It's -9.80665 meters/second2 or -32.174 feet / second2.
     
  18. Jul 19, 2009 #17
    Re: Parabola

    Gravity is -981 since it's converted to the game's units.

    What about that time variable that gets increased in the timeframe function?
     
  19. Jul 19, 2009 #18

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    The time variable isn't being used in the other equations. You'd might use it to make a graph of position or velocity versus time.
     
  20. Jul 20, 2009 #19
    Re: Parabola

    Well that was actually what I was doing all along. timeframe was timestep actually, I think you misunderstood.

    Right now I am using a parbolic equation that calculates things and allows people to specify a maxheight but there will no longer be any gravity.

    function ParabolaZ2_v2 takes real y0, real y1, real h, real d, real x returns real
    return ((4 * h / d) * (d - x) + y1 - y0) * (x / d) + y0
    endfunction

    y0 = initial z coordinate of object
    y1 = z coordinate at end of the ball
    h = maxheight
    d = distance
    x= distance travelled

    It makes the thrown ball drop exactly when the velocity is 0 but the old one doesn't and I was wondering if it was possible to do it with physics.
     
  21. Jul 20, 2009 #20

    rcgldr

    User Avatar
    Homework Helper

    Re: Parabola

    I understood that timeframe was timestep or delta time. I don't understand why there is a parabola if there's no gravity. I don't understand what your parabola function is trying to calculate.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Speed of the knockback is <= 0
  1. Time at t = 0 (Replies: 11)

Loading...