Sunteți pe pagina 1din 72

Curves and Surfaces

CMPT 361
Introduction to Computer Graphics
Torsten Mller
Machiraju/Zhang/Mller

Rendering Pipeline
Hardware
Modelling

Transform

Visibility
Illumination +
Shading

Perception,

Texture/
Color

Interaction
Machiraju/Zhang/Mller

Realism

Reading
Angel Chapter 10
Foley et al. - Chapter 11

Machiraju/Zhang/Mller

Today

Polynomials
Parametric representation
Fairness vs. smoothness
Parametric vs. geometric continuity
Hermite spline
Bezier spline
B-Spline
Surfaces
Subdivision Machiraju/Zhang/Mller

Filling a gap
So far, we have focused on lines, flat
polygons, and simple objects, e.g., spheres
Missing: freeform curves and surfaces
Although smooth curves and surfaces are
converted to polygonal curves and meshes
when rendered, they still provide a good
option for modeling
We follow the text loosely
Machiraju/Zhang/Mller

[Zorin 01]

Why curves and surfaces?


Natural to use for modeling of smooth shapes,
e.g.,
Body of an automobile
Shape of cartoon characters (Shrek)
Motion curves in animation, etc.
http://www.shrek2.com/
Smoothness can often be
guaranteed analytically
Compact (analytical) representation
Theory of smooth curves and surfaces, e.g.,
from calculus and differential geometry, is well Machiraju/Zhang/Mller
developed

Polynomial curves and surfaces


In computer graphics, we prefer curves and
surfaces represented by polynomials
Approximation power: Can approximate any
continuous function to any accuracy
(WeierstrasssTheorem)
Can offer local control for shape design through
the use of piecewise polynomials
All derivatives and integrals are available
(infinitely smooth) and easy to compute
Compact representation
Machiraju/Zhang/Mller
Efficient evaluation
e.g., Horners rule

Horners rule
Consider a cubic polynomial
b(t) = at3 + bt2 + ct + d
Straightforward way to evaluate b(t) takes 6
multiplications and 3 additions
Horners Rule:
b(t) = ((a * t + b) * t + c) * t + d
It takes 3 additions and 3 multiplications. In
general, n +s and n *s for polynomial with
degree = n.
Machiraju/Zhang/Mller

Curve & surface representation


Explicit: y = f(x), z = f(x, y)
Implicit (level-set): f(x,y) = 0, f(x, y, z) = 0
Parametric:
2D planar curve segment:
(x(t), y(t)), t [0, 1]

3D space curve segment:


(x(t), y(t), z(t)), t [0, 1]

3D parametric surface patch:


(x(u, v), y(u, v), z(u, v)), u, v [0, 1]
Machiraju/Zhang/Mller

Basis Functions

http://terpconnect.umd.edu/~petersd/interp.html

Machiraju/Zhang/Mller

10

Piecewise polynomial curves


Consider the problem of polynomial
interpolation:
High-degree
interpolation

Piece-wise cubic
interpolation
Machiraju/Zhang/Mller

11

Today

Polynomials
Parametric representation
Fairness vs. smoothness
Parametric vs. geometric continuity
Hermite spline
Bezier spline
B-Spline
Surfaces
Subdivision Machiraju/Zhang/Mller

12

Fairness vs. smoothness


Smoothness of curves and surfaces:
Local property: often achieved by design
Related to existence and continuity of various
derivatives,
e.g., f(x) = 3x100 9x2 + + 1 is infinitely smooth,
but is it visually pleasing?

Fairness (often appears in CAGD literature)


Global property: often achieved by some form of
energy minimization
Related to the energy of a curve or surface
e.g., f(x) = 3x100 9x2 + + 1 has high bending
energy, and is not Machiraju/Zhang/Mller
very visually pleasing

13

Parametric cubic curves


