An introduction to interpolation and splines

Similar documents
Curves and Surfaces 1

3D Modeling Parametric Curves & Surfaces

3D Modeling Parametric Curves & Surfaces. Shandong University Spring 2013

Fall CSCI 420: Computer Graphics. 4.2 Splines. Hao Li.

Intro to Modeling Modeling in 3D

Splines. Parameterization of a Curve. Curve Representations. Roller coaster. What Do We Need From Curves in Computer Graphics? Modeling Complex Shapes

2D Spline Curves. CS 4620 Lecture 18

Until now we have worked with flat entities such as lines and flat polygons. Fit well with graphics hardware Mathematically simple

2D Spline Curves. CS 4620 Lecture 13

Interactive Graphics. Lecture 9: Introduction to Spline Curves. Interactive Graphics Lecture 9: Slide 1

Representing Curves Part II. Foley & Van Dam, Chapter 11

Parametric Curves. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Curves and Surfaces Computer Graphics I Lecture 9

Bezier Curves, B-Splines, NURBS

Parametric Curves. University of Texas at Austin CS384G - Computer Graphics

Know it. Control points. B Spline surfaces. Implicit surfaces

Sung-Eui Yoon ( 윤성의 )

Parameterization. Michael S. Floater. November 10, 2011

Curves and Surfaces Computer Graphics I Lecture 10

Lecture 2.2 Cubic Splines

Intro to Curves Week 1, Lecture 2

Curves. Computer Graphics CSE 167 Lecture 11

Computer Graphics Curves and Surfaces. Matthias Teschner

CS 536 Computer Graphics Intro to Curves Week 1, Lecture 2

The Free-form Surface Modelling System

Computer Graphics. Curves and Surfaces. Hermite/Bezier Curves, (B-)Splines, and NURBS. By Ulf Assarsson

CSE 167: Introduction to Computer Graphics Lecture 12: Bézier Curves. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

Lecture 9: Introduction to Spline Curves

OUTLINE. Quadratic Bezier Curves Cubic Bezier Curves

CSE 167: Introduction to Computer Graphics Lecture #13: Curves. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Central issues in modelling

Parameterization of triangular meshes

Remark. Jacobs University Visualization and Computer Graphics Lab : ESM4A - Numerical Methods 331

Rational Bezier Curves

Intro to Curves Week 4, Lecture 7

CS-184: Computer Graphics

Information Coding / Computer Graphics, ISY, LiTH. Splines

In this course we will need a set of techniques to represent curves and surfaces in 2-d and 3-d. Some reasons for this include

Need for Parametric Equations

LECTURE #6. Geometric Modelling for Engineering Applications. Geometric modeling for engineering applications

Handout 4 - Interpolation Examples

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

COMPUTER AIDED ENGINEERING DESIGN (BFF2612)

CS 450 Numerical Analysis. Chapter 7: Interpolation

15.10 Curve Interpolation using Uniform Cubic B-Spline Curves. CS Dept, UK

Curve Representation ME761A Instructor in Charge Prof. J. Ramkumar Department of Mechanical Engineering, IIT Kanpur

The goal is the definition of points with numbers and primitives with equations or functions. The definition of points with numbers requires a

08 - Designing Approximating Curves

Parametric curves. Brian Curless CSE 457 Spring 2016

Geometric Modeling of Curves

Computergrafik. Matthias Zwicker. Herbst 2010

CS130 : Computer Graphics Curves (cont.) Tamar Shinar Computer Science & Engineering UC Riverside

(Refer Slide Time: 00:02:24 min)

Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn.

CSE 167: Introduction to Computer Graphics Lecture #11: Bezier Curves. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Computational Physics PHYS 420

Introduction to Computer Graphics

CS770/870 Spring 2017 Curve Generation

Friday, 11 January 13. Interpolation

Computer Graphics. Unit VI: Curves And Fractals. By Vaishali Kolhe

MA 323 Geometric Modelling Course Notes: Day 31 Blended and Ruled Surfaces Coons Patches

Design considerations

For each question, indicate whether the statement is true or false by circling T or F, respectively.

ECE 600, Dr. Farag, Summer 09

Gardener s spline curve

Curves D.A. Forsyth, with slides from John Hart

CHAPTER 6 Parametric Spline Curves

Bézier Splines. B-Splines. B-Splines. CS 475 / CS 675 Computer Graphics. Lecture 14 : Modelling Curves 3 B-Splines. n i t i 1 t n i. J n,i.

Curves and Surfaces. CS475 / 675, Fall Siddhartha Chaudhuri

