Cubic Splines; Bézier Curves 1 Cubic Splines piecewise approximation with cubic polynomials conditions on the coefficients of the splines 2 Bézier Curves computer-aided design and manufacturing MCS 471 Lecture 8(b) Numerical Analysis Jan Verschelde, 6 July 2018 Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 1 / 18
Cubic Splines; Bézier Curves 1 Cubic Splines piecewise approximation with cubic polynomials conditions on the coefficients of the splines 2 Bézier Curves computer-aided design and manufacturing Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 2 / 18
piecewise approximation with cubic polynomials f 1 f 0 f 2 f 3 f 5 f 4 x 0 x 1 x 2 x 3 x 4 x 5 Input: (x i, f i ), i = 0, 1,..., n, x 0 < x 1 < < x n. Interpolating splines S i through internal nodes x 1, x 2,..., x n 1 : S i 1 (x i 1 ) = S i (x i ) same value, S i 1 (x i 1) = S i (x i) same slope, S i 1 i 1) = S i (x i ) same concavity. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 3 / 18
cubic splines Input: n + 1 data points (x 0, f 0 ), (x 1, f 1 ),..., (x n, f n ). Interpolating cubic splines: S i (x) = f i + b i (x x i ) + c i (x x i ) 2 + d i (x x i ) 3, on [x i, x i+1 ], i = 0, 1,..., n 1. We see S i (x i ) = f i. Additional conditions: S i (x i+1 ) = f i+1, i = 0, 1,..., n 1, S i 1 (x i) = S i (x i), i = 1, 2,..., n 1, S i 1 i) = S i (x i ), i = 1, 2,..., n 1. So we have n + (n 1) + (n 1) = 3n 2 conditions for 3n coefficients. Two degrees of freedom. For a natural spline, we require S 0 (x 0) = 0 and S n(x n ) = 0. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 4 / 18
Cubic Splines; Bézier Curves 1 Cubic Splines piecewise approximation with cubic polynomials conditions on the coefficients of the splines 2 Bézier Curves computer-aided design and manufacturing Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 5 / 18
deriving conditions S i (x) = f i + b i (x x i ) + c i (x x i ) 2 + d i (x x i ) 3, S i (x) = b i + 2c i (x x i ) + 3d i (x x i ) 2, S i (x) = 2c i + 6d i (x x i ). Consider S i (x i ) = 2c i c i = S i (x i )/2, and then: S i (x i+1 ) = 2c i + 6d i (x i+1 x i ) S i (x i ) = 2c i S i (x i+1 ) S i (x i ) = 6d i (x i+1 x i ) d i = S i (x i+1 ) S i (x i ) 6(x i+1 x i ) Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 6 / 18
deriving conditions continued We have already derived the following: S i (x) = f i + b i (x x i ) + c i (x x i ) 2 + d i (x x i ) 3, c i = S i (x i )/2, d i = (S i (x i+1 ) S i (x i ))/(6(x i+1 x i )). Now we look for conditions on b i : S i (x i+1 ) = f i+1 = f i + b i (x i+1 x i ) + c i (x i+1 x i ) 2 + d i (x i+1 x i ) 3. f i+1 f i x i+1 x i = b i + c i (x i+1 x i ) + d i (x i+1 x i ) 2 = b i + S i (x i ) 2 = b i + S i (x i ) 2 (x i+1 x i ) + S i (x i+1 ) S 6(x i+1 x i ) (x i+1 x i ) + S i (x i+1 ) S 6(x i+1 x i ) i (x i ) (x i+1 x i ) 2 i (x i ) (x i+1 x i ) 2 Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 7 / 18
deriving conditions continued f i+1 f i = b i + S i (x i ) x i+1 x i 2 = b i + x i+1 x i 6 (x i+1 x i ) + S i (x i+1 ) S 6(x i+1 x i ) b i = f i+1 f i x i+1 x i x i+1 x i 6 ( 3S i (x i ) + S i (x i+1 ) S i (x i ) ) i (x i ) (x i+1 x i ) 2 (2S i (x i ) + S i (x i+1 )) Denote h i = x i+1 x i, T i = S i (x i ), T i+1 = S i (x i+1 ): b i = f i+1 f i h i h i 6 (2T i + T i+1 ), c i = T i 2, d i = T i+1 T i 6h i. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 8 / 18
deriving conditions continued S i (x) = b i + 2c i (x x i ) + 3d i (x x i ) 2, S i (x i) = b i. Impose slope conditions S i 1 (x i) = S i (x i), h i = x i+1 x i. S i 1 (x i) = b i 1 + 2c i 1 (x i x i 1 ) + 3d i 1 (x i x i 1 ) 2 = f i f i 1 h i 1 h i 1 6 (2T i 1 + T i ) + 2 T i 1 2 h i 1 + 3 T i T i 1 ( 3 = T i 6 h i 1 1 ) ( 6 h i 1 + T i 1 3 6 h i 1 + h i 1 2 ) 6 h i 1 = 2 6 h i 1T i + 1 6 h i 1T i 1 + f i f i 1 h i 1 6h i 1 h 2 i 1 + f i f i 1 h i 1 Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 9 / 18
imposing slope conditions S i 1 (x i) = S i (x i) Recall: S i (x) = b i + 2c i (x x i ) + 3d i (x x i ) 2, S i (x i ) = b i = f i+1 f i h i h i 6 (2T i + T i+1 ). Thus we have: 2 6 h i 1T i + 1 6 h i 1T i 1 + f i f i 1 = f i+1 f i 2 h i 1 h i 6 h it i 1 6 h it i+1 1 6 h it i+1 + 2 6 (h i 1 + h i )T i + 1 6 h i 1T i 1 = f i+1 f i f i f i 1 h i h i 1 h i T i+1 + 2(h i 1 + h i )T i + h i 1 T i 1 = 6(f [x i, x i+1 ] f [x i 1, x i ]) for i = 1, 2,..., n, which gives n equations in n + 2 unknowns, with two additional conditions: T 0 = 0, T n+1 = 0. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 10 / 18
an example, for n = 4 A = h 0 2(h 0 + h 1 ) h 1 0 0 0 h 1 2(h 1 + h 2 ) h 2 0 0 0 h 2 2(h 2 + h 3 ) h 3 A T 0 T 1 T 2 T 3 T 4 = 6(f [x 1, x 2 ] f [x 0, x 1 ]) 6(f [x 2, x 3 ] f [x 1, x 2 ]) 6(f [x 3, x 4 ] f [x 2, x 3 ]) With T 0 = 0 and T 4 = 0: a 3-by-3 linear system. b i = f i+1 f i h i h i 6 (2T i + T i+1 ), c i = T i 2, d i = T i+1 T i 6h i. S i (x) = f i + b i (x x i ) + c i (x x i ) 2 + d i (x x i ) 3. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 11 / 18
compute a numerical example Exercise 1: Compute the natural cubic spline through the points (1, 1), (2, 5), (3, 6), and (4, 0). Verify that your solution satisfies all conditions, as listed on slide #4. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 12 / 18
uniqueness of the cubic spline Observe that the system in the T i s is diagonally dominant. This implies that the linear system has a unique solution. Theorem For inputs (x i, f i ), i = 0, 1,..., n, x 0 < x 1 < < x n, there is a unique piecewise approximation with cubic splines S i : interpolating: S i (x i ) = f i, i = 0, 1,..., n 1, S n 1 (x n ) = f n, at all internal nodes, for i = 1, 2,..., n 1: S i 1 (x i 1 ) = S i (x i ), S i 1 (x i 1) = S i (x i), S i 1 (x i 1) = S i (x i ), natural: S 0 (x 0) = 0, S n 1 (x n) = 0. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 13 / 18
numerical conditioning Exercise 2: Consider the matrix for n = 6: 2(h 0 + h 1 ) h 1 0 0 0 h 1 2(h 1 + h 2 ) h 2 0 0 A = 0 h 2 2(h 2 + h 3 ) h 3 0 0 0 h 3 2(h 3 + h 4 ) h 4, 0 0 0 h 4 2(h 4 + h 5 ) where h i is the distance between x i and x i+1, for i = 0, 1,..., 5. 1 Generate random values for all h i s and compute the condition number of A. Is this problem well conditioned? Justify. 2 For which values of h i is the matrix A poorly conditioned? Generate an example and justify your choice for the distances. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 14 / 18
Cubic Splines; Bézier Curves 1 Cubic Splines piecewise approximation with cubic polynomials conditions on the coefficients of the splines 2 Bézier Curves computer-aided design and manufacturing Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 15 / 18
Bézier Curves Bézier curves are splines that allow to control the slopes at the knots. y 4 3 2 1 0 0 1 2 3 4 x Input: knot (1, 1) with control (1, 3), knot (2, 2) with control (3, 3). Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 16 / 18
a Bézier curve Input: end points (x 1, y 1 ), (x 4, y 4 ); and control points (x 2, y 2 ), (x 3, y 3 ). Set b x = 3(x 2 x 1 ), c x = 3(x 3 x 2 ) b x, d x = x 4 x 1 b x c x, b y = 3(y 2 y 1 ), c y = 3(y 3 y 2 ) b y, d y = y 4 y 1 b y c y, then the Bézier curve (x(t), y(t)), for t [0, 1], is x(t) = x 1 + b x t + c x t 2 + d x t 3 y(t) = y 1 + b y t + c y t 2 + d y t 3. We see that x(0) = x 1 and y(0) = y 1, x (0) = b x and y (0) = b y. x(1) = x 1 + b x + c x + x 4 x 1 b x c x = x 4 x (1) = b x + 2c x + 3(x 4 x 1 b x c x ) = 3(x 4 x 1 ) 2b x c x = 3(x 4 x 1 ) 2b x (3(x 3 x 2 ) b x ) = 3(x 4 x 1 ) 3(x 2 x 1 ) 3(x 3 x 2 ) = 3(x 4 x 3 ). Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 17 / 18
an example Input: knot (1, 1) with control (1, 3), knot (2, 2) with control (3, 3). y 4 3 2 1 0 0 1 2 3 4 x Output: x(t) = 1 + 6t 2 5t 3, y(t) = 1 + 6t 6t 2 + t 3. Numerical Analysis (MCS 471) Cubic Splines; Bézier Curves L-8(b) 6 July 2018 18 / 18