# ICS 415 Computer Graphics B-Spline curves (Chapter 8)

## Presentation on theme: "ICS 415 Computer Graphics B-Spline curves (Chapter 8)"— Presentation transcript:

ICS 415 Computer Graphics B-Spline curves (Chapter 8)
Dr. Muhammed Al-Mulhem March 1, 2009 March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
Bezier curves do not provide enough flexibility in curve design. A Bezier curve based on L+1 control points is a combination of L-degree polynomials. High degree polynomials are expensive to compute, and are vulnerable to numerical round-off errors. We want the designer to be free to use as many control points as desired, even 40 or more. March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
Bezier curves do not offer enough local control of the curve shape. The figure shows five control points used to fashion a Bezier curve (solid line), which deviates somewhat from the desired curve (dashed line) near t = 1. March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
To correct this, the user would move P2 and P3 up somewhat to force the Bezier curve closer to the desired curve. But this also affects the shape of the first half of the curve, forcing it away somewhat from the desired version. March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
A change to any control point alters the entire curve. This arises from the nature of Bernstein polynomials: each is “active” (non-zero) over the entire interval [0, 1]. The interval over which a function is nonzero is often called its support. Because every Bernstein polynomial has support over the entire interval [0, 1], and the curve is a blend of these functions, each control point has an effect on the curve at all t-values between 0 and 1. Therefore, adjusting any control point affects the shape of the curve everywhere, with no local control. March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
The four cubic Bézier blending functions: March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
Contrast the set of blending functions at right. Six blending functions, R0(t), R1(t), ... , R5(t) are shown, each having support that is only a part of the interval [0, 1]. March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
For instance, the support of R0(t) is [0, .25] and that of R3(t) is [.25, 1.0]. At any value of t, no more than three of the blending functions are active. March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
We use the blending functions to build a curve, V(t), based on six given control points, P0, P1, , P5. We use the same kind of parametric form as for Bezier curves: March 1, 2009 Dr. Muhammed Al-Mulhem

Better Blending Functions
At each t the position V(t) depends on no more than three control points. For all t in [0.75, 1.0] only the points P3, P4, and P5 control the shape of the curve. If P4 is moved to P’4, only the dashed portion of the curve will change. These blending functions give some local control to the control points. March 1, 2009 Dr. Muhammed Al-Mulhem

Wish List for Blending Functions
The blending functions should: be easy to compute and numerically stable; sum to one at every t in [a,b]; have small support to offer local control; interpolate certain control points, chosen by the designer; be smooth enough. March 1, 2009 Dr. Muhammed Al-Mulhem

The functions should be easy to compute and numerically stable.
For rapid curve generation we want the blending functions to be computationally simple. We also want them to be minimally affected by numerical round-off error. Consequently, we choose polynomials for the blending functions; the degree of the polynomials should be fairly small. Other kinds of functions, such as sines and cosines, would be too expensive to use. March 1, 2009 Dr. Muhammed Al-Mulhem

The functions must sum to one at every t in [a, b].
V(t) is a weighted sum of points at each t, and this makes sense only if it is an affine sum of points at every t in [a, b]. (Otherwise it is not a point.) Thus we insist that: March 1, 2009 Dr. Muhammed Al-Mulhem

The functions should have small support for local control.
To achieve local control we want each blending function to be concentrated in t, having support over only a small portion of the interval [a, b]. March 1, 2009 Dr. Muhammed Al-Mulhem

The functions should interpolate certain control points.
The designer may want V(t) to pass through some of the control points, but only be attracted towards others. We will need to provide a mechanism that adjusts the blending functions so that certain control points are interpolated. March 1, 2009 Dr. Muhammed Al-Mulhem

The functions should have sufficient smoothness.
The designer normally wants V(t) to be a smooth curve for any set of control points. Typically V(t) should be at least 1-smooth, or even 2-smooth, to produce shapes of the desired smoothness. The smoothness of V(t) depends on the smoothness of the blending functions. Specifically, if every blending function is 1-smooth in [a, b], then V(t) will also be 1-smooth in [a, b]. March 1, 2009 Dr. Muhammed Al-Mulhem

