Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:34:01+00:00 2026-05-24T07:34:01+00:00

I’d like to do the following; create a 2 -column array of arbitrary finite

  • 0

I’d like to do the following;

  1. create a 2 -column array of arbitrary finite length (say, 10 rows)
  2. populate it sequentially from a constant-rate datastream
  3. once its populated, update it from the same datastream ( ie replace element 0, move 1-9 down, discard old 9)
  4. (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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:34:02+00:00Added an answer on May 24, 2026 at 7:34 am

    This should work ok (nice question, by the way – fun little challenge, since there are tons of ways to do it)

    var pointSmoother = (function(){
      var pointCount     = 10, // number of points to keep
          componentCount = 2,  // number of components per point (i.e. 2 for x and y)
          points = [];
    
      function clear() {
        var i, l;
        for( i = 0, l = componentCount ; i < l ; i++ ) {
          if( typeof points[i] === 'undefined' ) {
            points.push([]);
          } else {
            points[i].splice(0, pointCount);
          }
        }
      }
    
      clear();
    
      function pushPoint( /* point components */ ) {
        var i, l;
        for( i = 0 ; i < componentCount ; i++ ) {
          points[i].unshift(arguments[i]);
          points[i] = points[i].slice(0, pointCount);
        }
      }
    
      function average() {
        var i, j, l, sum, averages = [];
        l = points[0].length;
        for( i = 0 ; i < componentCount ; i++ ) {
          sum = 0;
          for( j = 0 ; j < l ; j++ ) {
            sum += points[i][j];
          }
          averages.push(sum/l);
        }
        return averages;
      }
    
      function getPoints() {
        return points;
      }
    
      return {
          getPoints: getPoints,
          pushPoint: pushPoint,
          clear:     clear,
          average:   average
      };
    }());
    

    What it basically does is it creates an object and assigns it to pointSmoother. The object has 4 methods: pushPoint(), clear(), getPoints() and average(). 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 x and y. When you receive them, add them to the thing by using pointSmoother.pushPoint(x, y);. You can then get the “average point”, by calling pointSmoother.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/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.