Está en la página 1de 10

Numerical Methods for Computational Science and Engineering

Numerical Methods for Computational Science


and Engineering
Lecture 10, Oct 22, 2012: Bezier curves, tensor splines
Peter Arbenz
Computer Science Department, ETH Z urich
E-mail: arbenz@inf.ethz.ch
NumCSE, Lecture 10, Oct 22, 2012 1/38
Numerical Methods for Computational Science and Engineering
Topics today
Bezier curves
A Bezier curve is a parametric curve frequently used in
computer graphics and related elds.
In vector graphics, Bezier curves are used to model smooth
curves that can be scaled indenitely. Paths, as they are
commonly referred to in image manipulation programs, are
combinations of linked Bezier curves.
Bezier curves were publicized 1962 by the French engineer
Pierre Bezier, who used them to design automobile bodies.
But the study of these curves was rst developed in 1959 by
mathematician Paul de Casteljau using a numerically stable
algorithm to evaluate Bezier curves.
2-dimensional tensor splines
NumCSE, Lecture 10, Oct 22, 2012 2/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials
From the binomial theorem we have for any n
1 = ((1 t) + t)
n
=
n

i =1
_
n
i
_
(1 t)
ni
t
i
.
The Bernstein polynomials of degree n on the interval [0, 1] are
dened as
B
i ,n
(t) :=
_
n
i
_
(1 t)
ni
t
i
, i = 0, 1, . . . , n. (1)
They form a partition of unity:
n

i =1
B
i ,n
(t) = 1.
NumCSE, Lecture 10, Oct 22, 2012 3/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
The Bernstein polynomials of degree 1 are
B
0,1
(t) = (1 t), B
1,1
(t) = t.
The Bernstein polynomials of degree 2 are
B
0,2
(t) = (1 t)
2
, B
1,2
(t) = 2(1 t)t, B
2,2
(t) = t
2
.
NumCSE, Lecture 10, Oct 22, 2012 4/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
Bernstein polynomials of degree 6.
NumCSE, Lecture 10, Oct 22, 2012 5/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
To obtain the Bernstein polynomials of degree n on an arbitrary
interval [a, b] we use the transformation
u [a, b] t [0, 1] : t =
u a
b a
to get
B
i ,n
(u; a, b) := B
i ,n
_
u a
b a
_
=
1
(b a)
n
_
n
i
_
(b u)
ni
(u a)
i
.
NumCSE, Lecture 10, Oct 22, 2012 6/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
Almost evident properties of Bernstein polynomials:
1. t = 0 is an i -fold zero of B
i ,n
2. t = 1 is an n i -fold zero of B
i ,n
3. B
i ,n
(t) = B
ni ,n
(1 t) (symmetry)
4. 0 B
i ,n
(t) 1 for all t [0, 1],
B
i ,n
(t) > 0 for all t (0, 1).
5. In the interval [0, 1], B
i ,n
(t) has precisely one maximum at
t = i /n.
NumCSE, Lecture 10, Oct 22, 2012 7/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
Theorem (recurrence relations)
Bernstein polynomials satisfy the following recurrences:
B
0,n
(t) = (1 t)B
0,n1
(t),
B
i ,n
(t) = t B
i 1,n1
(t) + (1 t) B
i ,n1
(t),
i = 1, . . . , n 1,
B
n,n
(t) = tB
n1,n1
(t).
()
NumCSE, Lecture 10, Oct 22, 2012 8/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
Proof of recurrence relations.
t B
i 1,n1
(t) + (1 t) B
i ,n1
(t)
= t
(n 1)!
(n 1 i + 1)!(i 1)!
(1 t)
ni
t
i 1
+ (1 t)
(n 1)!
(n 1 i )!i !
(1 t)
n1i
t
i
=
_
(n 1)!i
(n i )!(i 1)!i
+
(n 1)!(n i )
(n 1 i )!i !(n i )
_
(1 t)
ni
t
i
= B
i ,n
(t)
NumCSE, Lecture 10, Oct 22, 2012 9/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Bernstein polynomials (cont.)
Theorem (linear independence)
The polynomials {B
i ,n
(t)}
n
i =0
are linearly independent and form a
basis of P
n
.
By consequence: any polynomial p P
n
can be written as
p(t) =
n

i =1