The functions should have sufficient smoothness. (2)
The derivative varies continuously from 0 at t = c, where the function starts. But the derivative at d is discontinuous, jumping abruptly from A to 0. A curve using this blending function would not be 1-smooth at t = d. Thus it is desirable for blending functions to be smooth internally, and also to start and end with derivatives of 0. March 1, 2009 Dr. Muhammed Al-Mulhem

The functions should have sufficient smoothness. (3)
Some Rk start and stop with zero derivatives; others do not. The shapes that begin and end inside [0, 1] do so with zero derivatives, so the curve V(t) will be 1-smooth inside (0,1). The derivatives may be discontinuous at t = 0 or t = 1 because we never use values of t beyond 0 or 1. March 1, 2009 Dr. Muhammed Al-Mulhem

Piecewise Polynomial Curves and Splines
There is no single cubic polynomial which can serve as a blending function. Instead, we piece together several low-degree polynomials. The curves are defined by different polynomials in different t-intervals and are called piecewise polynomials. March 1, 2009 Dr. Muhammed Al-Mulhem

Piecewise Polynomial Curves and Splines (2)
The example shape, g(t), helps establish some nomenclature. g(t) consists of three polynomial segments, defined as March 1, 2009 Dr. Muhammed Al-Mulhem

Piecewise Polynomial Curves and Splines (3)
The support of g(t) is [0, 3]. a(t) is defined on the span [0, 1], b(t) on the span [1, 2], and c(t) on the span [2, 3]. The points where a pair of segments meet are called joints. The values of t at the joints are called knots. There are four knots in this example: 0, 1, 2, and 3. March 1, 2009 Dr. Muhammed Al-Mulhem

Piecewise Polynomial Curves and Splines (4)
g(t) is continuous over its support; because it is built from polynomials, it is certainly continuous inside each span, and a(1) = b(1) = 1/2, and b(2) = c(2) = 1/2. The derivative of g(t) is continuous everywhere: g(t) is 1-smooth in [0, 3]. The derivative is continuous inside each span and a’(1) =b’(1) =1, b’(2) = c’(2) = -1. March 1, 2009 Dr. Muhammed Al-Mulhem

Splines The shape g(t) here is an example of a spline function, a piecewise polynomial function that is “smooth enough”. Definition of a Spline Function: An Mth-degree spline function is a piecewise polynomial of degree M that is (M-1)-smooth at each knot. The example g(t) is a quadratic spline: It is a piecewise polynomial of degree 2 and has a continuous first derivative everywhere. March 1, 2009 Dr. Muhammed Al-Mulhem

Making Blending Functions from Splines
We use translated versions of g(t), where each blending function gk(t) is formed by translating the basic shape g(t) by a certain amount. The figure shows seven blending functions g0(t),..,g6(t) formed by translating g(t) by integer amounts: gk(t) = g(t+k) for k = 0, 1, 2, … March 1, 2009 Dr. Muhammed Al-Mulhem

Making Blending Functions from Splines (2)
Since the knots of the various versions of g(t) occur at integers, this is equivalent to translating; the knots of one curve then line up with knots of the next curve. These translated versions will form a legitimate set of blending functions only if they add up exactly to 1 at every t. But they do for all t in [2, 7]. March 1, 2009 Dr. Muhammed Al-Mulhem

Making Blending Functions from Splines (3)
The designer chooses 7 control points and generates the curve from Only values of t between 2 and 7 can be used. In that range, exactly three of the blending functions are active at any value of t, so there is good local control of the curve’s shape. In addition, at times t = 2, 3, .., and 7 only two of the functions are active and they both have value 0.5. Therefore, at these t-values V(t) will lie at the midpoint of the line between two of the control points. March 1, 2009 Dr. Muhammed Al-Mulhem

