Presentation is loading. Please wait.

Presentation is loading. Please wait.

Interpolating Splines, Implicit Descriptions Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, March 5,

Similar presentations


Presentation on theme: "Interpolating Splines, Implicit Descriptions Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, March 5,"— Presentation transcript:

1 Interpolating Splines, Implicit Descriptions Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, March 5, 2004

2 5 Mar 2004CS 481/6812 Review: Bézier Algorithms [1/3] The de Casteljau Algorithm computes a point on a Bézier curve using this repeated lirping procedure. Each lirp is done using the same value of t. x, y, and z are computed separately. lirp P0P0 P1P1 P2P2 P3P3 P4P4 Point on curve

3 5 Mar 2004CS 481/6813 Review: Bézier Algorithms [2/3] Another way to draw a Bézier curve is to use the polynomial that describes it to compute coordinates of points. If there are n control points (P 0, P 1, …, P n–1 ), then a Bézier curve is parameterized by a polynomial of degree n–1. For four control points the polynomial is P 0 ·(1–t) 3 + P 1 ·3(1–t) 2 t + P 2 ·3(1–t)t 2 + P 3 ·t 3. This is made up of pieces called Bernstein polynomials. B 3 0 (t) = (1–t) 3. B 3 1 (t) = 3(1–t) 2 t. B 3 2 (t) = 3(1–t)t 2. B 3 3 (t) = t 3. The pattern: Descending powers of (1–t). Ascending powers of t. Coefficients are binomial coefficients. Found in Pascal’s Triangle.

4 5 Mar 2004CS 481/6814 Review: Bézier Algorithms [3/3] The way we described Bézier surfaces last time suggests how to extend curve-drawing algorithms to surfaces. Say we have a grid of 9 control points, as shown. The horizontal curves have the following formulas: P 0,0 ·(1–t) 2 + P 0,1 ·2(1–t)t + P 0,2 ·t 2 P 1,0 ·(1–t) 2 + P 1,1 ·2(1–t)t + P 1,2 ·t 2 P 2,0 ·(1–t) 2 + P 2,1 ·2(1–t)t + P 2,2 ·t 2 Now we use points on these curves as control points. Let our vertical parameter be s. We obtain the following formula for a Bézier patch: [ P 0,0 ·(1–t) 2 + P 0,1 ·2(1–t)t + P 0,2 ·t 2 ]·(1–s) 2 + [ P 1,0 ·(1–t) 2 + P 1,1 ·2(1–t)t + P 1,2 ·t 2 ]·2(1–s)s + [ P 2,0 ·(1–t) 2 + P 2,1 ·2(1–t)t + P 2,2 ·t 2 ]·s 2 P 0,0 P 0,1 P 0,2 P 1,0 P 1,1 P 1,2 P 2,0 P 2,1 P 2,2

5 5 Mar 2004CS 481/6815 Review: Bézier Properties [1/3] Two properties of Bézier curves are worth another look: Affine Invariance Convex-Hull Property An affine transformation is a transformation that can be produced by doing a linear transformation followed by a translation. All of the transformations we have dealt with, except for perspective projection, are affine. Bézier curves have the property that applying an affine transformation to each control points results in the same transformation being applied to every point on the curve. This property is called affine invariance. For example, to rotate a Bézier curve, apply a rotation to the control points. In short: Transformations act the way you want them to.

6 5 Mar 2004CS 481/6816 The convex hull of a set of points is the smallest convex region containing them. Informally speaking, “lasso” (or shrink-wrap) the points; the region inside the lasso is the convex hull. A Bézier curve lies entirely in the convex hull of its control points. This is called the convex-hull property. This property makes it easy to specify where a curve will not go. Smooth interpolating splines never have this property. Review: Bézier Properties [2/3] P1P1 P0P0 P2P2 P1P1 P0P0 P2P2 PointsConvex hull P1P1 P0P0 P2P2

7 5 Mar 2004CS 481/6817 Review: Bézier Properties [3/3] Bézier curves do not interpolate all their control points. So we can easily specify where it does not go, but not where it does go. Bézier curves also do not have “local control”. A curve has local control if moving a single control point only changes a small part of the curve (the part near the control point). Moving any control point on a Bézier curve changes the whole curve. This is the main reason we do not use Bézier curves with a large number of control points. Instead, we piece together several 3- or 4-point Bézier curves in a smooth way. This multiple-Bézier curve does have local control.