i
B
i ,n
(t). (+)
Denition
Eq. (+) is called Bezier representation of p.
The
i
are the Bezier coecients.
The points (i /n,
i
) are called Bezier points.
The connection of the Bezier points is called Bezier polygon.
NumCSE, Lecture 10, Oct 22, 2012 10/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Example
Control points: (0, 0), (1/3, 1), (2/3, 1), (1, 1)
Bezier polynomial p(t) = t
3
+ 3t
2
3t.
NumCSE, Lecture 10, Oct 22, 2012 11/38
Numerical Methods for Computational Science and Engineering
Bernstein and Bezier polynomials
Example (cont.)
Theorem
The graph of the Bezier polynomials is in the convex hull of
the Bezier points.
The graph of a polynomial and its Bezier polygon meet at the
end points t = 0 and t = 1 and have equal slopes.
In fact:
p

(t) =
n

i =0

i
_
n
i
_
d
dt
[(1 t)
ni
t
i
]
=
0
[n(1 t)
n1
] +
1
n[(n 1)(1 t)
n2
t + (1 t)
n1
] + . . .
p

(0) = n(
1

0
)
NumCSE, Lecture 10, Oct 22, 2012 12/38
Numerical Methods for Computational Science and Engineering
Casteljau algorithm
Casteljau algorithm
The Casteljau algorithm is an algorithm to compute value of the
Bezier polynomial. It exploits the recurrences ().
Let p(t) =

n
i =0

i
B
i ,n
(t) be a Bezier polynomial. Then
p(t) =
n

i =0

i
B
i ,n
(t)
=
0
(1 t)B
0,n1
(t) +
n1

i =1

i
[t B
i 1,n1
(t) + (1 t) B
i ,n1
(t)]
+
n
tB
n1,n1
(t)
=
n1

i =0
[
i
(1 t) +
i +1
t]B
i ,n1
(t).
NumCSE, Lecture 10, Oct 22, 2012 13/38
Numerical Methods for Computational Science and Engineering
Casteljau algorithm
Casteljau algorithm (cont.)
p(t) =
n

i =0

i
B
i ,n
(t)
=
n1

i =0
[
i
(1 t) +
i +1
t]B
i ,n1
(t)
n1

i =0

(1)
i
B
i ,n1
(t)
=
n2

i =0

(2)
i
B
i ,n2
(t)
= =
=
(n)
0
with
(k)
i
=
(k1)
i
(1 t) +
(k1)
i +1
t.
NumCSE, Lecture 10, Oct 22, 2012 14/38
Numerical Methods for Computational Science and Engineering
Casteljau algorithm
Casteljau algorithm (cont.)
Geometric interpretation:
The point (x
(1)
i
, y
(1)
i
) with
x
(1)
i
= (1t)
i
n
+t
i + 1
n
=
i + t
n
, y
(1)
i
=
(1)
i
= (1t)
i
+
i +1
t
lies on the straight line between (
i
n
,
i
) and (
i +1
n
,
i +1
)
(on the Bezier polygon).
The point (x
(2)
i
, y
(2)
i
) with
x
(2)
i
= (1 t)x
(1)
i
+ tx
(1)
i +1
, y
(2)
i
= (1 t)y
(1)
i
+ y
(1)
i +1
t
etc.
NumCSE, Lecture 10, Oct 22, 2012 15/38
Numerical Methods for Computational Science and Engineering
Casteljau algorithm
Casteljau algorithm (cont.)
NumCSE, Lecture 10, Oct 22, 2012 16/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Bezier curves
Bezier curves are polynomial curves represented in the basis of
Bernstein polynomials:
P
n
(t) =
n

i =0
B
i ,n
(t)P
i
, t [0, 1]
where B
i ,n
(t) is the Bernstein polynomial of degree n. Each
component of P
n
(t) is a Bezier polynomial!
The points P
i
are called control points of the Bezier curve.
Given 2 points P
0
and P
1
the Bezier curve of degree 1 is the
straight line
P
1
(t) = (1 t)P
0
+ tP
1
joining the two points.
NumCSE, Lecture 10, Oct 22, 2012 17/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Bezier curves (cont.)
Given three points P
0
, P
1
and P
2
the Bezier curve of degree 2 is
P
2
(t) = (1 t)
2
P
0
+ 2(1 t)tP
1
+ t
2
P
2
.
P
2
(0) = P
0
and P
2
(1) = P
2
so that the curve interpolates the end
points. However, P
1
is not part of the curve.
Furthermore:
P

2
(0) = 2P
0
+ 2P
1
,
P

