B样条曲线

  1. 零次 B 样条

F i , 0 ( t ) = { 1 t i ≤ t < t i + 1 0 o t h e r s \bm{F}_{i,0}(t) = \begin{cases} 1 & t_i \leq t Fi0(t)={10tit<ti+1others
B样条曲线_第1张图片
2. 一次 B 样条,
F i , 1 ( t ) = t − t i t i + 1 − t i F i , 0 ( t ) + t i + 2 − t t i + 2 − t i + 1 F i + 1 , 0 ( t ) \bm{F}_{i, 1}(t) = \frac{t - t_i}{t_{i+1} - t_i} \bm{F}_{i, 0}(t) + \frac{t_{i+2} - t}{t_{i+2} - t_{i+1}} \bm{F}_{i+1, 0}(t) Fi,1(t)=ti+1tittiFi,0(t)+ti+2ti+1ti+2tFi+1,0(t)

通过

F i , 0 ( t ) = { 1 t i ≤ t < t i + 1 0 o t h e r s F i + 1 , 0 ( t ) = { 1 t i + 1 ≤ t < t i + 2 0 o t h e r s \bm{F}_{i,0}(t) = \begin{cases} 1 & t_i \leq t< t_{i+1} \\ 0 & others \end{cases} \qquad \bm{F}_{i+1, 0}(t) = \begin{cases} 1 & t_{i+1} \leq t Fi,0(t)={10tit<ti+1othersFi+1,0(t)={10ti+1t<ti+2others

可以得到

F i , 1 ( t ) = { t − t i t i + 1 − t i t − i ≤ t < t i = 1 t i + 2 − t t i + 2 − t i + 1 t i + 1 ≤ t < t i + 2 0 o t h e r s \bm{F}_{i, 1}(t) = \begin{cases} \frac{t - t_i}{t_{i+1} - t_i} & t-i \leq t < t_{i=1}\\ \\ \frac{t_{i+2} - t}{t_{i+2} - t_{i+1}} & t_{i+1} \leq t Fi,1(t)= ti+1tittiti+2ti+1ti+2t0tit<ti=1ti+1t<ti+2others
B样条曲线_第2张图片
3. 二次 B 样条

F i , 2 ( t ) = t − t i t i + 2 − t i F i , 1 ( t ) + t i + 3 − t t i + 3 − t i + 1 F i + 1 , 1 ( t ) \bm{F}_{i, 2}(t) = \frac{t - t_i}{t_{i+2} - t_i} \bm{F}_{i, 1}(t) + \frac{t_{i+3} - t}{t_{i+3} - t_{i+1}} \bm{F}_{i+1, 1}(t) Fi,2(t)=ti+2tittiFi,1(t)+ti+3ti+1ti+3tFi+1,1(t)

F i , 1 ( t ) = { t − t i t i + 1 − t i t i ≤ t < t i + 1 t i + 2 − t t i + 2 − t i + 1 t i + 1 ≤ t < t i + 2 0 o t h e r s F i + 1 , 1 ( t ) = { t − t i + 1 t i + 2 − t i + 1 t i + 1 ≤ t < t i + 2 t i + 3 − t t i + 3 − t i + 2 t i + 2 ≤ t < t i + 3 0 o t h e r s \bm{F}_{i, 1}(t) = \begin{cases} \frac{t - t_i}{t_{i+1} - t_i} & t_i \leq t < t_{i+1}\\ \\ \frac{t_{i+2} - t}{t_{i+2} - t_{i+1}} & t_{i+1} \leq t Fi,1(t)= ti+1tittiti+2ti+1ti+2t0tit<ti+1ti+1t<ti+2othersFi+1,1(t)= ti+2ti+1tti+1ti+3ti+2ti+3t0ti+1t<ti+2ti+2t<ti+3others

得到

F i , 1 ( t ) = { t − t i t i + 2 − t i t − t i t i + 1 − t i t i ≤ t < t i + 1 t − t i t i + 2 − t i t i + 2 − t t i + 2 − t i + 1 + t i + 3 − t i + 1 t i + 3 − t i + 1 t − t i + 1 t i + 2 − t i + 1 t i + 1 ≤ t < t i + 2 ( t i = 3 − t ) 2 ( t i = 3 − t i + 1 ) ( t i + 3 − t i + 2 ) t i + 2 ≤ t < t i + 3 0 o t h e r s \bm{F}_{i, 1}(t) = \begin{cases} \frac{t - t_i}{t_{i+2} - t_i} \frac{t-t_i}{t_{i+1}-t_i} & t_i \leq t < t_{i+1} \\ \\ \frac{t - t_i}{t_{i+2} - t_i} \frac{t_{i+2}-t}{t_{i+2}-t_{i+1}} + \frac{t_{i+3} - t_{i+1}}{t_{i+3} - t_{i+1}} \frac{t-t_{i+1}}{t_{i+2}-t_{i+1}} & t_{i+1} \leq t < t_{i+2} & \\ \\ \frac{(t_{i=3} - t)^2}{(t_{i=3} - t_{i+1})(t_{i+3} - t_{i+2})}& t_{i+2} \leq t < t_{i+3} & \\ \\ 0 & others \end{cases} Fi,1(t)= ti+2tittiti+1tittiti+2tittiti+2ti+1ti+2t+ti+3ti+1ti+3ti+1ti+2ti+1tti+1(ti=3ti+1)(ti+3ti+2)(ti=3t)20tit<ti+1ti+1t<ti+2ti+2t<ti+3others

B样条曲线_第3张图片
根据参数 t t t 的值和次数 k k k 与节点矢量双精度数组 K n o t Knot Knot 计算第 i i i k k k 次的 B 样条基函数的 F i , k ( t ) F_{i, k}(t) Fi,k(t)

分析

F i , k ( t ) = t − t i t i + k − t i F i , k − 1 ( t ) + t i + k + 1 − t t i + k + 1 − t i + 1 F i + 1 , k − 1 ( t ) F_{i, k}(t) = \frac{t -t_i}{t_{i+k} - t_i} F_{i, k-1}(t) + \frac{t_{i+k+1} - t }{t_{i+k+1} - t_{i+1}} F_{i+1, k-1}(t) Fi,k(t)=ti+ktittiFi,k1(t)+ti+k+1ti+1ti+k+1tFi+1,k1(t)

n u m b e r a t o r 1 = t − t i n u m b e r a t o r 2 = t i + k + 1 − t d e n o m i n a t o r 1 = t i + k − t i d e n o m i n a t o r 2 = t i + k + 1 − t i + 1 c o f f i c i e n t 1 = n u m b e r a t o r 1 d e n o m i n a t o r 1 c o f f i c i e n t 1 = n u m b e r a t o r 2 d e n o m i n a t o r 2 v a l u e 1 = c o f f i c i e n t 1 × F i , k − 1 ( t ) v a l u e 2 = c o f f i c i e n t 2 × F i + 1 , k − 1 ( t ) numberator_1 = t - t_i \\ numberator_2 = t_{i+k+1} - t \\ denominator_1 = t_{i+k} - t_i \\ denominator_2 = t_{i+k+1} - t_{i+1} \\ cofficient_1 = \frac{numberator_1 }{denominator_1 }\\ cofficient_1 = \frac{numberator_2 }{denominator_2 }\\ value_1 = cofficient_1 \times F_{i, k-1}(t)\\ value_2 = cofficient_2 \times F_{i+1, k-1}(t) numberator1=ttinumberator2=ti+k+1tdenominator1=ti+ktidenominator2=ti+k+1ti+1cofficient1=denominator1numberator1cofficient1=denominator2numberator2value1=cofficient1×Fi,k1(t)value2=cofficient2×Fi+1,k1(t)

B样条曲线_第4张图片


double BasisFunctionValue(double t, int i, int k)
{
	double val1, val2, val;
	if (k == 0)
	{
		if ((t >= knot[i]) && t < knot[i + 1])
		{
			return 1.0;
		}
		else
		{	// 其它
			return 0.0;
		}
	}
	if (k > 0) {
		if (t < knot[i] || t > knot[i + k + 1]) {
			return 0.0;		// 其它
		}
		else
		{
			double coffcient1, coffcient2;	// 凸组合系数1 凸组合系数 2
			double denominator = 0.0;		// 分母
			denominator = knot[i + k] - knot[i];	
			if (denominator == 0.0)
			{
				// 约定 0/0 = 0
				coffcient1 = 0.0;
			}
			else
			{
				coffcient1 = (t - knot[i]) / denominator;	// 计算的第一项
			}
			denominator = knot[i + k + 1] - knot[i + 1];	// 递推公式第二项分母
			if (denominator == 0.0)
			{
				// 约定 0/0 = 0
				coffcient2 = 0.0;
			}
			else
			{
				coffcient2 = (knot[i + k + 1] - t) / denominator;	// 递推公式第二项
			}
			val1 = coffcient1 * BasisFunctionValue(t, i, k - 1);	// 递推公式第一项的只
			val2 = coffcient2 * BasisFunctionValue(t, i+1, k - 1);	// 递推公式第二项的只
			val = val1 + val2;	// 基函数的值
		}
	}

	return val;
}

你可能感兴趣的:(图像图形处理,算法)