# B样条

De Boor算法是一个数值上稳定的计算B样条的方法。

## 定义

${\displaystyle t_{0}

${\displaystyle \mathbf {S} :[0,1]\to \mathbb {R} ^{2}}$

${\displaystyle \mathbf {S} (t)=\sum _{i=0}^{m}\mathbf {P} _{i}b_{i,n}(t){\mbox{ , }}t\in [0,1]}$.

Pi称为控制点de Boor点. m+1个n次B样条基可以用Cox-de Boor递归公式 定义

${\displaystyle b_{j,0}(t):=\left\{{\begin{matrix}1&\mathrm {} \quad t_{j}
${\displaystyle b_{j,n}(t):={\frac {t-t_{j}}{t_{j+n}-t_{j}}}b_{j,n-1}(t)+{\frac {t_{j+n+1}-t}{t_{j+n+1}-t_{j+1}}}b_{j+1,n-1}(t).}$

### 均匀B样条曲线

${\displaystyle b_{j,n}(t):=b_{n}(t+n-j)\qquad {\mbox{ , }}j=-1,\ldots m+1}$

${\displaystyle b_{n}(t):=(m+1)\sum _{i=0}^{m+1}\omega _{i}(t_{i}-t)_{+}^{m}\qquad {\mbox{ , }}t\in [0,1]}$

${\displaystyle \omega _{i}:=\prod _{j=0,i\neq j}^{m+1}{\frac {1}{t_{i}-t_{k}}}}$

${\displaystyle (t_{i}-t)_{+}}$

## 注解

n次B样条的一个基

${\displaystyle b_{i,n}(t)}$

${\displaystyle b_{i,n}(t)=\left\{{\begin{matrix}>0&\mathrm {} \quad t_{i}\leq t

## 例子

### 常数B样条

${\displaystyle b_{j,0}(t)=1_{[t_{j},t_{j+1})}=\left\{{\begin{matrix}1&\mathrm {} \quad t_{j}\leq t

### 线性B样条

${\displaystyle b_{j,1}(t)=\left\{{\begin{matrix}{\frac {t-t_{j}}{t_{j+1}-t_{j}}}&\mathrm {if} \quad t_{j}\leq t

### 三次B样条

${\displaystyle S_{i}(t)=\sum _{k=0}^{3}\mathbf {P} _{i-3+k}b_{i-3+k,3}(t)\qquad {\mbox{ , }}t\in [0,1]}$

${\displaystyle S(t)=\sum _{i=0}^{m}\mathbf {P} _{i}b_{i,}(t)}$

## B樣條的程式指令

### Matlab

In Matlab，the command“spline” can be used for spline interpolation.

(Note： In the command, the cubic B-spline is used)

Cubic B-Spline Interpolation by Matlab

Generating a sine-like spline curve and samples it over a finer mesh:

x = 0:1:10; % original sampling points

y = sin(x);

xx = 0:0.1:10; % new sampling points

yy = spline(x,y,xx);

plot(x,y,'o',xx,yy)

### Python

• pip install numpy
• pip install scipy
• pip install matplotlib

Cubic B-Spline Interpolation by Python

from scipy.interpolate import interp1d

import matplotlib.pyplot as plt

import numpy as np

x = np.arange(0, 11) # original sample points, [0, 1, 2, …, 9, 10]

y = np.sin(x)

f = interp1d(x, y, kind=' cubic ') ) # Cubic means the cubic B-spline.

x_new = np.arange(0, 10.1, 0.1) # new sample points, [0, 0.1, 0.2, ….., 9.9, 10]

y_new = f(x_new)

plt.plot(x,y,'o',x_new, y_new)

plt.show()

## 参考

1. ^ Les Piegl and Wayne Tiller: The NURBS Book, Springer-Verlag 1995-1997 (2nd ed).

## 參考文獻

• Jian-Jiun Ding, “Time Frequency Analysis and Wavelet Transforms ”, NTU, 2021.