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

Apply linear interpolation when incrementing the grid? #8

Closed
mbostock opened this issue Apr 11, 2017 · 1 comment · Fixed by #46
Closed

Apply linear interpolation when incrementing the grid? #8

mbostock opened this issue Apr 11, 2017 · 1 comment · Fixed by #46

Comments

@mbostock
Copy link
Member

Currently we round data points to the nearest grid point before blurring. It would probably be better to apply linear interpolation to a 2×2 grid to the nearest grid points to the data point instead, something like this:

data.forEach(function(d, i, data) {
  var xi = (x(d, i, data) + o) * Math.pow(2, -k),
      yi = (y(d, i, data) + o) * Math.pow(2, -k);
  if (xi >= 0 && xi < n - 1 && yi >= 0 && yi < m - 1) {
    var x0 = Math.floor(xi),
        y0 = Math.floor(yi),
        xt = xi - x0,
        yt = yi - y0;
    values0[x0 + y0 * n] += (1 - xt) * (1 - yt);
    values0[x0 + 1 + y0 * n] += xt * (1 - yt);
    values0[x0 + 1 + (y0 + 1) * n] += xt * yt;
    values0[x0 + (y0 + 1) * n] += (1 - xt) * yt;
  }
});
@mbostock mbostock changed the title Apply linear interpolation when initializing the grid? Apply linear interpolation when incrementing the grid? Apr 11, 2017
@mbostock
Copy link
Member Author

Apparently this is called linear binning:

Linear binning is a slight tweak to regular binning where if the grid points x and z surround the data point y, then (z−y)/(z−x) mass is distributed to the grid point at x, and (y − x)/(z − x) to the point at z.

Fil added a commit that referenced this issue Jun 2, 2020
@Fil Fil mentioned this issue Jun 2, 2020
mbostock pushed a commit that referenced this issue Jun 5, 2021
mbostock added a commit that referenced this issue Jun 5, 2021
* apply linear binning
closes #8

* a test for contourDensity & linear binning

* style

Co-authored-by: Mike Bostock <mbostock@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant