Skip to content
Subhajit Sahu edited this page Aug 8, 2022 · 2 revisions

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

Clone this wiki locally