remap - nodef/extra-math GitHub Wiki

Re-map a number from one range to another.

Similar: constrain, normalize, remap, lerp.

function remap(x, r, R, t, T)
// x: a number
// r: lower bound of current range
// R: upper bound of current range
// t: lower bound of target range
// T: upper bound of target range
const xmath = require('extra-math');


xmath.remap(25, 0, 100, 0, 1366);
// → 341.5

xmath.remap(110, 0, 100, -20, -10);
// → -9

References