How to predict trajectory of a moving ball? So I am working with python + opencv to predict the trajectory of a moving ball.
I am able to track the motion of the ball which is actually color tracking. However, I have no idea how can I predict its path.
I found a paper dealing with this situation: http://natguy.net/juggling_paper.pdf
Its explains on third page under state estimation that it uses Euler's method to find a predicted trajectory through space subject to gravity. I dont understand how this works.
Can you please explain it? Or can you please suggest some other method for this prediction?
By the way, this is the link for its implementation by the same guy who wrote that paper: https://github.com/NattyBumppo/Ball-Tracking
Thank you.
 A: Euler's method approximates an exact solution to a differential equation as an iterative algebraic equation. Look at it like this - given a differential equation like
$$\frac{dx}{dt}=x^2-t$$
We can loosen the definition of $\displaystyle d=\lim_{\Delta\to0}\Delta$ and instead revert back to using $\Delta$ with a nonzero limit and refer to it as the step size - by how much are we jumping in time between iterations.
$$\frac{dx}{dt}\approx\frac{\Delta x}{\Delta t}=\frac{x_{i+1}-x_i}{\Delta t}$$
And for reference
$$\frac{d^2x}{dt^2}\approx\frac{x_{i+1}-2x_i+x_{i-1}}{\Delta t^2}$$

Using the first, we can approximate the solution to the differential equation
$$\frac{x_{i+1}-x_i}{\Delta t}=x_i^2-t_i\implies x_{i+1}=x_i+\Delta t\left(x_i^2-t_i\right)$$
Notice that to begin this iterative process, we first need to know the initial condition to calculate the next position. Likewise, using the second derivative approximation requires two initial conditions.
This is extremely useful when plotting solutions/gathering data to differential equations that are difficult to solve, as it approximates the solution one step at a time.

Edit:
If you have drag, then you must separate the solution into two parts: $1$. When the ball is going up (drag is acting in the direction of weight) and $2$. When the ball is coming back down (drag is opposite of weight). Then you'll have (with positive $z$ direction going upwards)
$$\sum_1F_z=-mg-F_d=m\frac{v_{i+1}-v_i}{\Delta t}$$
It's clear that the object is slowing down as the iterations progress and it will reach its peak when $v_{i+1}=0$. Then you must change the direction of drag.
$$\sum_2F_z=-mg+F_d=m\frac{v_{j+1}-v_j}{\Delta t}$$
Where there's a matching condition between the two stages which gives you the initial value for the first $v_j$
In the case that there is no drag, then $F_d=0$. Each part is then the same so you get the approximation of the solution presented by Blavius (which assumes no drag). In either case for the approximation, you want to solve for the next iteration, $v_{n+1}$ and loop through the values to keep finding $v_{n+1}$.
To find its $z$-position, you would have to numerically integrate these data found by velocity or use the second relation that $\frac{dv}{dt}=\frac{d^2s}{dt^2}$ and again solve for $s_{i+1}$ and keep looping through to find its next position.
A: I can suggest a different method. You know acceleration $a$, initial velocity $v_0$, and initial position $p_0$, and an arbitrary time $t$. This approach uses the definition that $a = \frac{dv}{dt} = \frac{d^2p}{dt^2}$.
Since $a$ is the derivative of velocity, you can integrate $a$ with respect to $t$ to obtain an updated velocity:
$$v=\int a dt=at+v_0$$
And since position is the derivative of velocity, integrating this new velocity with respect to time will result in the new position:
$$p=\int at+v_0 dt = \frac{1}{2}at^2+v_0t+p_0$$
Now we have an updated position as a function of time. Note that this just the y position. The x direction should have a constant velocity. Thus, if you want this equation as a function of $x$ rather than time $t$, you can parameterize it. Since $x = v_xt$, you know that $t=\frac{x}{v_x}$. Now you can make your y position a function of your x position by plugging in that value for $t$ into the equation above.
