Skip to content

Instantly share code, notes, and snippets.

@joonaojapalo
Created October 30, 2020 07:39
Show Gist options
  • Save joonaojapalo/82b62b52b47dafbf19ec5c366011cd2d to your computer and use it in GitHub Desktop.
Save joonaojapalo/82b62b52b47dafbf19ec5c366011cd2d to your computer and use it in GitHub Desktop.
Gamma interpolation function
//N = Math.ceil((x1 - x0) / d + 1))
/**
* @param {Number} k Gamma.
* @param {Number} x Interpolation value [0, 1]
*/
const f = (k, x) => (Math.exp(k * Math.max(0, Math.min(1, x)))-1)/(Math.exp(k)-1)
/**
* @param {Number} k Gamma
* @param {Number} N Number of steps
* @param {Number} y0 Start value.
* @param {Number} y1 End value.
*/
const gi = (k, N, y0, y1) => {
let dy = (y1-y0)
return Array.from(Array(N)).map((_, i) => y0 + (y1 - y0) * f(k, i / (N-1)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment