cs 376 introduction to computer graphics 04 / 23 / 2007 instructor: michael eckmann
Post on 28-Dec-2015
222 Views
Preview:
TRANSCRIPT
CS 376Introduction to Computer Graphics
04 / 23 / 2007
Instructor: Michael Eckmann
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Today’s Topics• Questions?
• Piecewise Cubic Parametric curves– Hermite– Bezier– Spline
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• Some motivations for having mathematical equations define curves and
surfaces• 1) polylines and polygons are 1st degree piecewise linear approximations
to curves and surfaces (they are approximations unless they are the exact description of the outline or shape)
– if they are approximations, then it takes large numbers of points to describe them for more accurate representations == BAD
– if interactively building these surfaces (or edges/outlines) then the more points, the more tedious it is to build
• We want to be able to get more accurate representations of curved
surfaces (or edges/outlines) than polygons or polylines give us AND we
want to be able to represent them with less points. This will benefit us by
having less storage and be more easily built interactively.
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• These smooth curves are also used in graphics for other purposes like
describing a motion path for an animation sequence.
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• Let's consider 2d dimensional curves which can be later generalized to 3d
surfaces.• Instead of using piecewise linear functions, we use piecewise smooth
curves. These are of a higher degree than linear functions.• We have several choices
– a) we can use functions like y = f(x) • problem that for each value of x there is one and only one y value
– can't represent circles/ellipses etc.• problem that you can't represent vertical lines and is problematic
to represent curves with a tangent/slope of infinity– b) we can use implicit equations like f(x,y) = 0 (e.g. a circle of radius
1 like: x2 + y2 – 1 = 0)• may have more solutions than we want --- e.g. to model half a
circle you'd need constraints on the values of x or y or both.• joining 2 implicitly defined curves is hard to make the tangents at
the join point agree
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• We have several choices
– c) we can use parametric equations of the curve• x = f(t) and y = g(t)
– where f(t) and g(t) are typically cubic polynomials• the problems of the other 2 choices are solved as we shall see
– we typically use cubic polynomials because• 1) quadratic or linear polynomials do not allow a curve segment
to be described with 2 endpoints and specific slopes at the 2 endpoints (examples on the board)
• 2) higher degree (than 3) polynomials are more compute intensive and allow (possibly) unwanted artefacts in the curve
• A cubic polynomial to define a finite curve segment has 4 coefficients
per parametric equationx(t) = a
xt3 + b
xt2 + c
xt + d
x y(t) = a
yt3 + b
yt2 + c
yt + d
y
z(t) = azt3 + b
zt2 + c
zt + d
z where 0 <= t <= 1
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• x(t) = a
xt3 + b
xt2 + c
xt + d
x
• y(t) = ayt3 + b
yt2 + c
yt + d
y
• z(t) = azt3 + b
zt2 + c
zt + d
z where 0 <= t <= 1
• can be written in matrix form as:
• Q(t) = [x(t) y(t) z(t)] = T C • where T = [t3 t2 t 1] and
[ax
ay
az]
• C = [bx
by
bz]
[cx
cy
cz]
[dx d
y d
z]
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• Continuity - when joining two curve segments together (piecewise
curves). There are several different kinds of continuity to consider• Geometric continuity
– G0 geometric continuity = the curve segments are joined together
– G1 geometric continuity = the curve segments are joined together and
the directions of tangent vectors are equal at the point where they are joined
• Parametric continuity– C
0 parametric continuity = same as G
0 geometric continuity
– C1 parametric continuity = the curve segments are joined together and
the directions AND magnitudes of tangent vectors are equal at the point where they are joined
– Ck parametric continuity = the curve segments are joined together and
the directions AND magnitudes of all the derivatives up to the kth are equal at the point where they are joined (that is, the 1st through kth derivatives exist and are continuous themselves)
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• Let me draw on the board some example joined curve segments and point
out their continuity.
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Curves• There are several families of cubic polynomial curve segments that are
determined by different things– Hermite
• determined by the 2 endpoints and the tangent vector at each of the 2 endpoints
– Bezier• determined by the 2 endpoints P
1 & P
4 and 2 other intermediate
points P2 & P
3 not on the curve
– the tangent vectors at the end points are the vectors P1P
2 and
P3P
4– which are [P
2 – P
1] and [P
4 – P
3]
– Spline• determined by 4 specific points
• Note: there can be higher degree polynomials of these families of curves
(see a few slides ahead for a 4th degree polynomial Bezier curve segment)
Hermite Curve segment examples (on the board)
Bezier Curve segment examples
more Bezier Curve segment examples
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Recall• x(t) = a
xt3 + b
xt2 + c
xt + d
x
• y(t) = ayt3 + b
yt2 + c
yt + d
y
• z(t) = azt3 + b
zt2 + c
zt + d
z where 0 <= t <= 1
• can be written in matrix form as:
• Q(t) = [x(t) y(t) z(t)] = T C • where T = [t3 t2 t 1] and
[ax
ay
az]
• C = [bx
by
bz]
[cx
cy
cz]
[dx d
y d
z]
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Basis Matrix and Geometry Matrix• Q(t) = [x(t) y(t) z(t)] = T C
• where T = [t3 t2 t 1] and
[ax
ay
az]
• C = [bx
by
bz]
[cx
cy
cz]
[dx d
y d
z]
• can be rewritten so that C = M G where – M is a 4x4 matrix called the Basis Matrix and – G is a 4x1 column vector called the Geometry Matrix
• so Q(t) = T M G
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Recall• Q(t) = [x(t) y(t) z(t)] = T M G• where T = [t3 t2 t 1] and
[m11
m12
m13
m14
]• M = [m
21 m
22 m
23 m
24]
[m31
m32
m33
m34
][m
41 m
42 m
43 m
44]
[G1]
• G = [G2]
[G3]
[G4]
Note: the values of Gi are the conditions that define the curve --- such as
endpoints and tangent vectors at those end points
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Blending functions• look at x(t) • x(t) = (t3 m
11+ t2 m
21 + t m
31 + m
41)g
1x + (t3 m
12+ t2 m
22 + t m
32 + m
42)g
2x +
(t3 m13
+ t2 m23
+ t m33
+ m43
)g3x
+ (t3 m14
+ t2 m24
+ t m34
+ m44
)g4x
where g1x
is the x coordinate of G1
similar equations for y(t) and z(t)
the curve is a weighted sum of the elements of the Geometry Matrix where the weights are cubic polynomials of t which are called the Blending Functions
the Blending Functions B are given by B = T Mso Q(t) = B G
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Example with lines• Recall the parametric equation of a line:
• x(t) = x0 + t ( x
end – x
0)
• y(t) = y0 + t ( y
end – y
0)
• z(t) = z0 + t ( z
end – z
0)
• what are the endpoints of the line segment described above?
can be rewritten as: • x(t) = a
xt + b
x
• y(t) = ayt + b
y
• y(t) = azt + b
z
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• x(t) = axt + b
x
• y(t) = ayt + b
y
• y(t) = azt + b
z To get this in the form of Q(t) = T C = T M G
• T = [ t 1 ] and • C = [ a
x a
y a
z ]
• [ bx b
y b
z]
• C = M G where
• M = [ m11
m12
] and G = [ g1x
g1y
g1z
]• [ m
21 m
22 ] [ g
2x g
2y g
2z ]
Example with lines
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• The geometry matrix is simply the two endpoints • G = [ G
1 ] = [ g
1x g
1y g
1z ] = [ x
0 y
0 z
0 ] = [ P
0 ]
• [ G2 ] [ g
2x g
2y g
2z ] [ x
end y
end z
end ] [ P
1 ]
• we need to find out the Basis Matrix M• M = [ m
11 m
12 ]
• [ m21
m22
]
• Q(t) = T M G = [ t 1 ] M G
• Let's do the rest on the board to figure out M
Example with lines
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• Q(t) = T M G = [ t 1 ] M G
• Recall that T M are the blending functions. • What then, are the blending functions of lines?
Example with lines
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• Q(t) = T C = T M G = [ t3 t2 t 1 ] M G• M is the 4x4 Basis matrix and G is the Geometry matrix• For Hermite curve segments, recall that they are defined with 2 endpoints
and the tangents at those endpoints. So, the Geometry matrix is made up of the 2 endpoints and the 2 tangent vectors.
• The tangent vectors are determined by the derivative of the curve with respect to t at each of the end points (when t=0 and when t=1).
• x(t) = axt3 + b
xt2 + c
xt + d
x
• y(t) = ayt3 + b
yt2 + c
yt + d
y
• z(t) = azt3 + b
zt2 + c
zt + d
z where 0 <= t <= 1
• x'(t) = 3axt2 + 2b
xt + c
x
• y'(t) = 3ayt2 + 2b
yt + c
y
• z'(t) = 3azt2 + 2b
zt + c
z
Hermite Basis Matrix and Blending Functions
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• x'(t) = 3axt2 + 2b
xt + c
x
• y'(t) = 3ayt2 + 2b
yt + c
y
• z'(t) = 3azt2 + 2b
zt + c
z
So, Q'(t) = [ 3t2 2t 1 0 ] C• agreed?• Let's call the 2 endpoints in the Geometry Matrix P
1 and P
4 and the 2
tangent vectors at those 2 endpoints R1 and R
4.
• [ P1 ]
• G = [ P4 ]
• [ R1 ]
• [ R4 ]
Hermite Basis Matrix and Blending Functions
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• Let's just work with the x coordinates (the y and z coordinates will be handled similarly)
• So, x(t) = axt3 + b
xt2 + c
xt + d
x = T C
x = [ t3 t2 t 1 ] M G
x
• and x'(t) = 3axt2 + 2b
xt + c
x = T C
x = [ 3t2 2t 1 0 ] M G
x
• when t = 0, x(t) gets us the first endpoint and when t = 1, x(t) gets us the other endpoint.
• x(0) = P1 = [ 0 0 0 1 ] M G
x
• x(1) = P4 = [ 1 1 1 1 ] M G
x
• when t = 0, x'(t) gets us the tangent at the first endpoint and when t = 1, x'(t) gets us the tangent at the other endpoint.
• x'(0) = R1 = [ 0 0 1 0 ] M G
x
• x'(1) = R4 = [ 3 2 1 0 ] M G
x
Hermite Basis Matrix and Blending Functions
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• [P1 ] [ 0 0 0 1 ]
• [P4 ] = G
x = [ 1 1 1 1 ] M G
x
• [R1 ] [ 0 0 1 0 ]
• [R4 ] [ 3 2 1 0 ]
• just like when we solved for M (the basis matrix) with the line equations, we do the same thing here because clearly
• [ 0 0 0 1 ] • [ 1 1 1 1 ] M = Identity• [ 0 0 1 0 ] • [ 3 2 1 0 ]• so, that matrix on the left is equal to M-1
Hermite Basis Matrix and Blending Functions
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
• There are techniques to get the inverse of a matrix which we won't go into here --- if you've had linear algebra, you should know how.
• The inverse of• [ 0 0 0 1 ] • [ 1 1 1 1 ]• [ 0 0 1 0 ] • [ 3 2 1 0 ]• is• [ 2 -2 1 1 ] • [ -3 3 -2 -1 ]• [ 0 0 1 0 ] • [ 1 0 0 0 ]• This is the Basis Matrix for Hermite curve segments. • Let's verify that it is indeed the inverse of the matrix above.
Hermite Basis Matrix and Blending Functions
top related