8 5 Mar 2004CS 481/6818 Review: Building Better Curves The biggest problems with Bézier curves are: Lack of local control. High degree, if there are a large number of control points. Lack of interpolation (sometimes a problem, sometimes not). Better curve #1: B-spline. Parametric curve described by polynomials based on control points. Has affine invariance & local control. Has same degree regardless of number of control points. Approximating, has convex-hull property. Better curve #2: Catmull-Rom spline. Parametric curve described by polynomials based on control points. Has affine invariance & local control. Has same degree (3) regardless of number of control points. Interpolating, no convex-hull property, (and a bit tough to get “just right”). Better curve #3: NURBS (Non-Uniform Rational B-Spline). Parametric curve described by rational functions based on control points. Has affine invariance & local control. Very general & adaptable, but thus somewhat tougher to use. Built into GLU.

9 5 Mar 2004CS 481/6819 Interpolating Splines: Overview We would like to define an interpolating spline with lots of convenient properties. We can get pretty much all the good properties, except for the convex-hull property. Remember that smooth, interpolating splines never have this property. Some interpolating splines require additional information, besides their control points. Our goal is not to require this. Our goal is called a Catmull-Rom spline. We will reach this goal in three steps. Hermite Curves Interpolating splines that require a vector to be specified at each control point. Cardinal Splines Nearly to the goal, but there is a “tension” parameter. Catmull-Rom Splines The goal.

10 5 Mar 2004CS 481/68110 Interpolating Splines: Hermite Curves — Idea [1/2] The first step toward our goal is an Hermite curve. French again. Say “air-MEET”. Clear your throat a little during the “r”, and you’ll have it perfect. An Hermite curve is an interpolating spline whose formulas are cubic (degree  3) polynomials. We look at the segment between two control points: P i and P i+1. At each control point, we specify a velocity (or direction) vector. Call the vectors v i and v i+1. P i+1 PiPi vivi v i+1

11 5 Mar 2004CS 481/68111 Interpolating Splines: Hermite Curves — Idea [2/2] It turns out that there is a unique cubic polynomial that meets the following four constraints: At t = 0, its value is P i. At t = 1, its value is P i+1. At t = 0, its derivative is v i. At t = 1, its derivative is v i+1. Remember that the value of this polynomial is a point in space. So it will have the form f(t) = At 3 + Bt 2 + Ct + D, where A, B, C, and D are points/vectors. P i+1 PiPi vivi v i+1

12 5 Mar 2004CS 481/68112 Interpolating Splines: Hermite Curves — Computations Again, there is a unique cubic polynomial f(t) = At 3 + Bt 2 + Ct + D that meets the following four constraints: At t = 0, its value is P i. At t = 1, its value is P i+1. At t = 0, its derivative is v i. At t = 1, its derivative is v i+1. How do we find it? First, find the derivative: f (t) = 3At 2 + 2Bt + C Next figure out what the four constraints mean: P i = f(0) = D P i+1 = f(1) = A + B + C + D v i = f (0) = C v i+1 = f (1) = 3A + 2B + C This gives a system of 4 linear equations in 4 variables (A, B, C, D). Solve to obtain: A = 2P i – 2P i+1 + v i + v i+1 B = –3P i + 3P i+1 – 2v i – v i+1 C = v i D = P i

13 5 Mar 2004CS 481/68113 Interpolating Splines: Hermite Curves — Code The results: A = 2P i – 2P i+1 + v i + v i+1 B = –3P i + 3P i+1 – 2v i – v i+1 C = v i D = P i Here is some code using TRANSF: const int ncp; // Number of Control Points pos p[ncp]; // Array of control points vec v[ncp]; // Vector for each control point int i; // subscript, same as i above double t; // parameter value, in [0,1] vec A = 2.*(p[i] – p[i+1]) + v[i] + v[i+1]; vec B = -3.*(p[i] – p[i+1]) – 2*v[i] – v[i+1]; vec C = v[i]; pos D = p[i]; pos point_on_hermite_curve = t*t*t*A + t*t*B + t*C + D;