B-Spline Polynomials. B-Spline Polynomials. Uniform Cubic B-Spline Curves CS 460. Computer Graphics

Lecture IV Bézier Curves

CS-184: Computer Graphics. Today

NURBS: Non-Uniform Rational B-Splines AUI Course Denbigh Starkey

8 Project # 2: Bézier curves

TO DUY ANH SHIP CALCULATION

Computer Graphics Splines and Curves

Curves & Surfaces. Last Time? Progressive Meshes. Selective Refinement. Adjacency Data Structures. Mesh Simplification. Mesh Simplification

CS 475 / CS Computer Graphics. Modelling Curves 3 - B-Splines

MA 323 Geometric Modelling Course Notes: Day 21 Three Dimensional Bezier Curves, Projections and Rational Bezier Curves

Curves and Surfaces. Shireen Elhabian and Aly A. Farag University of Louisville

ME 261: Numerical Analysis Lecture-12: Numerical Interpolation

Rational Bezier Surface

B-spline Curves. Smoother than other curve forms

CS 4620 Final Exam. (a) Is a circle C 0 continuous?

Parametric curves. Reading. Curves before computers. Mathematical curve representation. CSE 457 Winter Required:

Curves and Surfaces. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd

To Do. Resources. Algorithm Outline. Simplifications. Advanced Computer Graphics (Spring 2013) Surface Simplification: Goals (Garland)

MA 323 Geometric Modelling Course Notes: Day 14 Properties of Bezier Curves

Background for Surface Integration

CS3621 Midterm Solution (Fall 2005) 150 points

while its direction is given by the right hand rule: point fingers of the right hand in a 1 a 2 a 3 b 1 b 2 b 3 A B = det i j k

Perspective Mappings. Contents

Approximation of 3D-Parametric Functions by Bicubic B-spline Functions

COMP3421. Global Lighting Part 2: Radiosity

Dgp _ lecture 2. Curves

8 Piecewise Polynomial Interpolation

Surface Modeling. Polygon Tables. Types: Generating models: Polygon Surfaces. Polygon surfaces Curved surfaces Volumes. Interactive Procedural

GEOMETRIC TOOLS FOR COMPUTER GRAPHICS

Chapter 6 Some Applications of the Integral

Shape Representation Basic problem We make pictures of things How do we describe those things? Many of those things are shapes Other things include

Transcription:

An introduction to interpolation and splines Kenneth H. Carpenter, EECE KSU November 22, 1999 revised November 20, 2001, April 24, 2002, April 14, 2004 1 Introduction Suppose one wishes to draw a curve in three dimensions. Then with most graphics systems one must approximate the curve as a series of straight line segments and give function calls to the graphics library for each vertex (at the beginning of the curve and at each joint between straight line segments). In most cases it would be excessive to store all these vertices in a graphics program. Instead, one wishes to store the information to draw the curve by giving a set of control points which appear the same to the user as vertices. Then a curve drawing function uses these control points to draw the curve as a set of short, straight line segments. There are several possibilities for using control points. If the curve passes through all the control points then it is said to interpolate the points. The mathematical function used to interpolate must be appropriate for what is being drawn. The most commonly used interpolation methods in computer graphics involve piecewise continuous cubics. For the sake of smoothness in the interpolated curve, one not only wants the curve to be continuous but to have continuous derivatives. In order to represent curves in three dimensions a parametric form is used. Then derivatives are taken with respect to the parameter. Continuity of some order of derivative with respect to the parameter is not necessarily the same as continuity of derivatives like dy/dx in the variables themselves. In the following, several ways of representing curves by control points will be examined. For each the questions of smoothness and continuity will be addressed, along with how close the representation of the desired curve is in other ways. 1.1 Mathematical representation The x, y, and z coordinates of the curve to be drawn are given by parametric functions: x = x(t), y = y(t), z = z(t), (1) where the parameter t ranges over a prescribed set of values. Derivatives are then, d n x/dt n, d n y/dt n, d n z/dt n, (2) for the n th derivative. When all three of these are continuous at a specific value of t then the curve is said to have C n continuity. The largest n for which this is true is said to be the continuity of the curve (on a parametric basis). 1