Let us focus on parametric curves for now
Generalization to surfaces is quite straightforward
Questions: what degree (of the polynomials) to
use?
Degree 0 2 (constant, linear, or quadratic): often has
too little flexibility
High-degree: unnecessarily complex and easy to
introduce undesirable wiggles (most objects we want
to model using curves and surfaces are somewhat
fair) fairness vs. smoothness
Most commonly used in graphics: parametric cubic
Machiraju/Zhang/Mller
(degree-3) curves and surfaces

14

Parametric cubic segment


Consider a single piece:
x(t) = a3t3 + a2t2 + a1t + a0
y(t) = b3t3 + b2t2 + b1t + b0
z(t) = c3t3 + c2t2 + c1t + c0
In matrix form:

T is said to be the monomial basis


Machiraju/Zhang/Mller

15

Derivatives and continuity


1st-order derivative of (x(t), y(t)): (x(t), y(t))
tangent
2nd-order derivative: (x(t), y(t)) related to
curvature
Parametric continuity of a curve (smoothness of
motion):

C0 continuous: curve is joined or connected


C1: requires C0 & 1st-order derivative is continuous
C2: requires C0 & C1 & 2nd-order derivative is cont.
Machiraju/Zhang/Mller
n
0
C : requires C & & Cn1 & nth derivative cont.

16

Continuity of piecewise
polynomials
A single polynomial segment is always C
But we mostly deal with piecewise polynomial
curves
Key: what happens at the joints between segments
C0: curve segments are connected
C1: C0 & 1st-order derivatives agree at joints
C2: C0 & C1 & 2nd-order derivative agree at joints, etc.

If Ci is not possible to enforce, can relax a bit


Visual smoothness: direction of tangents stays the
same but magnitude (speed) may change
Machiraju/Zhang/Mller

17

Geometric continuity
geometric continuity
G0 cont.: curve segments are connected (same as C0)
G1: G0 & 1st-order derivatives are proportional at joints.
Note:
Proportional = same direction but may have different
magnitudes
Weaker than C1

G2: G1 & 2nd-order derivative proportional at joints

Example: p(t) = (3t, t3) and q(t) = (4t+3, 2t2+4t+1)


with t [0, 1] for each. Is this C0, G1, and/or C1?
p(1)=q(0)=(3,1), so G0; p(1)=(3,3) and q(0)=(4,4), so
Machiraju/Zhang/Mller
1
1
G not C

18

On to curve design
We want to design piecewise cubic polynomial curves
that satisfy certain design constraints, e.g.,
Curve should pass through certain points
Curve should have some given derivatives at specific points
Curve should be smooth: G1, C1, C2, or
Curve must be contained in certain area, or has at most this
length, etc.

Need proper basis functions to facilitate design process


These basis functions or blending functions blend
together the individual contributions of the control
points
Machiraju/Zhang/Mller

19

Basis of cubic polynomials


Monomial basis: {1, t, t2, t3}, is only one
possibility
Recall basis:
x(t) = P1b1(t) + P2b2(t) + P3b3(t) + P4b4(t)
From design point of view, want P1, P2, P3, and P4
to represent observable quantities, e.g.,
Position: for interpolation
Derivatives: to control direction and smoothness, etc.

i.e., they are control points


Control points are blended by the basis functions;
Machiraju/Zhang/Mller
they control the shape of the curve

20

Ex. 1: Hermite curves


Defined by two points (P1 and P4) and two
tangents (R1 and R4)
R
P
1
1
Aim: Achieve C or G continuity
P
Want cubic curve x(t),
R
t [0, 1], such that
Let us note that the
control points P1,
(y and z are similar)
1

P4, R1, and R4 are


all observable
quantities and they
control the shape of
the curve

x(0) = P1
x(1) = P4
x(0) = R1
x(1) = R4

Machiraju/Zhang/Mller

21

Cubic Hermite curves


x(t) = TA = a3t3 + a2t2 + a1t + a0, where T =
[t3 t2 t 1] and A = [a3 a2 a1 a0]T. We want

So G = BA and thus A = B1G


It follows that x(t) = TA = TB1G = HG
Machiraju/Zhang/Mller

