npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

2d-bicubic-interpolate

v1.0.7

Published

Interpolate data set representing function of two variables z = f(x,y) with bicubic spline

Downloads

29

Readme

2d-bicubic-interpolate

Ver. 1.0.7

This version includes contribution of Akshat Khare. According to Akshat pull request:

Previously the code failed for matrices with repeated value of z for
different record, which is undesired, so changed the code to accomodate
that issue.

Description

This package is a simple implementation of a cubic-spline by morganherlocker for two-directional interpolation (2-dimensional arrays).
Assumed purpose of this package is to interpolate discrete function of two variables (e.g., for a surface plot).

z = f(x,y)

Following package was developed for another project that utilizes it for surface plot interpolation.

Dependencies

Package runs thanks to two dependencies. Firstly, of course cubic-spline by morganherlocker must be included. Another little package needed to run 2d-bicubic-spline is split-array by Arthur Verschaeve. Development dependencies fot testing include Mocha & Chai.

Install

To install package:

npm install --save 2d-bicubic-interpolate

Include in your project

import interpolateArray from '2d-bicubic-interpolate';

API

interpolateArray(data, n);

Function takes two parameters: data, including data set to interpolate, and parameter n that describes 'strength' of interpolation. Function returns interpolated data set.

data

Data set is expected to be representation of a discrete function of two variables. Data set is expected to be an array of objects, where every each object presents coordinates for each point of function. Coordinates values are expected to be real numbers.

const data = [
    {
        x: 0, 
        y: 0, 
        z: 2
    },
    {
        x: 1, 
        y: 0, 
        z: 0.3
    },
    {
        x: 0, 
        y: 1, 
        z: 1.4
    },
    {
        x: 1, 
        y: 1, 
        z: 2.5
    }
]

n parameter - the interpolation factor

Interpolation factor, the n parameter need to be a positive integer or 0. This number describes how many new points are going to be put between primary points. E.g., for n = 4, between every 2 primary points from input data, four new points are going to be calculated and inserted between. For n = 0, no interpolation is applied and output is the same as input.

Output

Function interpolateArray returns new data set, which has the same structure as an input. Length of new data array is described as:

L1 = L0 + (L0 - 1) * n

Where:
L1 - length of output array
L0 - length of input array
n - interpolation factor

Examples

Example 1

import interpolateArray from '2d-bicubic-interpolate';
const data = [
    {
        x: 0,
        y: 0,
        z: 0.3
    },
    {
        x: 1,
        y: 0,
        z: 1.2
    },
    {
        x: 0,
        y: 1,
        z: 1.4
    },
    {
        x: 1,
        y: 1,
        z: 2.2
    }
];

console.log(interpolateArray(data, 1));

/*
console: 

(9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0:{x: 0, y: 0, z: 0.3}
1:{x: 0, y: 0.5, z: 0.85}
2:{x: 0, y: 1, z: 1.4}
3:{x: 0.5, y: 0, z: 0.75}
4:{x: 0.5, y: 0.5, z: 1.275}
5:{x: 0.5, y: 1, z: 1.8}
6:{x: 1, y: 0, z: 1.2}
7:{x: 1, y: 0.5, z: 1.7}
8:{x: 1, y: 1, z: 2.2}
*/

Example 2

Working principle of algorithm is presented by a 3D surface chart (vis.js), representing some discrete function of two-variables.
Data before interpolation:

InterpolateArray(data, 0);    

Raw data

Data interpolated with different interpolation factors: Data interpolated with different interpolation factors:

InterpolateArray(data, 1);  

N=1

InterpolateArray(data, 10);  

N=10