1

I have a ball which drops to a point, from which it should bounce and reach another point.

My ball starts with an acceleration towards the first point, hits the point and bounces off to the left side. What I want is the velocity & acceleration applied to the ball after hitting the first point, so it both has a bouncing effect, and reaches it's destination (doesn't go offside, like the bright trail).

I have the linear vector between points, coordinates of points and angle between them.

Explanation

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Mahdi Dibaiee
  • 885
  • 1
  • 7
  • 20
  • 2
    What's your question? Where's your code? What have you tried? – j08691 Jun 13 '15 at 15:49
  • some similar questions worth looking: [cannon ball trajectory](http://stackoverflow.com/a/26174961/2521214) , [Bouncing Ball](http://stackoverflow.com/a/20017455/2521214) – Spektre Jun 14 '15 at 08:33

2 Answers2

2

First we figure out how long it will take to get from the higher point to the lower point by solving for t:

at2 + viyt = dy

Then we take t and use it for our lateral velocity:

vx = dx / t

Once you have the lateral velocity, just slice time up as finely as you like and move the ball to each calculated point in turn.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Could you please add some details on the math? I don't get what a in at² and the indices on v mean. I would like to try it. – stacker Jun 13 '15 at 20:00
  • @stacker `a.t^2+v(iy)=dy` is y axis equation of the bounced movement `a` is local forcefield (gravity) acceleration (usually `-9.81m.s^-2`), `v(iy)` is the incident speed in y axis after hitting the ground the first time, `t` is time from the first bounce and `dy` is the ground line size in y axis only `a,v,dy` are knowns `t` is unknown you need to solve that quadratic equation and the resulting positive `t` is time the ball need to hit the second bounce point .the rest should be clear ... – Spektre Jun 14 '15 at 08:22
0

If you don't want a full blown physics simulation you could fake this by a linear interpolation (lerp) from the start point to end-point.

See Moving object from vector A to B in 2d environment with in increments of percents for lerp in java script.

Change the coordinate pointing upwards (y or z) depending on the coordinate system you use. While t is animated from 0..1:

 var relativeHeight = Math.Sin( t * Math.PI ) * curveAmplitude;
 posy = orgPosy + relativeHeight;
Community
  • 1
  • 1
stacker
  • 68,052
  • 28
  • 140
  • 210