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

map(x):[a,b]→[c,d]map(x)=d−cb−a(x−a)+c

Example

The interval [0,10] can be mapped to [0,100] using map.

map(x)=10xmap(0)=0map(10)=100

Derivation

The map function can be thought of as a linear function that passes through the points (a,c) and (b,d). This means that the function should map a to c and b to d.

map(a)=cmap(b)=d

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

map(x)−c=d−cb−a(x−a)map(x)=d−cb−a(x−a)+c

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