Sunteți pe pagina 1din 33

CS 445 / 645

Introduction to Computer Graphics


Lecture
Lecture 23
23
B
Bézier
ézier Curves
Curves
Splines - History
Draftsman
Draftsman use
use ‘ducks’
‘ducks’ and
and
strips
strips of
of wood
wood (splines)
(splines) to
to
draw
draw curves
curves
Wood
Wood splines
splines have
have second-
second- A Duck (weight)
order
order continuity
continuity
And
And pass
pass through
through the
the
control
control points
points

Ducks trace out curve


Bézier Curves
Similar
Similar to
to Hermite,
Hermite, but
but more
more intuitive
intuitive definition
definition of
of
endpoint
endpoint derivatives
derivatives
Four
Four control
control points,
points, two
two of
of which
which are
are knots
knots
Bézier Curves

The
The derivative
derivative values
values of
of the
the Bezier
Bezier Curve
Curve at
at the
the
knots
knots are
are dependent
dependent on
on the
the adjacent
adjacent points
points

The
The scalar
scalar 33 was
was selected
selected just
just for
for this
this curve
curve
Bézier vs. Hermite

We
We can
can write
write our
our Bezier
Bezier in
in terms
terms of
of Hermite
Hermite
•• Note
Note this
this is
is just
just matrix
matrix form
form of
of previous
previous equations
equations
Bézier vs. Hermite
Now
Now substitute
substitute this
this in
in for
for previous
previous Hermite
Hermite

M
MBezier
Bezier
Bézier Basis and Geometry Matrices
Matrix
Matrix Form
Form

But
But why
why is
is M Bezier a
MBezier a good
good basis
basis matrix?
matrix?
Bézier Blending Functions
Look
Look at
at the
the blending
blending
functions
functions

This
This family
family of
of
polynomials
polynomials is
is called
called
order-3
order-3 Bernstein
Bernstein
Polynomials
Polynomials
•• C(3,
C(3, k)
k) ttkk (1-t) 3-k;; 0<=
(1-t)3-k 0<= kk <=
<= 33
•• They
They are
are all all positive
positive inin interval
interval [0,1]
[0,1]
•• Their
Their sum
sum is
is equal
equal to
to 11
Bézier Blending Functions
Thus,
Thus, every
every point
point on
on curve
curve is
is
linear
linear combination
combination of
of the
the
control
control points
points
The
The weights
weights of
of the
the
combination
combination are
are all
all positive
positive
The
The sum
sum of
of the
the weights
weights is
is 11
Therefore,
Therefore, the
the curve
curve is
is aa
convex
convex combination
combination ofof the
the
control
control points
points
Convex combination of control points
Will
Will always
always remain
remain within
within bounding
bounding region
region
(convex
(convex hull)
hull) defined
defined by
by control
control points
points
Bézier Curves
Bezier
Bezier
Why more spline slides?
Bezier
Bezier and
and Hermite
Hermite splines
splines have
have global
global influence
influence
•• One
One could
could create
create aa Bezier
Bezier curve
curve that
that required
required 15
15 points
points to
to define
define the
the
curve…
curve…
–– Moving
Moving any
any one
one control
control point
point would
would affect
affect the
the entire
entire curve
curve
•• Piecewise
Piecewise Bezier
Bezier or
or Hermite
Hermite don’t
don’t suffer
suffer from
from this,
this, but
but they
they don’t
don’t
enforce
enforce derivative
derivative continuity
continuity at
at join
join points
points
B-splines
B-splines consist
consist of
of curve
curve segments
segments whose
whose polynomial
polynomial
coefficients
coefficients depend
depend onon just
just aa few
few control
control points
points
•• Local
Local control
control
Examples
Examples of
of Splines
Splines
B-Spline Curve (cubic periodic)
Start
Start with
with aa sequence
sequence of
of control
control points
points
Select
Select four
four from
from middle
middle of
of sequence
sequence (p i-2,, p
(pi-2 i-1,, p
pi-1 i+1)) d
pii,, ppi+1 d
•• Bezier
Bezier and
and Hermite
Hermite goes
goes between
between ppi-2
i-2 and
and ppi+1
i+1

