In the last image, only three points are displayed, which are enough to determine a quadratic polynomial, not a cubic one. For cubic interpolation, you will need four points. The cubic polynomial can be set in different ways; here are two.
The easiest way is to simply allow the (single) polynomial to go through all four points.
Another way is to use tangents. Again, we need four points. Let the left two points define the slope. Ask the polynomial to go through the second point (in general, it does not go through the first point) and corresponds to the calculated slope at that point. And the same on the right side for the fourth and third points.
By the way, any higher-order polynomial is probably a bad idea, because they tend to become very unstable when there is even a small amount of input noise.
If you give more detailed information about your problem area, I can give a more specific answer. For example, where does your data come from, what curve can you usually expect, and can you go back and try more if necessary? I can also provide equations and pseudo-code if necessary.
Update: stupid, I left the sentence, citing two paths without typing them. Allocated them now.
source share