A lot of the examples of cubic bezier fitting code that I can find online are based on that "Algorithm for Automatically Fitting Digitized Curves" Graphics Gems article by Philip J. Schneider.
The problem is that the algorithm only fits "aligned" knots, knots where the tangents have geometric continuity.
This has three input points, the blue curve was fit to them (it's from this demo by the way).
Is there an algorithm that can fit a piecewise cubic bezier curve that can have sharp ("cusp") type knots? On some cases (like those 3 input points) it would make the curve fit the polyline formed by the 3 points perfectly.
Something like this (a mockup):