I am trying to write an algorithm that interpolates between 3 values.
The interpolation will be over the interval [0,1].
What I would like to do is: (Hopefully this makes sense)
- at x = 0, y = [start value]
- at x = [peak location], y = [middle value]
- at x = 1, y = [end value].
This is easy to do if the [peak location] is 0.5 and the [start value] = [end value] since I can just fit a parabola. But I have been trying to do something along the lines of: [start value] = 0.3, [middle value] = 0.9, [peak location] = 0.2, and [end value] = 0.1
I am trying to do this in a non piecewise way. I have looked into Beziér Curves, but I cannot use x as an input.
Apologies for this may not being clear, but I'm hoping someone can point me in the right direction.
EDIT: one more thing I just noticed: It appears that the maximum of the Bezier Curve does not occur at 0.2 (my desired peak location). So I don't think Bezier curves are what my solution is.
EDIT2: I was able to get much closer with Catcall-Rom splines:




Let's use the notation from Fang's answer. Given $y_0$, $y_m$, $y_1$, and $m$, we want to find a function $f$ such that $f(0) = y_0$, $f(m) = y_m$, and $f(1) = y_1$.
It sounds like you already know how to find a quadratic polynomial $g$ and a value $x_m$ such that $g(0) = y_0$, $g(x_m) = y_m$, $g(1) = y_1$, and $g'(x_m) = 0$.
This parabola has all the right properties, except that it doesn't achieve it's maximum at the right $x$-value: we wanted the maximum to occur at $x=m$, and it's occurring at $x=x_m$ instead.
So, now the idea is that we reparameterize by distorting the $x$-axis. We construct a monotone function $\alpha$ such that $\alpha(0) = 0$, $\alpha(m) = x_m$, and $\alpha(1) = 1$. Then, if we define $f(x) = g(\alpha(x))$, the function $f$ will have the desired properties.
The remaining question is how to construct the function $\alpha$. In most situations, a quadratic polynomial will work, but there is some danger that it won't be monotone in extreme cases. A better choice would probably be a Moebius transformation of the form $\alpha(x) = x/(cx+d)$. You can adjust $c$ and $d$ to get the right properties. The final function $f$ will then be a rational quadratic (the quotient of two quadratic polynomials). Actually, you could probably just construct this rational quadratic directly, without all the reparameterization fuss outlined above.