I'm making a computer program and I ran into a problem of mapping/interpolating number from one range into another. I've formalized it as a mathematics problem. Look over it and I'd appreciate your insights.
There is a function $f:[a,b]\to[10,100]$ for fixed $(a, b, p)$ such that:
- $f(a)=10$
- $f(p)=45$ for some arbitary $p$
- $f(b)=100$
How to find the value of $f(p_o)$ where $ a\leq p_o \leq b$
Few Notes:
- The closer $p$ is to $a$, the more drastically the value of $f(p_o)$ should change if $ a \leq p_o \leq p$. Similarly, the closer $p$ is to $b$, the more drastically the value of $f(p_o)$ should change if $ p \leq p_o \leq b$.
Thank you!
How about a straight line joining $(a,10)$ to $(p,45)$ and then a straight line from $(p,45)$ to $(b,100)$? That's about as linear as you can get. For exactly one value of $p$ it will be a single line.
As an alternative, you can fit a unique quadratic curve $rx^2 + sx + t$ through those three points. Finding the coefficients in terms of $a$, $b$ and $p$ is three linear equations in three unknowns. Draw a few to see if they look right for your application.