Math behind a "fling"? (i.e. on a mobile touch device) I'm working on a game which relies on "flinging" an object. That is, click and hold on the object, and then drag and release it, and it continues on the path you were dragging it. Of course, the most well-known example of flinging is with iPhone and Android devices, where you can quickly scroll down a list by quickly swiping your finger upward, giving the illusion of "flinging" the list.
I'm tracking mouse positions (x,y) and timestamps. But I'm drawing a blank as to how I can take a list of positions and times and get out of it a velocity or curve that an object should follow.
What are my options? Right now I am looking only for a straight-line fling action, but if it's easy to implement some sort of curve that better fits the fling, that would be good information that I might be able to integrate into the design of the game.
 A: In the physical world, once an object is released from all external forces, it will travel in a straight line. UI design strongly suggests that interfaces work better when the user is using previous knowledge of motor control, eye movement, physics, etc. Unless you have a legitimate reason to curve after the object is released, I would personally go with linear only.
In that case, take the last few coordinates and timestamps, and average the velocity components together. Then run a quadratic or exponential function of time on each component until the change of position is negligibly small. The latter functions relates to throwing an object upward and watching it being slowed by gravity, and the former relates to shoving an object on the ground and seeing it come to a stop by friction. Since the exponential function seems like the best for the job, here's an example.
Find the last few velocities for the $x$ and $y$ components, and average them:
$v = \frac{\Delta x}{\Delta t}; y = \cdots$
$x = \frac{\sum v_x}{n}; y = \cdots$
Set time from release for $t$, $\beta$ as some friction constant, $v_x$ as the average velocity for each component, and $x_0$ as the initial release point.
$x = v_x (1 - e^{-\beta t})$
The purpose of the 1 is to align the function to start at zero when time is zero.
So I hope this helps. I'm interested in what you're doing, so you'll have to show me when you're done. ;)
A: Why not compute a cubic spline from the 5 most recent samples equidistant in time?  This will give you a smooth curve and you can use the parametric derivative of the spline as a velocity.  http://mathworld.wolfram.com/CubicSpline.html
