Professional Documents
Culture Documents
Bezier
Bezier
Bezier
Introduction
• |Representing Curves
– Curves are just lots of small straight lines joined up
• Interpolation
• Parametric equations
• Types of curve
– Consider two: Splines and Bezier Curves
• Derivation
• Implementation
Computers can’t draw curves
dx = x1 - x0
We now have the equation(s) of a
straight line written as a function of some dy = y1 - y0
parameter t.
x(t) = x0 + t.dx
y(t) = y0 + t.dy
Let us just confirm that
spline
knots
Polynomial parametric eqns
• 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!
Cubic parametic eqns
• The general form of a cubic parametric
equation (in t) is:
• xt = a0 + a1t + a2t2 + a3t3
• similarly for y
• We want xt
• We control t
• We therefore need values for a0, a1, a2 & a3
– Likewise for b0 etc.
Obtaining a0, a1, a2 & a3
• How do we make it
wiggle where we Ni Ni+1
want?
Si Si+1
Ni-1
• Consider two
contiguous
segments: Si and Si+1
Eqn 36 (from CGvJ – Ch. 9)
• Each segment is represented by a separate cubic
parametric eqns (only x shown):
• In Si
• In Si+1
xt a0 a1t a2 t a3t
2 3
dt
dx
1 a 2 a 2 t 3a3 t 2
dt
2. The joint is continuous
• Again consider what happens at Ni
– At Ni in segment Si: t=1
– At Ni in segment Si+1: t=0
dx
a1 2a2 3a3 a1
dt Ni
3. The joint is smooth
• Differentiate (eqn 39) w.r.t. t
2
d x
2
2 a 2 6 a3t
dt
2
d x
2
2 a
2 6 a3
t
dt
3. The joint is smooth
• Again consider what happens at Ni
– At Ni in segment Si: t=1
– At Ni in segment Si+1: t=0
2
d x
2
2 a
2 6 a3
2 a 2
dt
Final boundary condition
• Currently have 3 eqns in 4 unknowns
• Need one more boundary condition:
• From endpoints of whole line
– Fixed gradient
• give a value for end(s) of curve
– Free end
• 2nd derivative is 0
– Contour
• Ends of line meet (loop) – gradient at 1st point = gradient at
last point
Solve set of simultaneous eqns
• To find the values of a0…a3 for each segment
• Gaussian elimination
– Similarly for y
What have we achieved?
• If we know three points on a curve we can calculate any
others
• Consider a curve 3 points at a time (red ones)
• Interpolate to generate sufficient intermediate points (white)
• Join with short straight lines
Bezier Curves
• An alternative to splines
polynomial).
– A 4-point curve will
have 3 segments (n=3)
Bezier Polynomials for n=3
B0 3 B 13
influence influence
n! n i
Bin (t ) .t .(1 t )
i
i!(n i )!
Parametric equations for x(t),y(t)
n
x(t ) xi .Bin (t )
i 0
n
y (t ) yi .Bin (t )
i 0
Implementing Bezier Splines
• Class Bezier2d
• Vector of points
• Mechanism for adding points
• (At least) 2 ways of drawing them
– Direct calculation method
• Draw method which calculates x(t),y(t)
– Recursive method
Direct calculation
• Use for loop
– For t=0 ; t<=1; t += 0.1{…..
public void draw(Graphics g){
float xsrc=((Point2d)points.get(0)).x();
float ysrc=((Point2d)points.get(0)).y();
for (float t=0; t<=1.1 ; t+= interval){
float xdest=0;
float ydest=0;
for (int i=0; i<numberOfPoints; i++){
float bint = bezier(i,numberOfPoints-1,t);
xdest += ((Point2d)points.get(i)).x() * bint;
ydest += ((Point2d)points.get(i)).y() * bint;
} //for i
g.drawLine((int)xsrc, (int)ysrc, (int)xdest, (int)ydest);
xsrc=xdest;
ysrc=ydest;
}//for t
}//end draw
Recursive method
Start with straight lines
joining points B
f
approximations to a e
j i
A
D
Recursive algorithm
Other curves
• Beta Splines – local influence, smooth joins
• NURBS – Non-uniform, rational Beta-
Splines
Summary
• Curves are just lots of little straight lines joined
together
• Parametric representation
• Splines
• Bezier Curves
– Direct calculation
– Recursive method
Next time….
• 3D Graphics
– Adding visual realism