Making Blending Functions from Splines: Example (4)
March 1, 2009 Dr. Muhammed Al-Mulhem

Properties of the Curve
The designer has some local control of the curve shape, because the interval of support for each blending function is limited to length 3. The designer knows that the curve must pass through midpoints of the control polygon edges. So the algorithm has some intuitive geometric properties. Because each blending function is 1-smooth, the whole curve is 1-smooth. No control points on the curve are interpolated. All polynomials are of degree two, so they are fast and stable to compute. The degree of the polynomials does not depend on the number of control points. The technique works for any number of control points. March 1, 2009 Dr. Muhammed Al-Mulhem

More General Blending Functions
We need more control of the curve shape: it must bend more and be smoother than just 1-smooth. This suggests moving to cubic polynomials. We also want the designer to be able to specify which control points are interpolated. And we want a single algorithm that would encompass all of the design techniques described above — including Bezier curves. So we want to develop more general families of blending functions that meet all the properties discussed in the earlier wish list. March 1, 2009 Dr. Muhammed Al-Mulhem

More General Blending Functions (2)
We continue to use the same parametric form based on L+1 control points and L+1 blending functions R0(t), ..., RL(t). We also continue to use piecewise polynomials for the blending functions, but now they are defined on a more general sequence of knots, called the knot vector, T = [t0, t1, t2, …]. Some knots might have the same value but are still given distinct names. March 1, 2009 Dr. Muhammed Al-Mulhem

More General Blending Functions (3)
Each blending function Rk(t) is a piecewise polynomial that is zero up to time tk, is non-zero over several spans in the knot vector, and then returns to zero again. We insist further that each Rk(t) be a spline function, so that it ensures a certain level of smoothness at all t in its support. March 1, 2009 Dr. Muhammed Al-Mulhem

More General Blending Functions (4)
Given a knot vector, is there some family of blending functions that can be used to generate every possible spline curve that can be defined on that knot vector? Such a family is called a basis for the splines, meaning that any spline curve whatsoever can be matched by the sum by choosing the proper control points. March 1, 2009 Dr. Muhammed Al-Mulhem

More General Blending Functions (5)
There are many such families, but there is one basis in particular whose blending functions have the smallest support and therefore offer the greatest local control. These are the B-splines, the ‘B’ derived from the word basis. March 1, 2009 Dr. Muhammed Al-Mulhem

B-Spline Basis Functions
There is a single recursive formula that defines all the B-spline functions of any order. It is easy to implement in a program and is numerically well behaved. Some other methods are more computationally efficient. March 1, 2009 Dr. Muhammed Al-Mulhem

B-Spline Basis Functions (2)
Each B-spline function is based on polynomials of a certain order, m. If m = 3, the polynomials will be of order 3 and thus of degree 2, and so they will be quadratic B-splines. If the order is m = 4, the underlying polynomials will be of degree 3, or cubic. These are the two most important cases, although the formulation allows us to construct B-splines of any order. March 1, 2009 Dr. Muhammed Al-Mulhem

B-Spline Basis Functions (3)
It is useful to make the order of a B-spline function explicit in the notation, and so we denote the k-th B-spline blending function of order m by Nk,m(t). March 1, 2009 Dr. Muhammed Al-Mulhem

B-Spline Basis Functions (4)
Summarizing the ingredients, we have a knot vector T = (t0, t1, t ) (L+1) control points Pk the order m of the B-spline functions The B-spline function for k = 0, 1, …, L is given by March 1, 2009 Dr. Muhammed Al-Mulhem

B-Spline Basis Functions (5)
To get things started, the first-order function must be defined. It is simply the constant function 1 within its span: March 1, 2009 Dr. Muhammed Al-Mulhem

B-Spline Basis Functions (6)
This set of functions automatically sums to one at every t, so it is legitimate to use them in forming combinations of points. Code to calculate the B-spline basis functions recursively is given in your book. March 1, 2009 Dr. Muhammed Al-Mulhem