•• B-Spline
B-Spline doesn’t
doesn’t interpolate
interpolate (touch)
(touch) anyany of
of them
them but
but
approximates
approximates going
going through
through ppi-1
i-1 and
and ppii
pp11 Q
Q44 pp22 pp66
tt44 Q
Q55
tt55
Q
Q33 tt66 Q
Q66
pp33
pp00 tt33 pp44 tt77
pp55
Uniform B-Splines
Approximating
Approximating Splines
Splines
Approximates
Approximates n+1
n+1 control
control points
points
•• P
P00,, P
P11,, …,
…, P
Pnn,, nn ¸¸ 33
Curve
Curve consists
consists of
of nn –2
–2 cubic
cubic polynomial
polynomial segments
segments
•• Q
Q33,, Q
Q44,, …
…QQnn
tt varies
varies along
along B-spline
B-spline as
as Q
Qii:: ttii <=
<= tt << tti+1
i+1

ttii (i(i == integer)


integer) are
are knot
knot points
points that
that join
join segment
segment Q
Qii to
to Q
Qi+1
i+1

Curve
Curve is
is uniform
uniform because
because knots
knots are
are spaced
spaced at
at equal
equal intervals
intervals of
of
parameter,
parameter,tt
Uniform B-Splines
First
First curve
curve segment,
segment, Q
Q33,, is
is defined
defined by
by first
first four
four
control
control points
points
Last
Last curve
curve segment,
segment, Q Qmm,, is
is defined
defined by by last
last four
four
control
control points,
points, P m-3,, P
Pm-3 m-2,, P
Pm-2 m-1,, P
Pm-1 Pmm
Each
Each control
control point
point affects
affects four
four curve
curve segments
segments
B-spline Basis Matrix
Formulate
Formulate 16
16 equations
equations to
to solve
solve the
the 16
16 unknowns
unknowns
The
The 16
16 equations
equations enforce
enforce the
the C
C00,, C
C11,, and
and C
C22
continuity
continuity between
between adjoining
adjoining segments,
segments, Q Q

 1 3  3 1
3 6 3 0
1
M B  spline 
6  3 0 3 0
 
1 4 1 0
B-Spline
Points
Points along
along B-Spline
B-Spline are
are computed
computed just
just as
as with
with
Bezier
Bezier Curves
Curves

Qi  t   UM B  Spline P

 1 3  3 1  pi 
3 6   

Qi  t   t 3
t 2
t 1 
1
6  3 0
3 0  pi 1 
3 0  pi  2 
  
1 4 1 0  pi 3 
B-Spline
By
By far
far the
the most
most popular
popular spline
spline used
used
C
C00,, C
C11,, and
and C
C22 continuous
continuous
Nonuniform, Rational B-Splines
(NURBS)
The
The native
native geometry
geometry element
element in
in Maya
Maya
Models
Models are
are composed
composed of
of surfaces
surfaces defined
defined by
by
NURBS,
NURBS, not
not polygons
polygons
NURBS
NURBS are
are smooth
smooth
NURBS
NURBS require
require effort
effort to
to make
make non-smooth
non-smooth
Converting Between Splines
Consider
Consider two
two spline
spline basis
basis formulations
formulations for
for two
two
spline
spline types
types
Converting Between Splines
We
We can
can transform
transform the
the control
control points
points from
from one
one
spline
spline basis
basis to
to another
another
Converting Between Splines
With
With this
this conversion,
conversion, we
we can
can convert
convert aa B-Spline
B-Spline
into
into aa Bezier
Bezier Spline
Spline
Bezier
Bezier Splines
Splines are
are easy
easy to
to render
render
Rendering Splines
Horner’s
Horner’s Method
Method
Incremental
Incremental (Forward
(Forward Difference)
Difference) Method
Method
Subdivision
Subdivision Methods
Methods
Horner’s Method

x ( t )  a x t  bx t  c x t  d x
3 2

x ( t )  [(a x t  bx ) t  c x ]t  d x
Three
Three multiplications
multiplications
Three
Three additions
additions
Forward Difference
x k 1  x k  x k
x k  a x t 3  bx t 2  c x t  d
x k 1  a x (t k   ) 3  bx ( t k   ) 2  c x (t k   )  d x
x k 1  x k  x k  3a xt k  (3a x 2  2bx )t k  (a x 3  bx 2  c x )
2