2
(1) = 2P
1
+ 2P
2
,
such that the derivative of the Bezier curve is proportional to that
of the Bezier through polygon the control points.
NumCSE, Lecture 10, Oct 22, 2012 18/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Bezier curves (cont.)
Theorem
The set of points of a Bezier curve
_
P(t) =
n

i =0
B
i ,n
(t)P
i
, t [0, 1]
_
is contained in the convex hull of the Bezier points P
0
, P
1
, , P
n
.
Theorem
For the end points of a Bezier curve we have
P(0) = P
0
, P(1) = P
n
P

(0) = n(P
1
P
0
), P

(1) = n(P
n
P
n1
).
NumCSE, Lecture 10, Oct 22, 2012 19/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Example
The Bezier curve of
degree three dened by
the control points
(2, 1), (3, 8), (8, 7), (10, 3)
NumCSE, Lecture 10, Oct 22, 2012 20/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Algorithm of de Casteljau
The following Matlab function bezier computes a point on the
Bezier curve with the de Casteljau algorithm.
function [y] = bezier(t,P)
% BEZIER evaluates the Bezier polynomial defined
% by the control points P for parameter t
% using the de Casteljau scheme
[m,n] = size(P); n=n-1;
T = zeros(m,n+1,n+1);
for i = 0:n
T(:, i+1,1) = P(:,i+1);
for j = 1:i
T(:,i+1,j+1) = (1-t)*T(:,i,j) + t*T(:,i+1,j);
end;
NumCSE, Lecture 10, Oct 22, 2012 21/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Algorithm of de Casteljau (cont.)
end;
y = T(:,n+1, n+1);
Here, a 3-dimensional Matlab array T is used to represent the
Casteljau scheme. For the control points of the previous example
P =
2 3 8 10
1 8 7 3
Calling U = bezier(0.5,P) gives the following:
NumCSE, Lecture 10, Oct 22, 2012 22/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Algorithm of de Casteljau (cont.)
T(:,:,1) =
2 3 8 10
1 8 7 3
T(:,:,2) =
0 2.5000 5.5000 9.0000
0 4.5000 7.5000 5.0000
T(:,:,3) =
0 0 4.0000 7.2500
0 0 6.0000 6.2500
T(:,:,4) =
0 0 0 5.6250
0 0 0 6.1250
NumCSE, Lecture 10, Oct 22, 2012 23/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Algorithm of de Casteljau (cont.)
U =
5.6250
6.1250
The point U = (5.6250, 6.1250) computed for t = 0.5 is marked on
the Bezier curve of degree 3 in the previous example/gure by .
NumCSE, Lecture 10, Oct 22, 2012 24/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Ecient evaluation of P(t)
We have
P(t) =
n

i =0
B
i ,n
(t)P
i
= [P
0
, P
1
, . . . , P
n
]
_
_
_
_
_
B
0,n
(t)
B
1,n
(t)
.
.
.
B
n,n
(t)
_
_
_
_
_
Let B
i ,n
(t) =

n
i =0
b
ij
t
nj
. Then,
P(t) = [P
0
, P
1
, . . . , P
n
]B
n
_
_
_
_
_
t
n
t
n1
.
.
.
1
_
_
_
_
_
, B
n
= ((b
ij
))
NumCSE, Lecture 10, Oct 22, 2012 25/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Ecient evaluation of P(t) (cont.)
Numerical example continued:
P
3
(t) =
_
x(t)
y(t)
_
=
_
2 3 8 10
1 8 7 3
_
_
_
_
_
1 3 3 1
3 6 3 0
3 3 0 0
1 0 0 0
_
_
_
_
_
_
_
_
t
3
t
2
t
1
_
_
_
_
=
_
7 12 3 2
5 24 21 1
_
_
_
_
_
t
3
t
2
t
1
_
_
_
_
=
___
7
5
_
t +
_
12
24
__
t +
_
3
21
__
t +
_
2
1
_
NumCSE, Lecture 10, Oct 22, 2012 26/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Segmented Bezier curves
In real applications Bezier curves can usually not be generated
by a single curve. They are composed of segments.
Continuity is easy to achieve: The last control point of one
segment, say j , has to be equal to the rst control point of
the next segment j + 1.
The continuity of the derivative requires that the second to
last control point of segment j , the second control point of
segment j + 1 and the control point common to segments j
and j + 1 lie on a line.
The distances of these points is determined by the length of
the segments.
NumCSE, Lecture 10, Oct 22, 2012 27/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Segmented Bezier curves (cont.)
Let the number of segments be m.
On each segment there is a Bezier curve of equal degree n.
The whole curve is parametrized by parameter u:
u
0
< u
1
< u
2
< < u
m1
< u
m
.
On the j th segment [u
j 1
, u
j
] the curve can be written as
P
j
(u) =
n

