Personal Logo

Interval Map

January 21, 2018

Many programs require a mathematical function capable of mapping an interval of numbers linearly onto another interval. A map\mathit{map} function maps one interval linearly onto another.

map(x):[a,b][c,d]map(x)=dcba(xa)+c\mathit{map}(x):[a,b]\to[c,d] \\ \mathit{map}(x) = \frac{d - c}{b - a}(x - a) + c

Example

The interval [0,10][0, 10] can be mapped to [0,100][0, 100] using map\mathit{map}.

map(x)=10xmap(0)=0map(10)=100\begin{aligned} \mathit{map}(x) & = 10x \\ \\ \mathit{map}(0) & = 0 \\ \mathit{map}(10) & = 100 \end{aligned}

Derivation

The map\mathit{map} function can be thought of as a linear function that passes through the points (a,c)(a,c) and (b,d)(b,d). This means that the function should map aa to cc and bb to dd.

map(a)=cmap(b)=d\begin{aligned} \mathit{map}(a) & = c \\ \mathit{map}(b) & = d \end{aligned}

With two points the slope can be obtained and the function can be written and simplified.

map(x)c=dcba(xa)map(x)=dcba(xa)+c\begin{aligned} \mathit{map}(x) - c & = \frac{d - c}{b - a}(x - a) \\ \mathit{map}(x) & = \frac{d - c}{b - a}(x - a) + c \end{aligned}

The function can be verified to ensure a correct mapping of aa to cc.

map(a)=dcba(aa)+cmap(a)=c\begin{aligned} \mathit{map}(a) &= \frac{d - c}{b - a}(a - a) + c \\ \mathit{map}(a) &= c \end{aligned}

The same can be done to ensure bb maps to dd.

map(b)=dcba(ba)+cmap(b)=dc+cmap(b)=d\begin{aligned} \mathit{map}(b) &= \frac{d - c}{b - a}(b - a) + c \\ \mathit{map}(b) &= d - c + c \\ \mathit{map}(b) &= d \end{aligned}

Portfolio

Blog

Twitter

GitHub