怎么样实现B-样条基函数的金字塔算法?
/*@remark 根据计算B-样条基函数,金字塔算法通式
@para num 多项式的阶数
@para t 参数
@para SectNum B-样条分段的段号
@para PolynomialsValues 生成的多项式系数
@return 生成正确返回true,否则返回flase
*/
bool BSplineBase ( int stage, double t, int SectNum, std::deque<double>& PolynomialsValues )
{
double parentL, parentR, delta, cPL, cPR, value;
double tCurLeft, tCurRight;
int i, j, oldLength;
// 参数检查
delta = 1.0/(2*stage-1);
tCurLeft = (3+SectNum) * delta;
tCurRight = tCurLeft - delta;
PolynomialsValues.push_back ( 1 );
// 开始计算
for ( i=0; i<stage; ++i ){
oldLength = PolynomialsValues.size();
if ( oldLength == 1 )
parentL = parentR = PolynomialsValues[0];
else{
parentL = PolynomialsValues[0];
parentR = PolynomialsValues[1];
}
// 左边缘单独处理
cPL = tCurLeft - tCurRight;
value = Normalize( parentL * (tCurLeft-t) / cPL, 4 );
PolynomialsValues.push_back ( value );
// 处理中间部分
tCurLeft += delta;
for ( j=0; j<oldLength-1; ++j ){
parentL = PolynomialsValues[j];
parentR = PolynomialsValues[j+1];
cPL = tCurLeft - delta - tCurRight;
cPR = tCurLeft - tCurRight - delta;
value = ((t-tCurRight)*parentL)/cPL + ((tCurLeft-t)*parentR)/cPR;
PolynomialsValues.push_back ( Normalize( value, 4 ) );
tCurLeft += delta;
tCurRight += delta;
}
// 右边缘单独处理
tCurLeft -= delta;
cPR = tCurLeft - tCurRight;
value = Normalize( parentR * (t - tCurRight) / cPR, 4 );
PolynomialsValues.push_back ( value );
// 删除上一行的内容
PolynomialsValues.erase ( PolynomialsValues.begin(), PolynomialsValues.begin()+oldLength );
// 改变左右系数
tCurLeft = (3+SectNum) * delta;
tCurRight = tCurLeft - (i+2)*delta;
}
return true;
}
三次B样条:
本文地址:http://www.45fan.com/a/question/68170.html