2 Polynomial interpolation When a set of N points is to be interpolated by a curve, one way to do it is to use a N-1 degree polynomial in t for each coordinate. This is usually unsatisfactory in appearance because of oscillations when N is greater than four. However there are special cases when N can be large because of other constraints on the polynomial. (Bézier curves) 2.1 Cubic polynomial interpolation through four points If the polynomial is to be cubic then we have for the equations in matrix form: X = [x(t) y(t) z(t)] = [1 t t 2 t 3 ] c 11 c 12 c 13 c 21 c 22 c 23 c 31 c 32 c 33 c 41 c 42 c 43 = TC. (3) To find the coefficient matrix C one needs the values on the curve at four points through which it passes. The conventional way to choose these points is for parameter values t = 0, 1/3, 2/3, 1. Obviously other values could be used and unequal spacing in t could be used. If these points are p 1 at t = 0, p 2 at t = 1/3, etc., then a matrix can be made of the control point coordinates: P = Then one can write the equation for C as where the matrix M 1 I p 1 p 2 p 3 p 4 = x 1 y 1 z 1 x 2 y 2 z 2 x 3 y 3 z 3 x 4 y 4 z 4. (4) P = M 1 I C (5) is made up of T for the values of t = 0, 1/3, 2/3, 1 to give M 1 I = 1 1/3 1/9 1/27 1 2/3 4/9 8/27 1 1 1 1 Now the coefficient matrix for the cubic is C = M I P. where the inverse of M 1 I M I = 11/2 9 9/2 1 9 45/2 18 9/2 9/2 27/2 27/2 9/2. (6) is. (7) Thus the graphics code to draw the curve loops on t in small increments from 0 to 1 calling the vertex function with vertices given by X = TM I P. 2.2 Matrix inverse for M I One can find matrix inverses by Gaussian elimination, or by using a computer tool such as octave: 2

elmo{khc} /classes/636/f99/prob:1> octave GNU Octave, version 2.0.14.92 (i386-pc-linux-gnu). Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type warranty. octave:1> A = [;1 1/3 1/9 1/27;1 2/3 4/9 8/27;1 1 1 1] A = 1.00000 0.00000 0.00000 0.00000 1.00000 0.33333 0.11111 0.03704 1.00000 0.66667 0.44444 0.29630 1.00000 1.00000 1.00000 1.00000 octave:2> M = A\eye(4) M = 1.00000 0.00000 0.00000 0.00000-5.50000 9.00000-4.50000 1.00000 9.00000-22.50000 18.00000-4.50000-4.50000 13.50000-13.50000 4.50000 octave:3> M*A ans = 1.00000 0.00000 0.00000 0.00000-0.00000 1.00000 0.00000 0.00000 0.00000-0.00000 1.00000 0.00000 0.00000 0.00000 0.00000 1.00000 octave:4> exit 2.3 Cubic spline interpolation When there are more than four points to be interpolated with cubics, one cannot just put a cubic through successive sets of four without having discontinuities in slope at the points where different cubic curves connect (at the so-called knots in the interpolation). But one can have not only continuous first derivatives but also continuous second derivatives at the knots if all the points are used in determining coefficients for all the needed cubics one for each section between points to be interpolated, in general. The result is called the cubic spline interpolant. Suppose there are N points to be interpolated and that their coordinates are labeled as x i, y i, and z i with i = 1, 2,... N. For the cubic between point i and point i + 1 let the parametric formula for x be x(t) = a i + b i t + c i t 2 + d i t 3, 0 t 1. (8) There will be similar equations for y(t) and z(t). There are N 1 segments between given points, so there are 4(N 1) coefficients to be found for the x(t) equations. 2(N 1) equations come from the 3