Using Multiple Knots in the Knot Vector
Up to this point we have used only B-splines based on equispaced knots. By varying the spacing between knots, the curve designer acquires much greater control of the shape of the final curve. A central question is what happens to the shapes of the blending functions when two knots are set very close to one another. March 1, 2009 Dr. Muhammed Al-Mulhem

Using Multiple Knots in the Knot Vector (2)
The figure shows the situation when the knot vector is T = (0, 1, 2, 3, 3+ ε, 4+ ε, ), where ε is a small positive number. March 1, 2009 Dr. Muhammed Al-Mulhem

Using Multiple Knots in the Knot Vector (3)
The piece of each piecewise polynomial lying in the interval [3, 3+ ε] has become squeezed into a very narrow span. The blending functions are not translations of one another. If ε = 0, this span will vanish altogether, and a multiple knot will occur at t = 3. This knot is said to have a “multiplicity of 2.” March 1, 2009 Dr. Muhammed Al-Mulhem

Using Multiple Knots in the Knot Vector (4)
Two of the linear B-splines are discontinuous, and the quadratic shapes have a discontinuous derivative at t = 3. In general, an i-smooth curve is reduced to an (i-1)-smooth curve at the multiple knot value. The cubic B-spline curves are 1-smooth everywhere, but not 2-smooth at t = 3. But if quadratic B-splines are used, the curve will interpolate control point P2 because the blending function N2,3(t) reaches value 1 at t = 3 and all the other blending functions are zero there. In general, when t approaches a knot of multiplicity greater than one, there is a stronger attraction to the governing control point. March 1, 2009 Dr. Muhammed Al-Mulhem

Using Multiple Knots in the Knot Vector (5)
Quadratic splines become discontinuous near a knot of multiplicity 3. Cubic splines exhibit a discontinuous derivative near a knot of multiplicity 3, but they also interpolate one of the control points. By adjusting the multiplicity of each knot, the designer can change the shape of the curve in a predictable fashion. Neither the equation nor the code need be altered when the knot vector contains multiple knots. As we mentioned, some of the denominators become zero, but the code automatically handles this situation, and no adjustments need be made. March 1, 2009 Dr. Muhammed Al-Mulhem

Standard Knot Vector The standard knot vector for a B-spline of order m begins and ends with a knot of multiplicity m and uses unit spacing for the remaining knots. We start with an example and then see how it arises. Suppose there are eight control points and we want to use cubic (m = 4) B-splines. The standard knot vector turns out to be T = (0, 0, 0, 0, 1, 2, 3, 4, 5, 5, 5, 5) March 1, 2009 Dr. Muhammed Al-Mulhem

Standard Knot Vector (2)
Blending functions N0,4(t) and N7,4(t) are discontinuous and have a support of one unit span. Only N3,4(t) and N4,4(t) have the usual span of four units. The remaining blending functions have two or three unit spans, and their shapes become more distorted as they approach the first and last knots. March 1, 2009 Dr. Muhammed Al-Mulhem

Standard Knot Vector (3)
The standard knot vector always ensures interpolation of the first and last control points. The initial direction of the B- spline curve at t = 0 is along the first segment of the control polygon, and similarly for the final direction. Note that a B-spline curve can cross itself when the control polygon does. March 1, 2009 Dr. Muhammed Al-Mulhem

Standard Knot Vector (4)
The standard knot vector for (L+1) control points and order-m B-splines is described as follows There are L+m+1 knots, denoted as t0, ,tL+m. The first m knots, t0, , tm - 1, all share the value 0. (The first m blending functions start at t = 0.) Knots tm, , tL increase in increments of 1, from value 1 through value L - m+1. (The final blending function, NL,m(t), begins at tL = L - m + 1 and has a support of width 1.) The final m knots, tL+1, , tL+m, all equal L - m + 2. March 1, 2009 Dr. Muhammed Al-Mulhem

