[Math] Create a formula that creates a curve between two points

curves

We have two points, $A$ and $B$. The difference in $x$ is 1 unit, and the difference in $y$ is arbitrary. For each point we also know the gradient. First, I want to draw a smooth line that connects both points and smoothly transitions between gradients. Then, I want a function that returns a $y$-value for any value of $x$ between $A$ and $B$, where $0 < x < 1$.

Best Answer

Assume that our conditions are: $$ f(0) = 0,~~ f(1) = b,~~ f'(0) = p,~~ f'(1) = q $$ and that we use a cubic polynomial $f(x) = a_3x^3 + a_2x^2 + a_1x + a_0$. Solving this system of equations yields: $$ f(x) = (p + q - 2b)x^3 + (3b - 2p - q)x^2 + px $$


For example, if our first point is $(0, 0)$ with a gradient of $p = 3$ and our second point is $(1, 4)$ with a gradient of $q = -2$, then our curve is: $$ f(x) = -7x^3 + 8x^2 + 3x $$ Indeed, the plot looks like:

enter image description here

Related Question