But
But this
this still
still is
is expensive
expensive to
to compute
compute
•• Solve
Solve for
for change at kk ((kk)) and
change at and change
change at k+1 ((k+1
at k+1 k+1))

•• Boot
Boot strap
strap with
with initial
initial values for xx00,, 00,, and
values for and 11
•• Compute
Compute xx33 by adding xx00 ++ 00 ++ 11
by adding
Subdivision Methods

Bezier
Bezier
Rendering Bezier Spline
public void spline(ControlPoint p0, ControlPoint p1,
ControlPoint p2, ControlPoint p3, int pix) {
float len = ControlPoint.dist(p0,p1) + ControlPoint.dist(p1,p2)
+ ControlPoint.dist(p2,p3);
float chord = ControlPoint.dist(p0,p3);
if (Math.abs(len - chord) < 0.25f) return;
fatPixel(pix, p0.x, p0.y);
ControlPoint p11 = ControlPoint.midpoint(p0, p1);
ControlPoint tmp = ControlPoint.midpoint(p1, p2);
ControlPoint p12 = ControlPoint.midpoint(p11, tmp);
ControlPoint p22 = ControlPoint.midpoint(p2, p3);
ControlPoint p21 = ControlPoint.midpoint(p22, tmp);
ControlPoint p20 = ControlPoint.midpoint(p12, p21);
spline(p20, p12, p11, p0, pix);
spline(p3, p22, p21, p20, pix);
}
Do you want a 5th assignment?
Assignment 5
Spline-generated
Spline-generated paths
paths
•• Create
Create aa six-sided
six-sided room
room with
with textured
textured walls,
walls, floor,
floor, ceiling
ceiling
•• Import
Import from
from aa file
file the
the description
description of
of aa 2-D
2-D spline
spline
–– Could
Could be
be Hermite
Hermite or
or Bezier
Bezier
•• Create
Create aa texture
texture mapped
mapped character
character that
that follows
follows the
the spline
spline in
in
the
the room
room
•• Create
Create aa simple
simple user
user interface
interface so
so the
the camera
camera can
can either
either be
be
under
under user
user control
control or
or follow
follow the
the character
character automatically
automatically
Virtual Trackball
Can
Can wewe use
use the
the mouse
mouse to
to control
control the
the 2-D
2-D rotation
rotation
of
of aa viewing
viewing volume?
volume?

Imagine
Imagine aa track
track ball
ball
•• User
User moves
moves point
point on
on ball
ball from
from (x,
(x, y,
y, z)
z) to
to (a,
(a, b,
b, c)
c)
Imagine
Imagine the
the points
points projected
projected onto
onto the
the ground
ground
•• User
User moves
moves point
point on
on ground
ground from
from (x,
(x, 0,
0, z)
z) to
to (a,
(a, 0,
0, c)
c)
Trackball
Movement
Movement of
of points
points on
on track
track ball
ball can
can be
be inferred
inferred
from
from mouse
mouse drags
drags on
on screen
screen

Inverse
Inverse problem
problem
•• Where
Where on
on trackball
trackball does
does (a,
(a, 0,
0, c)
c) hit?
hit?
•• Ball
Ball is
is unit
unit sphere,
sphere, so
so ||x,
||x, y,
y, z||
z|| == 1.0
1.0
•• xx == a,
a, zz == c,
c, yy == solve
solve for
for itit
Trackball
User
User defines
defines two
two points
points
•• Place
Place where
where first
first clicked
clicked X
X == (x,
(x, y,
y, z)
z)
•• Place
Place where
where released
released A
A == (a,
(a, b,
b, c)
c)
Ball
Ball rotates
rotates along
along axis
axis perp
perp to
to line
line defined
defined by
by these
these two
two points
points
•• compute
compute cross
cross produce
produce of
of lines
lines to
to origin:
origin: (X
(X –– O)
O) xx (A
(A –– O)
O)
Ball
Ball rotates
rotates by
by amount
amount proportional
proportional to
to distance
distance between
between lines
lines
•• magnitude
magnitude of
of cross
cross product
product tells
tells us
us angle
angle between
between lines
lines (dot
(dot product
product too)
too)
|sin || == ||cross
•• |sin ||cross product||
product||
Compute
Compute rotation
rotation matrix
matrix and
and use
use itit to
to rotate
rotate world
world

S-ar putea să vă placă și