Code for the Standard Knot Vector
void buildKnots (int m, int L, double knot[ ]) { // Build the standard knot vector for L+1 control points // and B-splines of order m int i; if (L < (m - 1)) return; // too few control points for (i = 0; i <= L + m; i++) if (i < m) knot[i] = 0.0; else if (i <= L) knot[i] = i - m + 1; // i is at least m here else knot[i] = L - m + 2; // i exceeds L here } March 1, 2009 Dr. Muhammed Al-Mulhem

B-splines and Bezier Curves
Bezier curves are a special case of B-splines. This is so because the B-spline blending functions defined on the standard knot vector are in fact Bernstein polynomials when m = L + 1. That is, Nk,L+1(t) = BkL(t) for k = 0, , L. Note that by convention the upper parameter of B() is degree, while the second parameter of N() is order. March 1, 2009 Dr. Muhammed Al-Mulhem

B-splines and Bezier Curves (2)
B-spline curves give local control of the shape. When the order of the B-spline polynomials is increased by 1, the support of each B-spline blending function extends one span further, reducing the amount of local control. When m reaches the bound of L+1, the Bezier case is obtained, and local control is at a minimum. March 1, 2009 Dr. Muhammed Al-Mulhem

Useful Properties of B-splines for Design
The m-th-order B-spline functions are piecewise polynomials of order m. They are (m-2)-smooth splines: They exhibit (m - 2) orders of continuous derivatives at every point in their support. They form a basis for any spline of the same order defined on the same knots; i.e., any spline can be represented as a linear combination of B- splines. Of all spline bases, the B-splines are the most concentrated, having the shortest supports. March 1, 2009 Dr. Muhammed Al-Mulhem

Useful Properties of B-splines for Design (2)
The B-spline blending function, Nk,m(t), begins at tk and ends at tk+m. Its support is [tk, tk+m]. The support of the family of functions, Nk,m(t), for k = 0, , L is the interval [t0, tm+L]. A closed B-spline curve based on L + 1 control points may be obtained (look at your book pages ). March 1, 2009 Dr. Muhammed Al-Mulhem

Useful Properties of B-splines for Design (3)
If the standard knot vector is used, the B-spline curve will interpolate the first and last control points. Its initial and final directions are along the first and last edges of the control polygon, respectively. Each B-spline function, Nk,m(t), is nonnegative for every t, and the family of such functions sums to 1. March 1, 2009 Dr. Muhammed Al-Mulhem

Useful Properties of B-splines for Design (4)
Curves based on B-splines are affine invariant (transformation invariant). To transform a B-spline curve, simply transform each control point, and generate the new curve based on the transformed control points. A B-spline curve is a convex combination of its control points and so lies in their convex hull. A stronger statement is possible: At any t only m B-spline functions are active (nonzero). Thus at each t the curve must lie in the convex hull of at most m consecutive active control points. March 1, 2009 Dr. Muhammed Al-Mulhem

Useful Properties of B-splines for Design (5)
The figure shows a quadratic B- spline curve using the standard knot vector. At most three control points are active at each t; the relevant convex hulls are triangles. As t increases, P(t) passes out of each triangle and into the next as each new blending function becomes active. March 1, 2009 Dr. Muhammed Al-Mulhem

Useful Properties of B-splines for Design (6)
B-spline curves exhibit linear precision: If m consecutive control points are collinear, their convex hull will be a straight line, and the curve will be trapped within it. B-spline curves are variation diminishing: A B- spline curve does not pass through any line more times than does its control polygon. March 1, 2009 Dr. Muhammed Al-Mulhem

Using Multiple Control Points
With cubic B-spline curves, the curve based on control points A, B, C, D, E, F, and G is normal. When a double point is used at D, (the control polygon is A, B, C, D, D, E, F, G), the curve is pulled toward D. When a triple point is placed at D, making the control polygon A, B, C, D, D, D, E, F, G, the curve must actually interpolate D. March 1, 2009 Dr. Muhammed Al-Mulhem