Remap

Moves a number from one range to another, with an optional easing curve.

Parameters

NameTypeDescription
ValueoutputFloatThe input placed in the output range.
InputFloatThe number to remap.
Input RangeVector 2The start and end of the range the input is measured in.
Output RangeVector 2The start and end of the range the result is placed in.
ModeEnumWhat happens with an input outside the input range.Choices: Unbounded, Clamp, Wrap, Mirror
EasingEnumThe curve the result follows on its way from the start of the output range to its end.Choices: Linear, Ease In Sine, Ease Out Sine, Ease In Out Sine, Ease In Quad, Ease Out Quad, Ease In Out Quad, Ease In Cubic, Ease Out Cubic, Ease In Out Cubic, Ease In Expo, Ease Out Expo, Ease In Out Expo, Ease In Back, Ease Out Back, Ease In Out Back, Ease In Elastic, Ease Out Elastic, Ease In Out Elastic, Ease In Bounce, Ease Out Bounce, Ease In Out Bounce

Remap takes a number in one range and places it at the same relative position in another range. An input halfway along the input range gives a result halfway along the output range. Either range may run downwards, so an output range from 1 to 0 flips the input. When the input range starts and ends on the same number, the result is the start of the output range.

The mode decides what happens when the input leaves the input range. Unbounded lets the result continue past the output range in step. Clamp holds it at the nearer end. Wrap starts over from the beginning, like the seconds hand of a clock. Mirror runs back and forth, so a steadily rising input gives a result that goes up, then down, then up again.

The easing bends the path between the two ends, like the easing curves in animation software. Linear is a straight line. Ease In starts slow and speeds up, Ease Out starts fast and slows down, and Ease In Out does both. The Back and Elastic curves overshoot on purpose, so their result can leave the output range for a moment. A curve only shapes the part between the two ends. Outside the input range it has no effect and the result continues in step with the input.

A typical use is turning a signal between 0 and 1 into a position between -5 and 5, or fitting a sensor value from 0 to 1023 into a range from 0 to 1.

Keywords: scale, range, map, normalize, ease, clamp, wrap, mirror, lerp, interpolate