I’d like to do the following;
- create a 2 -column array of arbitrary finite length (say, 10 rows)
- populate it sequentially from a constant-rate datastream
- once its populated, update it from the same datastream ( ie replace element 0, move 1-9 down, discard old 9)
- (optimally) output an average for each column
I can probably do 4 myself, but have no idea how to do 1-3.
If it helps, I’m trying to translate this;
http://kindohm.com/2011/03/01/KinectCursorControl.html (see under the dreaded shaking cursor).
This should work ok (nice question, by the way – fun little challenge, since there are tons of ways to do it)
What it basically does is it creates an object and assigns it to
pointSmoother. The object has 4 methods:pushPoint(),clear(),getPoints()andaverage(). At the top of the thing you can set how many coordinates a point has, and how many points (maximum) to keep. I used your example of 2 coordinates per point, and 10 points at a time.Now, I’ve made the assumption that you get your values in sets of 2 at a time. Let’s call those 2 values
xandy. When you receive them, add them to the thing by usingpointSmoother.pushPoint(x, y);. You can then get the “average point”, by callingpointSmoother.average()which will return an array with (in this case) 2 values: average x and average y.If you want to look at the array yourself, you can call
pointSmoother.getPoints()which will return the points array. And lastly,pointSmoother.clear()will empty the array of previous values.Here’s a demo, of sorts: http://jsfiddle.net/tapqs/1/