i =0
P
ij
B
in
(u; u
j 1
, u
j
), u [u
j 1
, u
j
].
where P
0j
, P
1j
, . . . , P
nj
are the Bezier points.
NumCSE, Lecture 10, Oct 22, 2012 28/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Segmented Bezier curves (cont.)
Continuity from segment j to segment j + 1 is guaranteed if
P
n,j
= P
0,j +1
Since
d
du
B
in
(u; u
j 1
, u
j
) =
d
du
B
in
_
u u
j 1
u
j
u
j 1
_
=
d
dt
B
in
(t)
1
h
j
,
we get with the theorem on page 21:
n(P
n,j
P
n1,j
)/h
j
= n(P
1,j +1
P
0,j +1
)/h
j +1
.
P
n,j
= P
0,j +1
=P
n,j
=
h
j +1
h
j
+ h
j +1
P
n1,j
+
h
j
h
j
+ h
j +1
P
1,j +1
Continuity of higher derivatives can be enforced similarly.
NumCSE, Lecture 10, Oct 22, 2012 29/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Example
Want to approximate quarter of unit circle by (one segment)
of Bezier curve.
NumCSE, Lecture 10, Oct 22, 2012 30/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Example (cont.)
P(t) =
3

i =0
P
i
B
i 3
(t)
=
_
1
0
_
(1 t)
3
+
_
1

_
3(1 t)
2
t +
_

1
_
3(1 t)t
2
+
_
0
1
_
t
3
How to choose ? Lets try to have the Bezier curve meet the
circle at t = 1/2:
_
1 1 0
0 1 1
_
1
8
_
_
_
_
1
3
3
1
_
_
_
_
=
__
1/2
_
1/2
_
= 3+4 = 8
_
1/2 = =
1
3
(8
_
1/24) 0.552285.
NumCSE, Lecture 10, Oct 22, 2012 31/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Examples of segmented Bezier curves
Prole of an airfoil.
Most pictures today from Schwarz/Kockler: Numerische Mathematik.
Springer.
NumCSE, Lecture 10, Oct 22, 2012 32/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Examples of segmented Bezier curves (cont.)
NumCSE, Lecture 10, Oct 22, 2012 33/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Bezier surfaces
Similarly as curves it is possible to dene surfaces in 3D:
Let P
ij
, i = 0, 1, . . . , n; j = 0, 1, . . . , m be 3-dimensional vectors.
We dene a surface by
x(s, t) :=
n

i =0
m

j =0
P
ij
B
in
(s)B
jm
(t), s, t [0, 1].
B
in
and B
jm
are Bernstein polynomials of the proper degree.
NumCSE, Lecture 10, Oct 22, 2012 34/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Tensor splines
Let (x
i
, y
j
), i = 0, 1, . . . , n; j = 0, 1, . . . , m be a regular grid.
Let B
i
(x), B
j
(y) be the piecewise linear functions that satisfy
B
i
(x
k
) =
ik
, B
j
(x

) =
j
.
We can interpolate a function f dened on [x
0
, x
n
] [y
0
, y
m
] by
n

i =0
m

j =0
f(x
i
, y
j
)B
i
(x)B
j
(y), (x, y) [x
0
, x
n
] [y
0
, y
m
]
Inside a rectangle [x
i
, x
i +1
] [y
j
, y
j +1
] this function is bilinear, i.e.
of the form
+ x + y + xy.
The 4 values , , , are determined by the 4 values of f at the
corners of the rectangle.
NumCSE, Lecture 10, Oct 22, 2012 35/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Tensor splines (cont.)
Piecewise
bilinear basis
function.
This is the
way
Matlab
works.
NumCSE, Lecture 10, Oct 22, 2012 36/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Tensor splines (cont.)
In the same way we can interpolate with piecewise cubic Hermite
polynomials which gives a smooth interpolant. We can also take
derivatives
f
x
(x
i
, y
j
),
f
y
(x
i
, y
j
),

2
f
xy
(x
i
, y
j
),
into account.
NumCSE, Lecture 10, Oct 22, 2012 37/38
Numerical Methods for Computational Science and Engineering
Bezier curves
Tensor splines (cont.)
Piecewise
bicubic basis
function.
NumCSE, Lecture 10, Oct 22, 2012 38/38

También podría gustarte