requirement that the cubics interpolate all the points: x i = a i, i = 1, 2,... N 1 (9) x i+1 = a i + b i + c i + d i, i = 1, 2,... N 1. (10) There are another N 2 equations for equating slopes at the interior points and another N 2 equations for equating 2nd derivatives at interior points: b i+1 = b i + 2c i + 3d i, i = 1, 2,... N 2 (11) c i+1 = c i + 3d i, i = 1, 2,... N 2. (12) Thus eqs.(9) through (12) provide 4N 6 equations for the 4N 4 unknown coefficients. The additional two values needed are the slopes at the first and the last point. These can be provided in several manners: 1. Give data specifying the slope at each end. 2. Take the slope at each end to be the slope of the straight line from the end point to the adjacent point. 3. Treat the points adjacent to the end points as not knots, that is make the same cubic interpolate the first three and last three points. This gives the needed two extra equations (the interpolation of the points next to the ends) for a spline with only N 3 segments. The matrix that would result from setting up these equations for solution would be large (4(N 1) square), but it would be sparse and banded. There are special numerical methods to handle such cases of systems of equations. The main drawback to the cubic spline interpolation is that changing one of the points interpolated will affect the appearance of the curve in segments far removed from the point changed. This lack of locality limits the usefulness of cubic spline interpolation in computer graphics. 3 Hermite cubic interpolation The problem with simple cubic polynomial interpolation through four points is that it only works well for four control points. With more than four, there will be only C 0 continuity at at least one of the joining points, called knots, between different cubics. This problem can be eliminated by the cubic spline interpolation of many points, but then locality of influence of points on the curve is lost. An alternative which provides locality and C 1 continuity is to specify both the points to be interpolated and the slope at the knots. One way to do this is with Hermite cubics. Hermite cubics are formed from four control numbers, but only two of them are the points to be interpolated. The other two are the slopes of the lines at these points. Thus one has to specify not only x(t) but also dx/dt at each point to be interpolated. The interpolation only goes between pairs of points before the cubic must be changed. But by specifying the same coordinate and slope for the end of one cubic and the beginning of the next, the complete curve has C 1 continuity. The matrix equation needed this time is X = TM H P H where P H is made up as follows: P H = x 1 y 1 z 1 x 2 y 2 z 2 dx dt 1 dx dt 2 4 dy dt 1 dy dt 2 dz dt 1 dz dt 2. (13)

To find M H, proceed as above for M I, but use dt/dt at point 1 and point 2 for the 3rd and 4th rows of M 1 H : and thus 4 Bézier curves M 1 H = M H = 1 1 1 1 0 1 0 0 0 1 2 3 0 0 1 0 3 3 2 1 2 2 1 1 (14). (15) The main difficulty with the Hermite cubic curves is the need to specify derivatives at points as well as coordinates. One can calculate derivatives by numerical differentiation if values are given for additional coordinates to be used in the numerical derivatives. The simplest version of this yields a cubic Bézier curve. 4.1 Cubic Bézier curves Suppose one gives four control points. The first and last are to be interpolated by a cubic, as with the Hermite curve. But the second and third are used to find the slopes at the first and last. The line from the first to second control point is assumed to correspond to changing parameter t from 0 to 1/3. The line from the third control point to the last is assumed to correspond to changing parameter t from 2/3 to 1. Thus we get the matrix of values needed for P H for the Hermite cubic curve from the control points P of the cubic Bézier curve (which is the same P as in eq.(4)) by multiplying them by a matrix to take the numerical derivative: P H = D B, P where D B = 0 0 0 1 3 3 0 0 0 0 3 3. (16) Thus the parametric equations for the cubic Bézier curve are X = TM B P with M B = M H D B or 3 3 0 0 M B =. (17) 3 6 3 0 1 3 3 1 4.2 Blending polynomials Any polynomial representation in the form X = TMP may by expressed as X = BP where B = TM is the matrix of blending polynomials. Thus one interprets the generation of the parametric equations for the curve as multiplying control points times blending polynomials. For the particular case of the cubic Bézier curve we have These curves are shown in Fig. 1. B B = [ (1 t) 3 3t(1 t) 2 3t 2 (1 t) t 3 ]. (18) 5

1 0.8 0.6 Blending polynomials for Bezier cubic (1-t) 3 3t(1-t) 2 3t 2 (1-t) t 3 0.4 0.2 0 0 0.2 0.4 0.6 0.8 1 t Figure 1: Cubic Bézier curve blending polynomials 4.3 Convex hulls and bounding boxes Note that the peculiar set of blending polynomials for the Bézier cubic, given in eq.(18), just happen to be the terms of the binomial expansion of [(1 t) + t] 3. (This is like (x + y) 3 with x = 1 t and y = t.) Because of this, the sum of the blending polynomials is always one for all t. This has the result that the curve, for all values of t, must lie within the convex hull defined by the control points. By definition, the convex hull for a parametric curve is the enclosing convex polyhedron having control points as vertices. Not all of the control points will necessarily be vertices of the convex polyhedron forming the convex hull. In two-dimensions, the convex hull is the convex polygon having control points as vertices and enclosing all control points. One can visualize the convex hull as the polygon formed by stretching a rubber band around pins placed on a drawing board at the locations of the vertices. Mathematically, one can show the convex hull property for a set of vertices as follows. Let the control points be represented by p i = [ x i y i z i ]. Now let X m be the control point having the minimum value of x = x m. When a parametric curve is obtained by taking a sum of control points times corresponding blending polynomials, X(t) = BP, with each blending polynomial being nonnegative, and with the sum of the blending polynomials being one, then for any t the x that results will be a weighted sum of the control point x i s and must always be greater or equal to x m. This argument can be repeated for the control point with the largest x value, and for the largest and smallest y and z values as well. This establishes that the curve lies in a rectangular bounding box. To change from this bounding box to the convex hull, one only need rotate coordinates until another control point has the maximum or minimum for such variables and find a new bounding box. The intersection of these bounding boxes will be the convex hull. 6

