本文探討了三種不同的曲線插值技術,分別是 Hermite Curves、Bezier Curves 和 Cubic B-spline Curves,它們都可以使用控制點來產生出曲線,但本文突出了 Cubic B-spline Curves 的優點,它可以讓兩個區段在接點處,一階微分的值是相同的,甚至可以滿足接點處的二階微分也相同,為了更加平滑的曲線。
Hermite curves 是另一種使用 control points 產生出 curve 的方式,特別的是,只需透過頭和尾兩個點的位置 及一階微分資訊 來求得
Hermite curves p ( u ) = c 0 + c 1 u + c 2 u 2 + c 3 u 3 p ′ ( u ) = c 1 + 2 u c 2 + 3 u 2 c 3 \begin{aligned} &\mathbf{p}(u)=c_{0}+c_{1} u+c_{2} u^{2}+c_{3} u^{3}\\ &\mathbf{p}^{\prime}(u)=\mathbf{c}_{1}+2 u \mathbf{c}_{2}+3 u^{2} \mathbf{c}_{3} \end{aligned} p ( u ) = c 0 + c 1 u + c 2 u 2 + c 3 u 3 p ′ ( u ) = c 1 + 2 u c 2 + 3 u 2 c 3 p 0 = p ( 0 ) = c 0 p 3 = p ( 1 ) = c 0 + c 1 + c 2 + c 3 \begin{aligned} &\mathbf{p}_{0}=\mathbf{p}(0)=\mathbf{c}_{0}\\ &\mathbf{p}_{3}=\mathbf{p}(\mathbf{1})=\mathbf{c}_{0}+\mathbf{c}_{1}+\mathbf{c}_{2}+\mathbf{c}_{3} \end{aligned} p 0 = p ( 0 ) = c 0 p 3 = p ( 1 ) = c 0 + c 1 + c 2 + c 3 p 0 ′ = p ′ ( 0 ) = c 1 p 3 ′ = p ′ ( 1 ) = c 1 + 2 c 2 + 3 c 3 \begin{aligned} &\mathbf{p}_{0}^{\prime}=\mathbf{p}^{\prime}(0)=\mathbf{c}_{1}\\ &\mathbf{p}_{3}^{\prime}=\mathbf{p}^{\prime}(\mathbf{1})=\mathbf{c}_{1}+2 \mathbf{c}_{2}+3 \mathbf{c}_{3} \end{aligned} p 0 ′ = p ′ ( 0 ) = c 1 p 3 ′ = p ′ ( 1 ) = c 1 + 2 c 2 + 3 c 3 我們一樣可以得到 Q = A c \mathbf{Q}=\mathbf{A c} Q = Ac ,其中的 A − 1 \mathbf{A}^{-1} A − 1 可以記為 M H \mathbf{M}_{\mathbf{H}} M H (Hermite Geometry Matrix)
Q = [ p 0 p 3 p 0 ′ p 3 ′ ] = [ 1 0 0 0 1 1 1 1 0 1 0 0 0 1 2 3 ] c , M H = [ 1 0 0 0 1 1 1 1 0 1 0 0 0 1 2 3 ] − 1 = [ 1 0 0 0 0 0 1 0 − 3 3 − 2 − 1 2 2 1 1 ] \begin{aligned} \mathbf{Q}=\left[\begin{array}{l} \mathbf{p}_{0} \\ \mathbf{p}_{3} \\ \mathbf{p}_{0}^{\prime} \\ \mathbf{p}_{3}^{\prime} \end{array}\right]=\left[\begin{array}{llll} 1 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 \\ 0 & 1 & 2 & 3 \end{array}\right] \mathbf{c}, \quad \mathbf{M}_{\mathbf{H}}=\left[\begin{array}{llll} 1 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 \\ 0 & 1 & 2 & 3 \end{array}\right]^{-1}=\left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ -3 & 3 & -2 & -1 \\ 2 & 2 & 1 & 1 \end{array}\right] \end{aligned} Q = ⎣ ⎡ p 0 p 3 p 0 ′ p 3 ′ ⎦ ⎤ = ⎣ ⎡ 1 1 0 0 0 1 1 1 0 1 0 2 0 1 0 3 ⎦ ⎤ c , M H = ⎣ ⎡ 1 1 0 0 0 1 1 1 0 1 0 2 0 1 0 3 ⎦ ⎤ − 1 = ⎣ ⎡ 1 0 − 3 2 0 0 3 2 0 1 − 2 1 0 0 − 1 1 ⎦ ⎤ 再來就可以算出 c \mathbf{c} c 矩陣,進而得到 p ( u ) \mathbf{p}(u) p ( u )
c = M H Q p ( u ) = u T c = u T M H Q \begin{aligned} &\mathbf{c}=\mathbf{M}_{\mathbf{H}} \mathbf{Q}\\ &\mathbf{p}(u)=\mathbf{u}^{T} \mathbf{c}=\mathbf{u}^{T} \mathbf{M}_{H} \mathbf{Q} \end{aligned} c = M H Q p ( u ) = u T c = u T M H Q 當我們只知道四個 control points 而不知道任何的一階微分資訊 時,就可以使用 bezier curves,他可以利用 p1, p2 的位置,來預估頭尾 p0, p3 的一階微分
Bezier curves 所以 Bezier 跟 Hermite 只差在一階微分的值,是用近似 的方法求得
P ( 0 ) = P 0 = c 0 P ( 1 ) = P 3 = c 0 + c 1 + c 2 + c 3 P ′ ( 0 ) = 3 ( P 1 − P 0 ) = c 1 P ′ ( 1 ) = 3 ( P 3 − P 2 ) = c 1 + 2 c 2 + 3 c 3 c = M B P , M B = [ 1 0 0 0 − 3 3 0 0 3 − 6 3 0 − 1 3 − 3 1 ] p ( u ) = u T c = u T M B P \begin{aligned} &P(0)=P_{0}=c_{0}\\ &P(1)=P_{3}=c_{0}+c_{1}+c_{2}+c_{3}\\\\ &P^{\prime}(0)=3\left(P_{1}-P_{0}\right)=c_{1}\\ &P^{\prime}(1)=3\left(P_{3}-P_{2}\right)=c_{1}+2 c_{2}+3 c_{3}\\\\ &\mathbf{c}=\mathbf{M}_{\mathrm{B}} \mathbf{P}, \quad \mathbf{M}_{\mathrm{B}}=\left[\begin{array}{cccc}1 & 0 & 0 & 0 \\ -3 & 3 & 0 & 0 \\ 3 & -6 & 3 & 0 \\ -1 & 3 & -3 & 1\end{array}\right]\\ &\mathbf{p}(u)=\mathbf{u}^{T} \mathbf{c}=\mathbf{u}^{T} \mathbf{M}_{\mathrm{B}} \mathbf{P} \end{aligned} P ( 0 ) = P 0 = c 0 P ( 1 ) = P 3 = c 0 + c 1 + c 2 + c 3 P ′ ( 0 ) = 3 ( P 1 − P 0 ) = c 1 P ′ ( 1 ) = 3 ( P 3 − P 2 ) = c 1 + 2 c 2 + 3 c 3 c = M B P , M B = ⎣ ⎡ 1 − 3 3 − 1 0 3 − 6 3 0 0 3 − 3 0 0 0 1 ⎦ ⎤ p ( u ) = u T c = u T M B P 從以下五個 bezier curves 可以看到,中間點皆是為了預測頭尾微分,而非真正要連接的點
Bezier curves example 上述所產生的 local curves 在連接時,依然會有一階微分不同導致不平滑的問題,解決方法是透過 B-spline curves
讓 curves 不一定要通過頭尾的 control points 但卻可以讓兩個區段在接點處,一階微分的值是相同的 事實上 B-spline 還能滿足接點處的二階微分相同 B-spline curves 在推導時,一樣是每四個 control points 來求得一個 curve
B-spline curves continuity q ( u ) q(u) q ( u ) 由 p i − 3 , p i − 2 , p i − 1 , p i \mathbf{p}_{i-3}, \mathbf{p}_{i-2}, \mathbf{p}_{i-1}, \mathbf{p}_{i} p i − 3 , p i − 2 , p i − 1 , p i 推導而出p ( u ) p(u) p ( u ) 由 p i − 2 , p i − 1 , p i , p i + 1 , \mathbf{p}_{i-2}, \mathbf{p}_{i-1}, \mathbf{p}_{i}, \mathbf{p}_{i+1}, p i − 2 , p i − 1 , p i , p i + 1 , 推導而出我們希望這兩個區段的 q ( 1 ) q(1) q ( 1 ) 和 p ( 0 ) p(0) p ( 0 ) 的位置相同、一階微分也相同,所以要滿足以下式子
p ( 0 ) = q ( 1 ) = 1 6 ( p i − 2 + 4 p i − 1 + p i ) p ′ ( 0 ) = q ′ ( 1 ) = 1 2 ( p i − p i − 2 ) \begin{aligned} &\mathbf{p}(0)=\mathbf{q}(1)= \color{red}{\frac{1}{6}\left(\mathbf{p}_{i-2}+4 \mathbf{p}_{i-1}+\mathbf{p}_{i}\right)}\\ &\mathbf{p}^{\prime}(0)=\mathbf{q}^{\prime}(1)= \color{red}{\frac{1}{2}\left(\mathbf{p}_{i}-\mathbf{p}_{i-2}\right)} \end{aligned} p ( 0 ) = q ( 1 ) = 6 1 ( p i − 2 + 4 p i − 1 + p i ) p ′ ( 0 ) = q ′ ( 1 ) = 2 1 ( p i − p i − 2 ) 後方求值的設定 (紅色處) 不是固定的,以上只是列出常用的做法
位置使用鄰近的三個 points 來預估 一階微分則用鄰近的兩個 points 來預估 要注意鄰近的點需要從兩個區段都有用到的點才能拿來使用 Since p ( u ) = c 0 + c 1 u + c 2 u 2 + c 3 u 3 = u T c p ( 0 ) = c 0 = 1 6 ( p i − 2 + 4 p i − 1 + p i ) p ′ ( 0 ) = c 1 = 1 2 ( p i − p i − 2 ) p ( 1 ) = c 0 + c 1 + c 2 + c 3 = 1 6 ( p i − 1 + 4 p i + p i + 1 ) p ′ ( 1 ) = c 1 + 2 c 2 + 3 c 3 = 1 2 ( p i + 1 − p i − 1 ) \begin{aligned} \text{Since } &\mathbf{p}(u)=\mathbf{c}_{0}+\mathbf{c}_{1} u+\mathbf{c}_{2} u^{2}+\mathbf{c}_{3} u^{3}=u^{T} \mathbf{c}\\ &\mathbf{p}(0)=\mathbf{c}_{0}=\frac{1}{6}\left(\mathbf{p}_{i-2}+4 \mathbf{p}_{i-1}+\mathbf{p}_{i}\right) \\ &\mathbf{p}^{\prime}(0)=\mathbf{c}_{1}=\frac{1}{2}\left(\mathbf{p}_{i}-\mathbf{p}_{i-2}\right) \\ &\mathbf{p}(1)=\mathbf{c}_{0}+\mathbf{c}_{1}+\mathbf{c}_{2}+\mathbf{c}_{3}=\frac{1}{6}\left(\mathbf{p}_{i-1}+4 \mathbf{p}_{i}+\mathbf{p}_{i+1}\right) \\ &\mathbf{p}^{\prime}(1)=\mathbf{c}_{1}+2 \mathbf{c}_{2}+3 \mathbf{c}_{3}=\frac{1}{2}\left(\mathbf{p}_{i+1}-\mathbf{p}_{i-1}\right) \end{aligned} Since p ( u ) = c 0 + c 1 u + c 2 u 2 + c 3 u 3 = u T c p ( 0 ) = c 0 = 6 1 ( p i − 2 + 4 p i − 1 + p i ) p ′ ( 0 ) = c 1 = 2 1 ( p i − p i − 2 ) p ( 1 ) = c 0 + c 1 + c 2 + c 3 = 6 1 ( p i − 1 + 4 p i + p i + 1 ) p ′ ( 1 ) = c 1 + 2 c 2 + 3 c 3 = 2 1 ( p i + 1 − p i − 1 ) 最後我們就可以像其他兩種 curves 一樣推導出 c \mathbf{c} c 和 p ( u ) \mathbf{p}(u) p ( u )
P = A c M S = A − 1 = 1 6 [ 1 4 1 0 − 3 0 3 0 3 − 6 3 0 − 1 3 − 3 1 ] ⇒ c = M S P ⇒ p ( u ) = u T c = u T M S P \begin{aligned} &\mathbf{P}=\mathbf{A c}\\ &\mathbf{M}_{\mathrm{S}}=\mathbf{A}^{-1}=\frac{1}{6}\left[\begin{array}{cccc} 1 & 4 & 1 & 0 \\ -3 & 0 & 3 & 0 \\ 3 & -6 & 3 & 0 \\ -1 & 3 & -3 & 1 \end{array}\right] &&\Rightarrow \mathbf{c}=\mathbf{M}_{\mathrm{S}} \mathbf{P}\\ & \quad&&\Rightarrow \mathbf{p}(u)=u^{T} \mathbf{c} = u^T\mathbf{M}_{\mathrm{S}} \mathbf{P} \end{aligned} P = Ac M S = A − 1 = 6 1 ⎣ ⎡ 1 − 3 3 − 1 4 0 − 6 3 1 3 3 − 3 0 0 0 1 ⎦ ⎤ ⇒ c = M S P ⇒ p ( u ) = u T c = u T M S P