Given n points:
p0, p1, p2, ..., pn;
How can I get the point c1, c2 so that the cubic bezier curve defined by
p0, c1, c2, pn
closest to the g
Judging by your question, I am assuming that you just wish to optimise the curve fit over the 2 'inner' control points of the cubic bezier. This is not an easy problem to solve as the bezier curve is described parametrically. The most obvious solution would be to use least-squares orthogonal distance regression but this is difficult as you will need to generate footpoint parameters onto the Bezier curve for each point you wish to fit. If this problem requires a specific anayltic solution and you have some mathematical education I would recommend reading "The NURBS Book" by Peigl and Tiller and becoming familiar with approximation theory and optimisation techniques. If not, I would go for a more heuristic type of approach as this type of problem is unlikely to be solved with a simple answer here.