22

Hermite curves
How to interpret this: x(t) = TA = TB1G = HG
G is a vector of observables or control points
H is vector of cubic Hermite bases (blending
polynomials)
For any G, use H to blend four control points to get
curve x(t)
The matrix Mhermite = B1 is really a change of basis
matrix: it changes the monomial basis T into the
Hermite basis H
Hermite curves are completely determined by
Machiraju/Zhang/Mller
Mhermite

23

The cubic Hermite matrix

Machiraju/Zhang/Mller

24

Piecewise Hermite curves


Can obviously enforce C1 or G1 continuity
at the joints
R1

R4
P4 = P1
P4

P1
R4 = kR1

Each segment parameterized over [0, 1], as


usual
Machiraju/Zhang/Mller

25

Today

Polynomials
Parametric representation
Fairness vs. smoothness
Parametric vs. geometric continuity
Hermite spline
Bezier spline
B-Spline
Surfaces
Subdivision Machiraju/Zhang/Mller

26

Ex. 2: Cubic Bzier curve


Defined by four control points P0, P1, P2, and P3
x(0) = P0
x(1) = P3
x(0) = 3(P1 P0)
x(1) = 3(P3 P2)

Convex hull property: Bzier curve lies within


the convex hull of the four control points
good control
Convex hull of a set of points on the plane:
tightest convex polygon
enclosing the set
Machiraju/Zhang/Mller

27

Convex hull property


A cubic curve satisfies the convex hull property if
it lies within the convex hull of its four control
points
Convex hull property is satisfied if and only if the
basis polynomials B1(t), B2(t), B3(t), B4(t) satisfy:
1. 0 B1(t), B2(t), B3(t), B4(t) 1 for t [0, 1], and
2. B1(t) + B2(t) + B3(t) + B4(t) = 1

Then each point of the curve is a convex


combination of the control points
The basis Bi(t) form a partition of unity
Machiraju/Zhang/Mller

28

The cubic Bzier matrix

Machiraju/Zhang/Mller

29

Bzier basis polynomials


B0(t) = (1 t)3, B1(t) = 3t(1 t)2,
B2(t) = 3t2(1 t), B3(t) = t3

Well known as the Bernstein Polynomials of


degree 3
Bernstein polynomials of degree n
We have
Partition of unity easy to see:
i Bi(t) = [t + (1 t)]n
Machiraju/Zhang/Mller

30

Piecewise Bzier curves


How to ensure C1 or G1 continuity for a
piecewise Bzier curve?
Each segment is parameterized over [0, 1]
P2
as usual
P6

P1
P3
P0

P5
P4

http://www.cs.princeton.edu/~min/cs426/jar/bezier.html
Machiraju/Zhang/Mller

31

Ex 3. Cubic B-Spline curves


Most popular choice in computer graphics
They are C2 continuous this beats Hermite
and Bzier curves in terms of smoothness
The theory of B-splines is very rich
NURBS: nonuniform rational B-splines
Each component is rational: x(t)/w(t), etc.
Can be used to specify circles, etc.

Machiraju/Zhang/Mller

32

Cubic B-Spline curves


Each cubic B-spline segment is specified by
four control points
Has the convex hull property
The cubic B-spline matrix:

Machiraju/Zhang/Mller

33

Piecewise cubic B-splines


Two consecutive segments share three control
points
m control points m 3 segments
Each segment parameterized over [0, 1] as usual
Exercise: what if control points repeat? P8
P2
P1

P4
C1

C3
P5

P6
C4

C5
P7

C2
P3

Machiraju/Zhang/Mller
http://www.cs.technion.ac.il/~cs234325/Applets/applets/bspline/GermanApplet.html

34

From curves to surfaces


One easy way: sweep a curve whose control
points also trace out some curves, e.g., bilinear
interpolation
Fit the simplest surface
between four points
Sweep a straight line and each
bilinear interpolation
point on the line traces a
straight line
Example of a ruled surface
Also an example of the more general class of
Machiraju/Zhang/Mller
tensor-product surfaces

