790 likes | 1.09k Views
MAE 152 Computer Graphics for Scientists and Engineers. Splines and Bezier Curves. Introduction. |Representing Curves A number of small line-segments joined Interpolation Parametric equations Types of curve we study Natural Cubic Splines and Bezier Curves Derivation Implementation.
E N D
MAE 152Computer Graphics for Scientists and Engineers Splines and Bezier Curves
Introduction • |Representing Curves • A number of small line-segments joined • Interpolation • Parametric equations • Types of curve we study • Natural Cubic Splines and Bezier Curves • Derivation • Implementation
“Computers can’t draw curves.” The more points/line segments that are used, the smoother the curve.
Why have curves ? • Representation of “irregular surfaces” • Example: Auto industry (car body design) • Artist’s representation • Clay / wood models • Digitizing • Surface modeling (“body in white”) • Scaling and smoothening • Tool and die Manufacturing
Curve representation • Problem: How to represent a curve easily and efficiently • “Brute force and ignorance” approaches: • storing a curve as many small straight line segments • doesn’t work well when scaled • inconvenient to have to specify so many points • need lots of points to make the curve look smooth • working out the equation that represents the curve • difficult for complex curves • moving an individual point requires re-calculation of the entire curve
Define a small number of points • Use a technique called “interpolation” to invent the extra points for us. • Join the points with a series of (short) straight lines Solution - Interpolation
The need for smoothness • So far, mostly polygons • Can approximate any geometry, but • Only approximate • Need lots of polygons to hide discontinuities • Storage problems • Math problems • Normal direction • Texture coordinates • Not very convenient as modeling tool • Gets even worse in animation • Almost always need smooth motion
Geometric modeling • Representing world geometry in the computer • Discrete vs. continuous again • At least some part has to be done by a human • Will see some automatic methods soon • Reality: humans are discrete in their actions • Specify a few points, have computer create something which “makes sense” • Examples: goes through points, goes “near” points
Requirements • Want mathematical smoothness • Some number of continuous derivatives of P • Local control • Local data changes have local effect • Continuous with respect to the data • No wiggling if data changes slightly • Low computational effort
A solution • Use SEVERAL polynomials • Complete curve consists of several pieces • All pieces are of low order • Third order is the most common • Pieces join smoothly • This is the idea of spline curves • or just “splines”
Parametric Equations - linear Walk from P0 to P1 at a constant speed. Start from P0 at t=0 Arrive at P1 at t=1 dx = x1 - x0 dy = y1 - y0 Where are you at a general time t? x(t) = x0 + t.dx y(t) = y0 + t.dy Equation(s) of a straight line as a function of an arbitrary parameter t.
Why use parametric equations? • One, two, three or n-dimensional representation is possible • Can handle “infinite slope” of tangents • Can represent multi-valued functions
For this class … • Natural Cubic Spline • Bezier Curves
Splines • Define the “knots” • (x0,y0) - (x3,y3) • Calculate all other points
Continuity • Parametric continuity Cx • Only P is continuous: C0 • Positional continuity • P and first derivative dP/du are continuous: C1 • Tangential continuity • P + first + second: C2 • Curvature continuity • Geometric continuity Gx • Only directions have to match
Order of continuity (a) (b) (c)
Wiggling effect • Example: • Four data points • Third degree polynomial • Might look something like: • This the ONLY third degree polynomial which fits the data • Wiggling gets much worse with higher degree
Polynomial parametric equations • To represent a straight line - linear parametric equation (i.e. one where the highest power of t was 1). • For curves, we need polynomial equations. Why? Because the graphs of polynomial equations wiggle!
Natural Cubic Spline • spline, n. 1A long narrow and relatively thin piece or strip of wood, metal, etc. 2A flexible strip of wood or rubber used by draftsmen in laying out broad sweeping curves, as in railroad work. • A natural spline defines the curve that minimizes the potential energy of an idealized elastic strip.
A natural cubic spline defines a curve, in which the points P(u)that define each segment of the spline are represented as a cubic P(u) =a0 + a1u + a2u2 + a3u3 • Where u is between 0 and 1 and a0, a1, a2 and a3 are (as yet) undetermined parameters. • We assume that the positions of n+1 control points Pk, where k = 0, 1,…, n are given, and the 1st and 2nd derivatives of P(u) are continuous at each interior control point.
Why cubic? • Undesirable wiggles and oscillations for higher orders • The lowest order polynomials to satisfy the following conditions Caution! Heavy math ahead!
A parametrically defined curve Parameterization
“Re-parameterization” non-uniform
Interpolation Approximation Interpolation versus Approximation
Hermite Interpolation 1 2 3 4 5
Hermite Spline • Say the user provides • A cubic spline has degree 3, and is of the form: • For some constants a, b, c and d derived from the control points, but how? • We have constraints: • The curve must pass through x0 when t=0 • The derivative must be x’0 when t=0 • The curve must pass through x1 when t=1 • The derivative must be x’1 when t=1
Hermite Spline A Hermite spline is a curve for which the user provides: • The endpoints of the curve • The parametric derivatives of the curve at the endpoints • The parametric derivatives are dx/dt, dy/dt, dz/dt • That is enough to define a cubic Hermite spline, more derivatives are required for higher order curves
Hermite Spline • Solving for the unknowns gives: • Rearranging gives: or
Hermite curves in 2D and 3D • We have defined only 1D splines: x = f(t:x0,x1,x’0,x’1) • For higher dimensions, define the control points in higher dimensions (that is, as vectors)
Basis Functions • A point on a Hermite curve is obtained by multiplying each control point by some function and summing • The functions are called basis functions
An interpolating cubic spline Hermite and Cubic Spline Interpolation
need two more Eq’s to determine all coefficients Spline Interpolation Natural Spline
Closed Curves Homework
Bezier Curves • An alternative to splines • M. Bezier was a French mathematician who worked for the Renault motor car company. • He invented his curves to allow his firm’s computers to describe the shape of car bodies.
Bezier curves • Typically, cubic polynomials • Similar to Hermite interpolation • Special way of specifying end tangents • Requires special set of coefficients • Need four points • Two at the ends of a segment • Two control tangent vectors
Bezier curves • Control polygon: control points connected to each other • Easy to generalize to higher order • Insert more control points • Hermite – third order only
De Casteljau algorithm • Can compute any point on the curve in a few iterations • No polynomials, pure geometry • Repeated linear interpolation • Repeated order of the curve times • The algorithm can be used as definition of the curve
Third order, u=0.75 De Casteljau algorithm
What does it mean ? 1 0 1