对于均匀B样条曲线,其曲线方程的矩阵表达为:
c ( t ) = [ 1 t ⋯ t k ] M k [ P i − k P i − k + 1 ⋮ P i ] t ∈ [ 0 , 1 ] (1) c(t) = [1\ t\ \cdots\ t^k] M_k \begin{bmatrix} P_{i-k}\\ P_{i-k+1}\\ \vdots\\ P_i \end{bmatrix} \ t\in[0,1] \tag{1} c(t)=[1 t ⋯ tk]Mk⎣ ⎡Pi−kPi−k+1⋮Pi⎦ ⎤ t∈[0,1](1)
其中 t t t为参数, P i − k , P i − k + 1 , ⋯ , P i P_{i-k},P_{i-k+1},\cdots,P_i Pi−k,Pi−k+1,⋯,Pi为 k + 1 k+1 k+1个控制点,而 M k M_k Mk由下式给出:
M k = [ m 0 , 0 m 0 , 1 ⋯ m 0 , k ⋮ ⋮ ⋯ ⋮ m k , 0 m k , 1 ⋯ m k , k ] (2) M_k = \begin{bmatrix} m_{0,0} & m_{0,1} & \cdots & m_{0,k} \\ \vdots & \vdots & \cdots & \vdots\\ m_{k,0} & m_{k,1} & \cdots & m_{k,k} \end{bmatrix} \tag{2} Mk=⎣ ⎡m0,0⋮mk,0m0,1⋮mk,1⋯⋯⋯m0,k⋮mk,k⎦ ⎤(2)
而矩阵 M k M_k Mk中的每个元素 m i , j m_{i,j} mi,j可以由下式直接给出,
m i , j = 1 ( k − 1 ) ! C k k − i ∑ s = j k ( − 1 ) s − j C k + 1 s − j ( k − s ) k − i (3) m_{i,j} = \frac{1}{(k-1)!} C_{k}^{k-i} \sum_{s=j}^{k}(-1)^{s-j}C_{k+1}^{s-j}(k-s)^{k-i} \tag{3} mi,j=(k−1)!1Ckk−is=j∑k(−1)s−jCk+1s−j(k−s)k−i(3)
由上式,很容易得出,
M 1 = [ 1 0 − 1 1 ] M_1 = \begin{bmatrix} 1 & 0 \\ -1 & 1 \end{bmatrix} M1=[1−101]
M 2 = [ 1 1 0 − 2 2 0 1 − 2 1 ] M_2=\begin{bmatrix} 1 & 1 & 0\\ -2 & 2 & 0\\ 1 & -2 & 1 \end{bmatrix} M2=⎣ ⎡1−2112−2001⎦ ⎤
M 3 = 1 2 ⋅ [ 1 4 1 0 − 3 0 3 0 3 − 6 3 0 − 1 3 − 3 1 ] M_3 = \frac{1}{2} \cdot \begin{bmatrix} 1 & 4 & 1 & 0\\ -3 & 0 & 3 & 0\\ 3 & -6 & 3 & 0\\ -1 & 3 & -3 & 1 \end{bmatrix} M3=21⋅⎣ ⎡1−33−140−63133−30001⎦ ⎤
M 4 = 1 6 ⋅ [ 1 11 11 1 0 − 4 − 12 12 4 0 6 − 6 − 6 6 0 − 4 12 − 12 4 0 1 − 4 6 − 4 1 ] M_4 = \frac{1}{6} \cdot \begin{bmatrix} 1 & 11 & 11 & 1 & 0\\ -4 & -12 & 12 & 4 & 0\\ 6 & -6 & -6 & 6 & 0\\ -4 & 12 & -12 & 4 & 0\\ 1 & -4 & 6 & -4 & 1 \end{bmatrix} M4=61⋅⎣ ⎡1−46−4111−12−612−41112−6−1261464−400001⎦ ⎤
计算矩阵 M k M_k Mk的matlab程序为,
clear all
clc
close all
%%
k = input('请输入一个大于等于1的整数:');
M = zeros(k+1,k+1);
for i = 0 : k
for j = 0 : k
a = 1 / factorial(k - 1);
a = a * nchoosek(k, k - i);
b = 0;
for s = j : k
b = b + (-1)^(s - j) * nchoosek(k + 1, s - j) * (k - s)^(k - i);
end
a = a * b;
M(i+1, j+1) = a;
end
end
M %小数表示
format rat
M %分数表示
对于均匀B样条曲线,其曲线多项式表示为:
c ( t ) = w 0 P i − k + w 1 P i − k + 1 + ⋯ + w k P i (4) c(t) = w_0 P_{i-k} +w_1P_{i-k+1}+\cdots + w_kP_i \tag{4} c(t)=w0Pi−k+w1Pi−k+1+⋯+wkPi(4)
其中 t t t为参数, P i − k , P i − k + 1 , ⋯ , P i P_{i-k},P_{i-k+1},\cdots,P_i Pi−k,Pi−k+1,⋯,Pi为 k + 1 k+1 k+1个控制点,而 w 0 , w 1 , ⋯ , w k w_0,w_1,\cdots,w_k w0,w1,⋯,wk是 t t t的多项式,可以理解为控制点的权重,由下式给出,
w i = 1 ( k − 1 ) ! ∑ j = 0 k − i ( − 1 ) j C k + 1 j ( t + k − i − j ) k i = 0 , 1 , ⋯ , k (5) w_i = \frac{1}{(k-1)!} \sum_{j=0}^{k-i}(-1)^jC_{k+1}^j(t+k-i-j)^{k} \ \ i=0,1,\cdots,k \tag{5} wi=(k−1)!1j=0∑k−i(−1)jCk+1j(t+k−i−j)k i=0,1,⋯,k(5)
当 k k k取4时,有5个控制点,每个控制点的权重分别为,
w 0 = 1 6 ⋅ ∑ j = 0 4 ( − 1 ) j ⋅ C 5 j ⋅ ( t + 4 − j ) 4 w_0=\frac{1}{6}\cdot \sum_{j=0}^4(-1)^j\cdot C_5^j \cdot (t+4-j)^4 w0=61⋅j=0∑4(−1)j⋅C5j⋅(t+4−j)4
w 1 = 1 6 ⋅ ∑ j = 0 3 ( − 1 ) j ⋅ C 5 j ⋅ ( t + 3 − j ) 4 w_1 = \frac{1}{6}\cdot\sum_{j=0}^3(-1)^j\cdot C_5^j \cdot (t + 3 - j)^4 w1=61⋅j=0∑3(−1)j⋅C5j⋅(t+3−j)4
w 2 = 1 6 ⋅ ∑ j = 0 2 ( − 1 ) j ⋅ C 5 j ⋅ ( t + 2 − j ) 4 w_2 = \frac{1}{6}\cdot \sum_{j=0}^2(-1)^j\cdot C_5^j \cdot (t + 2 - j)^4 w2=61⋅j=0∑2(−1)j⋅C5j⋅(t+2−j)4
w 3 = 1 6 ⋅ ∑ j = 0 1 ( − 1 ) j ⋅ C 5 j ⋅ ( t + 1 − j ) 4 w_3 = \frac{1}{6}\cdot\sum_{j=0}^1(-1)^j\cdot C_5^j \cdot (t + 1 - j)^4 w3=61⋅j=0∑1(−1)j⋅C5j⋅(t+1−j)4
w 4 = 1 6 ⋅ ∑ j = 0 0 ( − 1 ) j ⋅ C 5 j ⋅ ( t − j ) 4 = t 4 w_4 = \frac{1}{6}\cdot\sum_{j=0}^0(-1)^j\cdot C_5^j \cdot (t - j)^4=t^4 w4=61⋅j=0∑0(−1)j⋅C5j⋅(t−j)4=t4
将 w 0 , w 1 , w 2 , w 3 , w 4 w_0,w_1,w_2,w_3,w_4 w0,w1,w2,w3,w4展开,合并同类多项式,可得,
w 0 = 1 6 ⋅ ( t 4 − 4 t 3 + 6 t 2 − 4 t + 1 ) = 1 6 ⋅ [ 1 t t 2 t 3 t 4 ] [ 1 − 4 6 − 4 1 ] w_0 = \frac{1}{6}\cdot (t^4 - 4t^3 + 6t^2 - 4t + 1)=\frac{1}{6} \cdot[1\ t \ t^2 \ t^3 \ t^4]\begin{bmatrix} 1\\ -4\\ 6\\ -4\\ 1 \end{bmatrix} w0=61⋅(t4−4t3+6t2−4t+1)=61⋅[1 t t2 t3 t4]⎣ ⎡1−46−41⎦ ⎤
w 1 = 1 6 ⋅ ( − 4 t 4 + 12 t 3 − 6 t 2 − 12 t + 11 ) = 1 6 ⋅ [ 1 t t 2 t 3 t 4 ] [ 11 − 12 − 6 12 − 4 ] w_1=\frac{1}{6} \cdot (- 4t^4 + 12t^3 - 6t^2 - 12t + 11) = \frac{1}{6} \cdot[1\ t \ t^2 \ t^3 \ t^4]\begin{bmatrix} 11\\ -12\\ -6\\ 12\\ -4 \end{bmatrix} w1=61⋅(−4t4+12t3−6t2−12t+11)=61⋅[1 t t2 t3 t4]⎣ ⎡11−12−612−4⎦ ⎤
w 2 = 1 6 ⋅ ( 6 t 4 − 12 t 3 − 6 t 2 + 12 t + 11 ) = 1 6 ⋅ [ 1 t t 2 t 3 t 4 ] [ 11 12 − 6 − 12 6 ] w_2=\frac{1}{6} \cdot (6t^4 - 12t^3 - 6t^2 + 12t + 11) = \frac{1}{6} \cdot[1\ t \ t^2 \ t^3 \ t^4]\begin{bmatrix} 11\\ 12\\ -6\\ -12\\ 6 \end{bmatrix} w2=61⋅(6t4−12t3−6t2+12t+11)=61⋅[1 t t2 t3 t4]⎣ ⎡1112−6−126⎦ ⎤
w 3 = 1 6 ⋅ ( − 4 t 4 + 4 t 3 + 6 t 2 + 4 t + 1 ) = 1 6 ⋅ [ 1 t t 2 t 3 t 4 ] [ 1 4 6 4 − 4 ] w_3=\frac{1}{6} \cdot (- 4t^4 + 4t^3 + 6t^2 + 4t + 1) = \frac{1}{6} \cdot[1\ t \ t^2 \ t^3 \ t^4]\begin{bmatrix} 1\\ 4\\ 6\\ 4\\ -4 \end{bmatrix} w3=61⋅(−4t4+4t3+6t2+4t+1)=61⋅[1 t t2 t3 t4]⎣ ⎡1464−4⎦ ⎤
w 4 = 1 6 ⋅ t 4 = 1 6 ⋅ [ 1 t t 2 t 3 t 4 ] [ 0 0 0 0 1 ] w_4=\frac{1}{6} \cdot t^4=\frac{1}{6} \cdot[1\ t \ t^2 \ t^3 \ t^4]\begin{bmatrix} 0\\ 0\\ 0\\ 0\\ 1 \end{bmatrix} w4=61⋅t4=61⋅[1 t t2 t3 t4]⎣ ⎡00001⎦ ⎤
将上述 w 0 , w 1 , w 2 , w 3 , w 4 w_0,w_1,w_2,w_3,w_4 w0,w1,w2,w3,w4代入公式(4),整理可得B样条曲线的表达式为,
c ( t ) = [ 1 t t 2 t 3 t 4 ] ⋅ 1 6 ⋅ [ 1 11 11 1 0 − 4 − 12 12 4 0 6 − 6 − 6 6 0 − 4 12 − 12 4 0 1 − 4 6 − 4 1 ] ⋅ [ P i − k P i − k + 1 ⋮ P i ] c(t) = [1\ t\ t^2\ t^3\ t^4]\cdot \frac{1}{6}\cdot \begin{bmatrix} 1 & 11 & 11& 1& 0\\ -4 & -12 & 12& 4& 0\\ 6 & -6 & -6& 6& 0\\ -4 & 12 & -12& 4& 0\\ 1 & -4 & 6 & -4 & 1 \end{bmatrix} \cdot \begin{bmatrix} P_{i-k}\\ P_{i-k+1}\\ \vdots\\ P_{i} \end{bmatrix} c(t)=[1 t t2 t3 t4]⋅61⋅⎣ ⎡1−46−4111−12−612−41112−6−1261464−400001⎦ ⎤⋅⎣ ⎡Pi−kPi−k+1⋮Pi⎦ ⎤
该表达式与第1节矩阵表达中公式(1)取 k = 4 k=4 k=4时一致。
[1] http://t.csdn.cn/WJQkU