35

Tensor-product (TP) surfaces


The curve to sweep:
Control point ai goes through a curve
The resulting surface is a tensor-product
surface
Surface is controlled by the grid of control
points Pij
Machiraju/Zhang/Mller

36

Ex. 1: TP cubic Bzier patch

The Bi(u)Bj(v)s form a basis for bi-cubic


polynomials
They also form a partition of unity the patch lies
within the convex hull of the 16 control points Pij
Patch can be seen as generated by sweeping a
Bzier curve where each point on the curve sweeps
out a Bzier curve
The four corner vertices are interpolated (easy to
Machiraju/Zhang/Mller
see?)

37

Cubic Bzier surface patch

[Angel 02]

In matrix form:
http://www.math.psu.edu/dlittle/java/parametricequations/beziersurfaces/index.html
Machiraju/Zhang/Mller

38

Ex. 2: TP cubic B-spline


surfaces
Analogues extension
of B-spline curves
N(u) and N(v) are the
cubic B-spline bases
16 control points per
bi-cubic B-spline patch
Satisfy the convex hull
property
Machiraju/Zhang/Mller

39

Smoothness of Bzier surface


G1 continuity: make 2-sets of 4 control
points on either side of an edge collinear
C1 continuity: collinear and equally spaced

Collinear
control points
Machiraju/Zhang/Mller
near patch boundary

40

Smoothness of B-spline
surface
C2 continuity is achieved if adjacent patches
share control points

Machiraju/Zhang/Mller

41

Today

Polynomials
Parametric representation
Fairness vs. smoothness
Parametric vs. geometric continuity
Hermite spline
Bezier spline
B-Spline
Surfaces
Subdivision Machiraju/Zhang/Mller

42

deCasteljau Recursion
We can use the convex hull property of
Bezier curves to obtain an efficient
recursive method that does not require any
function evaluations
Uses only the values at the control points

Based on the idea that any polynomial and


any part of a polynomial is a Bezier
polynomial for properly chosen control
data
Machiraju/Zhang/Mller

43

Splitting a Cubic Bezier


p0, p1, p2, p3 determine a cubic Bezier
polynomial and its convex hull

Consider left half l(u) and right half r(u)


Machiraju/Zhang/Mller

44

l(u) and r(u)


Since l(u) and r(u) are Bezier curves, we
should be able to find two sets of control
points {l0, l1, l2, l3} and {r0, r1, r2, r3} that
determine them

Machiraju/Zhang/Mller

45

Convex Hulls
{l0, l1, l2, l3} and {r0, r1, r2, r3} each have a convex hull that
that is closer to p(u) than the convex hull of {p0, p1, p2, p3}
This is known as the variation diminishing property.
The polyline from l0 to l3 (= r0) to r3 is an approximation to
p(u). Repeating recursively we get better approximations.

Machiraju/Zhang/Mller

46

Equations
Start with Bezier equations p(u)=uTMBp
l(u) must interpolate p(0) and p(1/2)
l(0) = l0 = p0
l(1) = l3 = p(1/2) = 1/8( p0 +3 p1 +3 p2 + p3 )

Matching slopes, taking into account that l(u)


and r(u) only go over half the distance as p(u)
l(0) = 3(l1 - l0) = p(0) = 3/2(p1 - p0 )
l(1) = 3(l3 l2) = p(1/2) = 3/8(- p0 - p1+ p2 + p3)

Symmetric equations
hold for r(u)
Machiraju/Zhang/Mller

47

Efficient Form
l0 = p0
r3 = p3
l1 = (p0 + p1)
r1 = (p2 + p3)
l2 = (l1 + ( p1 + p2))
r1 = (r2 + ( p1 + p2))
l3 = r0 = (l2 + r1)
Requires only shifts and adds!

Machiraju/Zhang/Mller

48

Every Curve is a Bezier Curve


