Detecting a shake gesture, from a collection of points, is basically looking for three changes in direction:
Example: (We need to look only at x-coordinates, as we are looking only for horizontal shakes, not vertical shakes)
1,2,3,4,5,6,7,8,[9],8,7,[6],[7]
In the above sequence of x-coords, I have marked the changes in direction with [].
The problem is, in the above case, we would detect even tiny unintentional shakes - for example, if you ask a person to drag his finger from the bottom of the screen to the top in a straight line, his hand may move a little left and right unintentionally, and we would regard this as a "shake"
Example:
1,2,[3],[2],[3].... (unintentional shake)
To avoid this, we need some kind of threshold, only above which we regard the movement as a shake. For example, the gap between changes in direction should be atleast 3 points, and the difference in value should be atleast 4.
So we should have something like:
1,2,3,4,5,6,7,8,[9],8,7,6,[5],6,7,8,[9]..... detected shake
1,2,3,4,5,6,7,8,[9],8,7,6,6,7,8,9..... ignored shake
1,2,3,2,1.... ignored shake...
This seems tricky to implement, as one would probably have to keep track of three indices. Rather than implement this myself, I was wondering if this is a known algorithm with a solution that I can look up ?