14 5 Mar 2004CS 481/68114 Interpolating Splines: Hermite Curves — Notes In practice, Hermite curve segments join to make a smooth curve. Hermite curves are relatively common. Whenever you see an interpolating curve with direction handles on the control points, you are probably dealing with an Hermite curve. Why did we use cubic polynomials? P i+1 PiPi vivi v i+1 P i+2 v i+2

15 5 Mar 2004CS 481/68115 Interpolating Splines: Cardinal Splines Hermite curves fall short of our goal, since they require direction vectors to be specified. If we can compute these vectors automatically, based on the control points, then we can meet our goal using Hermite curves. Idea Let v i be parallel to the vector from P i–1 to P i+1. So v i = k(P i+1 – P i–1 ). The value k is called the tension. The tension can be whatever you want, but usually it is between 0 and 1. Tension 0 makes a polyline. Problem: We cannot define the first & last curve segments. We address this later. P i+1 P i–1 PiPi vivi

16 5 Mar 2004CS 481/68116 Interpolating Splines: Catmull-Rom Splines (The Goal) Suppose the control points of a cardinal spline are equally spaced along a straight line. What should the tension be? k = ½ seems natural, since it makes the speed constant. A cardinal spline with tension ½ is called a Catmull-Rom spline. Properties Defined entirely in terms of control points. Can use any number of control points; always defined by cubic polynomials. Interpolating. Smooth. Local control. Affine invariant. NO convex-hull property , but you can’t have everything. Use the Hermite-curve code to draw it.

17 5 Mar 2004CS 481/68117 Interpolating Splines: Hitting the Endpoints One small problem with a Catmull-Rom spline is that we cannot hit the first and last control points (unless they lie in a loop). Each segment needs 4 constraints. Normally, these are the two positions and the two vectors. But we don’t have a vector at the first & last points. Solution Instead of constraining f to be a certain velocity vector, use the constraint f (0) = 0 or f (1) = 0 at the endpoints. Then solve the system again. Then, given any list of control points, we have a uniquely defined curve passing through all of them, in order. There are any number of other proposed variations on the cardinal spline, higher-degree versions, etc.

18 5 Mar 2004CS 481/68118 Interpolating Splines: Surface Patches We define a Catmull-Rom surface patch using the same ideas that we used to define a Bézier patch. Start with a rectangular grid of control points. Compute curves through each horizontal row of control points. Use corresponding points on these curves as control points for vertical curves. Put the vertical curves together to make the patch. See the formula for a Bézier patch to get an idea of how the computation would look.

19 5 Mar 2004CS 481/68119 Implicit Descriptions: Introduction Recall, a surface can be defined using: A Polygon List An Explicit description Formulas based on parameters. An Implicit Description Equations to be solved. Spline curves & surfaces are a way to create easy-to-define explicit descriptions. Now, we look at implicit descriptions.

20 5 Mar 2004CS 481/68120 Implicit Descriptions: Why? One problem with explicit descriptions is that they generally assume some kind of rectangular grid on a surface. Can you put a rectangular grid on an arbitrary object? What about a surface that can change topology? Implicit descriptions do not have these problems. Of course, they have other problems …

21 5 Mar 2004CS 481/68121 Implicit Descriptions: What They Look Like [1/2] Strictly speaking, an implicit description is an equation to be solved. In practice, however, things look a bit different. Typically, we specify “potential” values at various points in space. We want to approximate the surface consisting of all points at a particular “threshold” value. This is called an isosurface. Thus, we want solutions to this equation: potential(x, y, z) = threshold_value However, we do not define the potential everywhere, so it might not be clear exactly what we are approximating.

22 5 Mar 2004CS 481/68122 Implicit Descriptions: What They Look Like [2/2] Specifying potential values generally takes one of two forms: Specify potentials at every point in a 3-D grid. Specify potentials at a very limited set of points. The former method is well studied, and somewhat reasonable algorithms exist to draw approximations of the surface. The latter method is up-and-coming … Time for a blackboard picture.


Download ppt "Interpolating Splines, Implicit Descriptions Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, March 5,"

Similar presentations


Ads by Google