We can render a given polynomial using the
recursive method if we find control points
for its representation as a Bezier curve
Suppose that p(u) is given as an
interpolating curve with control points q
p(u)=uTMIq

There exist Bezier control points p such that


p(u)=uTMBp
-1M
Equating and solving,
we
find
p=M
B
I
Machiraju/Zhang/Mller

49

Matrices

Interpolating to Bezier

B-Spline to Bezier

Machiraju/Zhang/Mller

50

Example
These three curves were all generated from
the same original data using Bezier
recursion by converting all control point
data to Bezier control points

Bezier

Interpolating
Machiraju/Zhang/Mller

B Spline

51

Surfaces
Can apply the recursive method to surfaces if we
recall that for a Bezier patch curves of constant u (or
v) are Bezier curves in u (or v)
First subdivide in u
Process creates new points
Some of the original points are discarded
original and discarded

original and
kept
Machiraju/Zhang/Mller

new
52

Second Subdivision

16 final points for


1 of 4 patches created
Machiraju/Zhang/Mller

53

Normals
For rendering we need the normals if we
want to shade
Can compute from parametric equations

Can use vertices of corner points to determine


OpenGL can compute automatically
Machiraju/Zhang/Mller

54

Utah Teapot
Most famous data set in computer graphics
Widely available as a list of 306 3D vertices
and the indices that define 32 Bezier patches

Machiraju/Zhang/Mller

55

Subdivision Schemes
In order to draw a curve we need to find
points on it:

first idea - go step by step, i.e.:

Machiraju/Zhang/Mller

56

Subdivision Schemes
Same for surfaces:

How can we find those new points?


What about triangles/arbitrary polygons?
Machiraju/Zhang/Mller

57

Subdivision Schemes (2)

Machiraju/Zhang/Mller

58

Loop
Guaranteed to be smooth everywhere except
at extraordinary vertices
Face Split
Triangular
meshes
approximating

Machiraju/Zhang/Mller

59

Loop (2)

Machiraju/Zhang/Mller

60

Loop - Boundary
Subdivision Mask for
Boundary Conditions

Vertex Rule

Edge Rule
Machiraju/Zhang/Mller

61

Modified Butterfly
Face Split
Triangular
meshes
interpolating

Machiraju/Zhang/Mller

62

Catmull-Clark
Face Split
Quad. Meshes
(extents to
arbitrary)
approximating
Masks for odd vertices

Machiraju/Zhang/Mller

63

Catmull-Clark (2)
Face Split
Quad. Meshes
(extents to
arbitrary)
approximating
Masks for even vertices

Machiraju/Zhang/Mller

64

Catmull-Clark (2)
FACE

EDGE

VERTEX

Machiraju/Zhang/Mller

65

Kobbelt
Face Split
Quad. Meshes
interpolating

Machiraju/Zhang/Mller

66

Kobbelt (2)
Mask for face vertex
adjacent to an
extraordinary vertex.
Two steps
The edge vertices
The face vertex
the edge odd control
point adjacent to an
extraordinary vertex
Machiraju/Zhang/Mller

67

Doo-Sabin
Vertex Split
Quad. Meshes
interpolating or approximating??

Machiraju/Zhang/Mller

68

Mid-Edge
Midedge, the simpler version of Doo-Sabin
scheme.

Machiraju/Zhang/Mller

69

Doo-Sabin & Mid-Edge


The interior rules can be decomposed into a
sequence of averaging steps.

Doo-Sabin scheme

Midedge scheme
Machiraju/Zhang/Mller

70

Subdivision Schemes
Butterfly

Loop

CatmullClark

Doo-Sabin

Machiraju/Zhang/Mller

71

Modeling with Subdivision


Subdivision produces smooth continuous
surfaces.
How can sharpness and creases be controlled
in a modeling environment?
ANSWER: Define new subdivision rules for
creased edges and vertices.
Tag Edges sharp edges.
If an edge is sharp, apply
new sharp subdivision rules.
Otherwise subdivide with
normal rules. Machiraju/Zhang/Mller

72

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