4.4 Bernstein basis functions and general Bézier curves The binomial expansion is (α + β) n = n i=0 Substitute α = 1 t and β = t in eq.(19) and we get n b n i (t) = 1, bn i = i=0 n! i!(n i)! αn i β i. (19) n! i!(n i)! ((1 t)n i t i. (20) The b n i (t) are the Bernstein basis functions of order n. Each is a nth degree polynomial. Thus the sum x(t) = n i=0 x i b n i (t) (21) is an nth degree polynomial parametric equation for coordinate x. Thus, the general Bézier curve for n + 1 control points is n X(t) = b n i (t)p i. (22) i=0 As with the Bézier cubic, the parametric curve interpolates the first and last control points and lies within the convex hull defined by the control points. 5 B-splines B-splines are a general classification of parametric curves defined by control points. The control is localized, and, in general, the curve does not interpolate any of the points. Cubic B-splines are widely used. They are mathematically similar to cubic Béizer curves but do not interpolate control points unless the same control point is repeated twice. They are formed by multiplying each control point by a basis function. The way they differ from the curves given in previous sections is that the parameter t is allowed to run over 0 to n, with n being related to the number of control points. The basis functions are defined to make them zero for t outside the range for which its control point is to have an effect. The knots of the cubics formed are at different coordinates than the control points. Further discussion of splines is beyond the scope of this introduction. See, Kenneth H. Carpenter, B-Splines, http://www.eece.ksu.edu/ khc/classes/636/bsplpdf.pdf, for more on this topic. 6 X-splines While B-Splines are widely used in computer graphics, especially in the form to NURBS, a more general form called X-splines may offer some advantages over B-splines. For a detailed description of X-Splines, see Carole Blanc and Christophe Schlick, X-Splines: A Spline Model Designed for the End-User, SIGGRAPH 95, Computer Graphics, pp. 377-386. (Currently this paper is available on the Internet at URL: http://www.acm.org/pubs/citations/proceedings/graph/218380/p377-blanc/) 7

7 Surface interpolation and approximation When a surface is desired instead of a curve, then there must be two parameters for the parametric representation: x(u, v), y(u, v), z(u, v). The method of forming such parametric functions is a straightforward extension of that used with curves. 7.1 Bi-cubic patches Hermite and Bézier cubics can be extended for surface as bi-cubic parametric functions. That is, for blending polynomials b i (t) one forms the parametric equations for the surface as sums of products b i (u)b j (v)p i, j. 7.2 Quadrics While cubics are most often used to get pleasing curves, for solids, use of quadratic functions in all three variables, called quadrics, are simpler and often suitable for representing solids. A quadric surface is not represented in parametric form but as a function of three variables set to zero: 0 = f (x, y, z) = [ x y z 1 ] c 11 c 12 c 13 c 14 c 21 c 22 c 23 c 24 c 31 c 32 c 33 c 34 c 41 c 42 c 43 c 44 x y z 1. (23) A quadric requires ten constants to define it. (Since the upper and lower off diagonal terms in the matrix multiply the same combinations of the variables, either the upper or lower constants may be taken to be zero.) A quadric can be a sphere, a cylinder, an ellipsoid, etc. 8 Exercises 1. Given two points: p 1 = (1.1, 2.1, 3) and p 2 = (3.1, 0, 1), and given that the derivatives, dx/dt, etc., are all zero at these points, find the Hermite cubic interpolant curve, as a formula for all of x(t), y(t), and z(t), which passes through these points with the specified derivative. What can be said about the physical slopes such as dy/dx when the parametric slopes are all zero? Find the numerical values of the coordinates on the interpolated curve for t = 1/3 and t = 2/3. 2. Given two points: p 1 = (1.1, 2.1, 3) and p 2 = (3.1, 0, 1), and given that the derivatives, dx/dt, etc., are all one at these points, find the Hermite cubic interpolant curve, as a formula for all of x(t), y(t), and z(t), which passes through these points with the specified derivative. 3. Plot, in the z = 0 plane, the projection of the curves (for 0 t 1) for exercises 1 and 2. (Use gnuplot, ignore the z function. Put both curves on the same axes.) 8