Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize x and y axis accuracy #295

Open
edinaldofcs opened this issue Mar 15, 2023 · 1 comment
Open

optimize x and y axis accuracy #295

edinaldofcs opened this issue Mar 15, 2023 · 1 comment

Comments

@edinaldofcs
Copy link

edinaldofcs commented Mar 15, 2023

Working on a personal project, I faced the same problem I encountered with this project... accuracy. One of the ways I found to minimize the variation in the x and y axes was to create an object, which captures the positions of the two axes and a function to return the simple arithmetic average of the last n samples.

var average = { x1: [], y1: [] };

function getAverage(x, y, iterations) {
   if (average.x1.length == iterations) {
     average.x1.shift();
     average.y1.shift();
   }

   average.x1.push(x);
   average.y1.push(y);

   let x1 = average.x1.reduce((acc, val) => acc + val, 0);
   let y1 = average.y1.reduce((acc, val) => acc + val, 0);

   x1 = x1 / average.x1.length;
   y1 = y1 / average.y1.length;

   return [`${x1}px`, `${y1}px`];
}

In this way, it is possible to add the axes more accurately

let [x01,y01] = getAverage(i.x, i.y,10)
...
(nB.style.transform = "translate3d(" + x01 + "," + y01 + ",0)");
@jeffhuang
Copy link
Contributor

Cool, you may check out the Kalman filter feature as well, in the Calibration Demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants