Implementation of the Pyramid Algorithm Based on the bezr Approximation

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.