Skip to content

Instantly share code, notes, and snippets.

@rosszurowski
Created December 10, 2014 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosszurowski/e2193733292846eb0dc5 to your computer and use it in GitHub Desktop.
Save rosszurowski/e2193733292846eb0dc5 to your computer and use it in GitHub Desktop.
An n-th degree polynomial interpolator. Used as an alternative for common `lerp` functions
/**
* N-th degree polynomial interpolation
* @param {Number} degree
* @param {Number} min
* @param {Number} max
* @param {Number} amount
* @returns {Number}
*/
function nerp(degree, min, max, amount) {
return min + Math.pow(amount, degree) * (max - min);
}
@rosszurowski
Copy link
Author

You can use it as follows:

var QUADRATIC = 2;
var CUBIC = 3;

nerp(QUADRATIC, 0, 1, 0.5) // returns 0.25
nerp(CUBIC, 0, 1, 0.5) // returns 0.125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment