Download presentation
1
Numerical Computation
Lecture 14: Bezier Curves United International College
2
Last Time During the last class period we covered: Cubic Splines
Readings: Pav, section 6.2 (omit 6.2.1)
3
Today We will cover: Bezier Curves Readings: These Slides !!
4
Review So far we have looked at the question of finding a polynomial (or set of polynomials) to interpolate a set of data points {xk ,yk} We have come up with two ways to find a single interpolating polynomial for the data: Lagrange method and Newton’s method. We have computed spline curves that interpolate the data over a partition.
5
Drawbacks to These Methods
These methods are quite useful for a variety of applications, but they have two major drawbacks: 1) They cannot model data that have duplicate y – values
6
Drawbacks to These Methods
2) The final shape of the curve is completely dependent on the data. It would be nice to be able to better control the shape of the interpolating curve without having to move data points.
7
Bezier Curves Bezier Curves can solve both of these problems !
Definition: A Bezier curve is a parametric curve described by polynomials based on control points. Any number of control points may be used. (usually 4) Degree of polynomials = number of points – 1. (usually =3) Several Bezier curves can easily be glued together in a way that makes the curve as a whole smooth. A Bezier curve passes through its first and last control points, but, in general, no others.
8
Parametric Curves Definition: A parametric curve is a vector function of a single argument (t). The variable t is called the parameter. Example: p(t) = (x(t), y(t)) is a parametric curve in the plane. Example: p(t) = (x(t), y(t), z(t)) is a parametric curve in space. Example: p(t) = (cos(t), sin(t)) for 0 ≤ t ≤ π produces a circle.
9
Parametric Curves Example: x(t) = t2–2t, y(t) = t–1, t in [0,3].
By using parametric curves we can create curves with multiple y-values for a given x-value. This solves the first problem discussed above as Drawback 1). y t = 3 (end) (t2–2t, t–1) x t = 0 (start)
10
Parametric Curves Other Benefits of using Parametric Curves:
Every curve can be described as a parametric curve. A parametric curve can be easily computed. A parametric curve is a useful description of motion. We think of the parameter as representing time (thus, “t”).
11
Parametric Curves - Motion
Given a parametric curve p(t) = (x(t), y(t)) p’(t) = (x’(t), y’(t)) velocity vector points in direction of motion p’(t)/||p’(t)|| unit tangent (velocity) vector ||p’(t)|| speed p’(t) p(t) t = 0 t = 1
12
Bezier Curves Bezier curves are parametric curves, where each of the parametric functions for x(t) and y(t) are polynomials in t (typically degree 2 or 3). Quadratic Bezier Curve: x(t) and y(t) are quadratic polynomials in t. (0 ≤ t ≤ 1) Cubic Bezier Curve: x(t) and y(t) are cubic polynomials in t. (0 ≤ t ≤ 1) x(t) = at3 + bt2 + ct + d y(t) = et3 + ft2 + gt + h
13
Bezier Curves x(t) = at3 + bt2 + ct + d Cubic Bezier Curve: •
p1=(x1,y1) Cubic Bezier Curve: x(t) = at3 + bt2 + ct + d y(t) = et3 + ft2 + gt + h (0 ≤ t ≤ 1) A Bezier curve passes through its first and last control points, so x0 = x(0) y0 = y(0) x3 = x(1) y3 = y(1) How do we find the other points (x(t),y(t)) on the curve? • p2=(x2,y2) (x(t),y(t)) p0=(x0,y0) p3=(x3,y3)
14
de Casteljau Algorithm
p1 The de Casteljau algorithm calculates the points on a Bezier Curve as a recursive series of linear interpolations. (“Lerps”) Step 1: q1 q0 p0 p2 q2 p3
15
de Casteljau Algorithm
Step 2: q1 r0 q0 r1 q2
16
de Casteljau Algorithm
Step 3: r0 • r1 p(t)=(x(t),y(t))
17
de Casteljau Algorithm
Expanding this recursive formula gives:
18
de Casteljau Algorithm
Collecting powers of t and simplifying, we get Note: p(0) = p0 and p(1) = p3, so this curve does go through the first and last control points, as was required.
19
Bezier Curve p1 • p(t) p0 p2 p3
20
Bernstein Polynomials
The polynomials that appear as coefficients of the powers of t are called Bernstein Polynomials.
21
Bernstein Polynomials
22
Bernstein Polynomials
B03(t) B33(t) B13(t) B23(t)
23
Bernstein Polynomials
24
Bernstein Polynomials
Definition: The i-th Bernstein polynomial of degree n is defined as Note: If we add up all of the Bernstein polynomials of degree n, we always get 1, no matter what t is.
25
Bezier Curves Bernstein Formula for a Bezier curve of degree n:
26
Bezier Curves Bernstein Formula for a cubic Bezier curve:
27
Matrix Form of Bezier Curves
So far we have looked at two methods for computing the Bezier curve: de Casteljau’s Algorithm and Bernstein Polynomials. Now, we will consider a third method, which is the most efficient method. This method involves matrix calculations. Recall the equations for the cubic Bezier curve:
28
Matrix Form of Bezier Curves
If we re-group the terms, so that we have all multipliers of powers of t, we get:
29
Matrix Form of Bezier Curves
30
Matrix Form of Bezier Curves
31
Matrix Form of Bezier Curves
32
Matlab Function for Bezier Curves
function p = bezier(t, p0, p1, p2, p3 ) % bezier computes the bezier curve value p(t) % defined by control points p0, p1, p2, p3 u=[t^3 t^2 t 1]; M = [-1, 3,-3, 1; 3,-6, 3, 0; -3, 3, 0, 0; 1, 0, 0, 0] C = [p0;p1;p2;p3] p=u*M*C end
33
Matlab Function for Bezier Curves
function plot_bezier(p0,p1,p2,p3) %plot_bezier plots the bezier curve through the control % points p0, p1, p2, p3 tvector = 0.0:0.05:1; pts = zeros(length(tvector),2); for i = 1:length(tvector) pts(i,:) = bezier(tvector(i), p0, p1, p2, p3); end C = [p0;p1;p2;p3]; plot(C(:,1), C(:,2),'o',pts(:,1),pts(:,2),'-');
34
Matlab Function for Bezier Curves
35
Bezier Surfaces Bezier surfaces are an extension of Bezier curves to 3 dimensions Instead of the curve being parameterized by a single variable t, we use two variables, s and t By definition, we choose to have s and t range from 0 to 1 0,1 t 1,1 0,0 s 1,0
36
Control Mesh Consider a bicubic Bezier surface (bicubic means that it is a cubic function in both the s and t parameters) A cubic curve has 4 control points, and a bicubic surface has a grid of 16 control points, p0 through p15 p12 p13 p8 t p9 p14 p4 p5 p15 p0 p10 p1 p11 p6 s p7 p2 p3
37
Bernstein Polynomial Recall that for a Bezier curve we had a formula in terms of the Bernstein polynomials: It seems reasonable to define the Bezier surface in a similar fashion so that the surface is really a family of Bezier curves:
38
Matrix Form Recall that the matrix form for a Bezier curve is
A parametric surface will have three component functions of s and t – one for each of the three dimensions: p(s,t) = (x(s,t), y(s,t), z(s,t))
39
Matrix Form To simplify the calculation of the parametric surface, we will consider the matrix equation for each of the x, y, and z components separately For example, to evaluate the x component of a Bezier curve, we have:
40
Matrix Form If we expand the Bernstein formula
and isolate the x component of p(s,t) we will get (after a lot of arithmetic!)
41
Matrix Form
42
Matrix Form We would have similar formulas for y(s,t) and z(s,t).
Notes: Cx stores the coefficients of the bicubic equation for x Gx stores the geometry (x components of the control points) BBez is the basis matrix (Bezier basis) s and t are the vectors formed from the exponents of s and t The matrix form can also take advantage of 4x4 matrix support which is built into modern computer graphics hardware
43
Programming Assignment
Your Programming Assignment is to create two Matlab functions: bezier_surf(s,t,G) This will take two parameters s and t and a 4x4x3 matrix G and will return the vector p(s,t) = (x(s,t), y(s,t), z(s,t)) bezier_surf_plot(G) This will take one parameter – a 4x4x3 matrix G and will plot the Bezier surface defined by these points.
44
Programming Assignment
To assist you in this work, I have included code on the lecture web page that shows how to input and work with a 4x4x3 matrix and gives an example you should use for the matrix G. It also shows what kind of output you should expect. The surface plot should look like the figure on the next page:
45
Programming Assignment
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.