In fact, there is a small difference between berstein and Laplace. When the use of Laplace for linear interpolation, the interpolation parameters used each time are different, while berstein is just the opposite, berstein does not require the curve to pass through the control point, so the berstein polynomial is an approximation method rather than an interpolation method, so the implementation is similar to that of the Laplace, but it is simpler :)
// Description: calculates the berstein base function based on the order, and the pyramid algorithm is generic.
// Parameter: Order of the num Polynomial
// T parameter
// Polynomial coefficient generated by polynomialsvalues
// Return: True is returned if generation is correct; otherwise, flase is returned.
Bool bernsteinbase (INT num, double T, STD: deque <double> & polynomialsvalues)
{
Double parentl, parentr, Delta, value;
Double tcurleft = 1, tcurright = 0;
Int I, j, oldlength;
// Parameter check
Delta = 1.0/(num-1 );
Polynomialsvalues. push_back (1 );
// Start Calculation
For (I = 0; I <num-1; ++ I ){
Oldlength = polynomialsvalues. Size ();
If (oldlength = 1)
Parentl = parentr = polynomialsvalues [0];
Else {
Parentl = polynomialsvalues [0];
Parentr = polynomialsvalues [1];
}
// The left edge is processed separately.
Value = normalize (parentl * (tcurleft-T), 4 );
Polynomialsvalues. push_back (value );
// Process the intermediate part
For (j = 0; j <oldLength-1; ++ J ){
Parentl = polynomialsvalues [J];
Parentr = polynomialsvalues [J + 1];
Value = (t-tcurright) * parentl) + (tcurleft-t) * parentr );
Polynomialsvalues. push_back (normalize (value, 4 ));
}
// Process the right edge separately
Value = normalize (parentr * (t-tcurright), 4 );
Polynomialsvalues. push_back (value );
// Delete the content of the previous row
Polynomialsvalues. Erase (polynomialsvalues. Begin (), polynomialsvalues. Begin () + oldlength );
}
Return true;
}
Picture