418382 สภาพแวดล้อมการทำ�างานคอมพ�วเตอร�กราฟิ�กส�การบรรยายคร��งทำ�� 7
CS 445 / 645Introduction to Computer Graphics
Lecture 22Lecture 22
Hermite SplinesHermite Splines
Lecture 22Lecture 22
Hermite SplinesHermite Splines
Splines – Old School
DuckDuckDuckDuck
SplineSplineSplineSpline
Representations of Curves
Use a sequence of points…Use a sequence of points…
• Piecewise linear - does not accurately model a smooth linePiecewise linear - does not accurately model a smooth line
• Tedious to create list of pointsTedious to create list of points
• Expensive to manipulate curve because all points must be Expensive to manipulate curve because all points must be repositionedrepositioned
Instead, model curve as piecewise-polynomialInstead, model curve as piecewise-polynomial
• x = x(t), y = y(t), z = z(t) x = x(t), y = y(t), z = z(t)
– where x(), y(), z() are polynomials where x(), y(), z() are polynomials
Use a sequence of points…Use a sequence of points…
• Piecewise linear - does not accurately model a smooth linePiecewise linear - does not accurately model a smooth line
• Tedious to create list of pointsTedious to create list of points
• Expensive to manipulate curve because all points must be Expensive to manipulate curve because all points must be repositionedrepositioned
Instead, model curve as piecewise-polynomialInstead, model curve as piecewise-polynomial
• x = x(t), y = y(t), z = z(t) x = x(t), y = y(t), z = z(t)
– where x(), y(), z() are polynomials where x(), y(), z() are polynomials
Specifying Curves (hyperlink)
Control PointsControl Points• A set of points that influence the A set of points that influence the
curve’s shapecurve’s shape
KnotsKnots• Control points that lie on the curveControl points that lie on the curve
Interpolating SplinesInterpolating Splines• Curves that pass through the control Curves that pass through the control
points (knots)points (knots)
Approximating SplinesApproximating Splines• Control points merely influence shapeControl points merely influence shape
Control PointsControl Points• A set of points that influence the A set of points that influence the
curve’s shapecurve’s shape
KnotsKnots• Control points that lie on the curveControl points that lie on the curve
Interpolating SplinesInterpolating Splines• Curves that pass through the control Curves that pass through the control
points (knots)points (knots)
Approximating SplinesApproximating Splines• Control points merely influence shapeControl points merely influence shape
Parametric Curves
Very flexible representationVery flexible representation
They are not required to be functionsThey are not required to be functions
• They can be multivalued with respect to any dimensionThey can be multivalued with respect to any dimension
Very flexible representationVery flexible representation
They are not required to be functionsThey are not required to be functions
• They can be multivalued with respect to any dimensionThey can be multivalued with respect to any dimension
Cubic Polynomials
x(t) = ax(t) = axxtt33 + b + bxxtt22 + c + cxxt + dt + dxx
• Similarly for y(t) and z(t)Similarly for y(t) and z(t)
Let t: (0 <= t <= 1)Let t: (0 <= t <= 1)
Let T = [tLet T = [t33 t t22 t 1] t 1]
Coefficient Matrix CCoefficient Matrix C
Curve: Q(t) = T*CCurve: Q(t) = T*C
x(t) = ax(t) = axxtt33 + b + bxxtt22 + c + cxxt + dt + dxx
• Similarly for y(t) and z(t)Similarly for y(t) and z(t)
Let t: (0 <= t <= 1)Let t: (0 <= t <= 1)
Let T = [tLet T = [t33 t t22 t 1] t 1]
Coefficient Matrix CCoefficient Matrix C
Curve: Q(t) = T*CCurve: Q(t) = T*C
z
z
y
y
x
x
zyx
zyx
d
c
d
c
d
c
bbb
aaa
ttt 123
Piecewise Curve Segments
One curve constructed by connecting many One curve constructed by connecting many smaller segments end-to-endsmaller segments end-to-end
• Must have rules for how the segments are joinedMust have rules for how the segments are joined
Continuity describes the jointContinuity describes the joint
• Parametric continuityParametric continuity
• Geometric continuityGeometric continuity
One curve constructed by connecting many One curve constructed by connecting many smaller segments end-to-endsmaller segments end-to-end
• Must have rules for how the segments are joinedMust have rules for how the segments are joined
Continuity describes the jointContinuity describes the joint
• Parametric continuityParametric continuity
• Geometric continuityGeometric continuity
Parametric Continuity
• CC11 is tangent continuity (velocity) is tangent continuity (velocity)
• CC22 is 2 is 2ndnd derivative continuity (acceleration) derivative continuity (acceleration)
• Matching direction and magnitude of dMatching direction and magnitude of dnn / dt / dtnn
CCnn continous continous
• CC11 is tangent continuity (velocity) is tangent continuity (velocity)
• CC22 is 2 is 2ndnd derivative continuity (acceleration) derivative continuity (acceleration)
• Matching direction and magnitude of dMatching direction and magnitude of dnn / dt / dtnn
CCnn continous continous
Geometric Continuity
If positions matchIf positions match• GG00 geometric continuity geometric continuity
If direction (but not necessarily magnitude) of tangent If direction (but not necessarily magnitude) of tangent matchesmatches• GG11 geometric continuity geometric continuity
• The tangent value at the end of one curve is proportional to the The tangent value at the end of one curve is proportional to the tangent value of the beginning of the next curvetangent value of the beginning of the next curve
If positions matchIf positions match• GG00 geometric continuity geometric continuity
If direction (but not necessarily magnitude) of tangent If direction (but not necessarily magnitude) of tangent matchesmatches• GG11 geometric continuity geometric continuity
• The tangent value at the end of one curve is proportional to the The tangent value at the end of one curve is proportional to the tangent value of the beginning of the next curvetangent value of the beginning of the next curve
Parametric Cubic Curves
In order to assure CIn order to assure C22 continuity, curves must be of continuity, curves must be of
at least degree 3at least degree 3
Here is the parametric definition of a cubic Here is the parametric definition of a cubic (degree 3) spline in two dimensions(degree 3) spline in two dimensions
How do we extend it to three dimensions?How do we extend it to three dimensions?
In order to assure CIn order to assure C22 continuity, curves must be of continuity, curves must be of
at least degree 3at least degree 3
Here is the parametric definition of a cubic Here is the parametric definition of a cubic (degree 3) spline in two dimensions(degree 3) spline in two dimensions
How do we extend it to three dimensions?How do we extend it to three dimensions?
Parametric Cubic Splines
Can represent this as a matrix tooCan represent this as a matrix tooCan represent this as a matrix tooCan represent this as a matrix too
Coefficients
So how do we select the coefficients?So how do we select the coefficients?
• [a[axx b bxx c cxx d dxx] and [a] and [ayy b byy c cyy d dyy] must satisfy the constraints ] must satisfy the constraints
defined by the knots and the continuity conditionsdefined by the knots and the continuity conditions
So how do we select the coefficients?So how do we select the coefficients?
• [a[axx b bxx c cxx d dxx] and [a] and [ayy b byy c cyy d dyy] must satisfy the constraints ] must satisfy the constraints
defined by the knots and the continuity conditionsdefined by the knots and the continuity conditions
Parametric Curves
Difficult to conceptualize curve as Difficult to conceptualize curve as x(t) = ax(t) = axxtt33 + b + bxxtt22 + c + cxxt + dt + dxx
(artists don’t think in terms of coefficients of cubics)(artists don’t think in terms of coefficients of cubics)
Instead, define curve as weighted combination of 4 well-Instead, define curve as weighted combination of 4 well-defined cubic polynomialsdefined cubic polynomials(wait a second! Artists don’t think this way either!)(wait a second! Artists don’t think this way either!)
Each curve type defines different cubic polynomials and Each curve type defines different cubic polynomials and weighting schemesweighting schemes
Difficult to conceptualize curve as Difficult to conceptualize curve as x(t) = ax(t) = axxtt33 + b + bxxtt22 + c + cxxt + dt + dxx
(artists don’t think in terms of coefficients of cubics)(artists don’t think in terms of coefficients of cubics)
Instead, define curve as weighted combination of 4 well-Instead, define curve as weighted combination of 4 well-defined cubic polynomialsdefined cubic polynomials(wait a second! Artists don’t think this way either!)(wait a second! Artists don’t think this way either!)
Each curve type defines different cubic polynomials and Each curve type defines different cubic polynomials and weighting schemesweighting schemes
Parametric Curves
HermiteHermite – two endpoints and two endpoint – two endpoints and two endpoint tangent vectorstangent vectors
BezierBezier - two endpoints and two other points that - two endpoints and two other points that define the endpoint tangent vectorsdefine the endpoint tangent vectors
SplinesSplines – four control points – four control points • C1 and C2 continuity at the join pointsC1 and C2 continuity at the join points
• Come close to their control points, but not guaranteed to Come close to their control points, but not guaranteed to touch themtouch them
Examples of Splines
HermiteHermite – two endpoints and two endpoint – two endpoints and two endpoint tangent vectorstangent vectors
BezierBezier - two endpoints and two other points that - two endpoints and two other points that define the endpoint tangent vectorsdefine the endpoint tangent vectors
SplinesSplines – four control points – four control points • C1 and C2 continuity at the join pointsC1 and C2 continuity at the join points
• Come close to their control points, but not guaranteed to Come close to their control points, but not guaranteed to touch themtouch them
Examples of Splines
Hermite Cubic Splines
An example of knot and continuity constraintsAn example of knot and continuity constraintsAn example of knot and continuity constraintsAn example of knot and continuity constraints
Hermite Cubic Splines
One cubic curve for each dimensionOne cubic curve for each dimension
A curve constrained to x/y-plane has two curves:A curve constrained to x/y-plane has two curves:
One cubic curve for each dimensionOne cubic curve for each dimension
A curve constrained to x/y-plane has two curves:A curve constrained to x/y-plane has two curves:
d
c
b
a
ttt
dctbtattf x
1
)(
23
23
h
g
f
e
ttt
hgtftettf y
1
)(
23
23
Hermite Cubic Splines
A 2-D Hermite Cubic Spline is defined by eight A 2-D Hermite Cubic Spline is defined by eight parameters: a, b, c, d, e, f, g, hparameters: a, b, c, d, e, f, g, h
How do we convert the intuitive endpoint constraints into How do we convert the intuitive endpoint constraints into these (relatively) unintuitive eight parameters?these (relatively) unintuitive eight parameters?
We know:We know:• (x, y) position at t = 0, p(x, y) position at t = 0, p11
• (x, y) position at t = 1, p(x, y) position at t = 1, p22
• (x, y) derivative at t = 0, dp/dt(x, y) derivative at t = 0, dp/dt
• (x, y) derivative at t = 1, dp/dt(x, y) derivative at t = 1, dp/dt
A 2-D Hermite Cubic Spline is defined by eight A 2-D Hermite Cubic Spline is defined by eight parameters: a, b, c, d, e, f, g, hparameters: a, b, c, d, e, f, g, h
How do we convert the intuitive endpoint constraints into How do we convert the intuitive endpoint constraints into these (relatively) unintuitive eight parameters?these (relatively) unintuitive eight parameters?
We know:We know:• (x, y) position at t = 0, p(x, y) position at t = 0, p11
• (x, y) position at t = 1, p(x, y) position at t = 1, p22
• (x, y) derivative at t = 0, dp/dt(x, y) derivative at t = 0, dp/dt
• (x, y) derivative at t = 1, dp/dt(x, y) derivative at t = 1, dp/dt
Hermite Cubic Spline
We know:We know:
• (x, y) position at t = 0, p(x, y) position at t = 0, p11
We know:We know:
• (x, y) position at t = 0, p(x, y) position at t = 0, p11
xpdf
d
c
b
adcbaf
x
x
1
23
23
)0(
1000
000)0(
yphf
h
g
f
ehgfef
y
y
1
23
23
)0(
1000
000)0(
Hermite Cubic Spline
We know:We know:
• (x, y) position at t = 1, p(x, y) position at t = 1, p22
We know:We know:
• (x, y) position at t = 1, p(x, y) position at t = 1, p22
xpdcbaf
d
c
b
adcbaf
x
x
2
23
23
)1(
1111
111)1(
yphgfef
h
g
f
ehgfef
y
y
2
23
23
)1(
1111
111)1(
Hermite Cubic Splines
So far we have four equations, but we have eight So far we have four equations, but we have eight unknownsunknowns
Use the derivativesUse the derivatives
So far we have four equations, but we have eight So far we have four equations, but we have eight unknownsunknowns
Use the derivativesUse the derivatives
d
c
b
a
tttf
cbtattf
dctbtattf
x
x
x
0123)(
23)(
)(
2
2
23
h
g
f
e
tttf
gftettf
hgtftettf
y
y
y
0123)(
23)(
)(
2
2
23
Hermite Cubic Spline
We know:We know:
• (x, y) derivative at t = 0, dp/dt(x, y) derivative at t = 0, dp/dt
We know:We know:
• (x, y) derivative at t = 0, dp/dt(x, y) derivative at t = 0, dp/dt
dtdp
cf
d
c
b
acbaf
xx
x
1
2
2
)0(
010203
0203)0(
dtdp
gf
h
g
f
egfef
y
y
y
1
2
2
)0(
010203
0203)0(
Hermite Cubic Spline
We know:We know:
• (x, y) derivative at t = 1, dp/dt(x, y) derivative at t = 1, dp/dt
We know:We know:
• (x, y) derivative at t = 1, dp/dt(x, y) derivative at t = 1, dp/dt
dtdp
cbaf
d
c
b
acbaf
xx
x
1
2
2
23)1(
011213
1213)1(
dtdp
gfef
h
g
f
egfef
y
y
y
1
2
2
23)1(
011213
1213)1(
Hermite Specification
Matrix equation for Hermite CurveMatrix equation for Hermite CurveMatrix equation for Hermite CurveMatrix equation for Hermite Curve
t = 0
t = 1
t = 0
t = 1
t3 t2 t1 t0
p1
p2
r p1
r p2
dtdp
dtdp
p
p
dtdp
dtdpp
p
h
g
f
e
d
c
b
a
y
y
y
y
x
x
x
x
2
1
2
1
1
1
2
1
0123
0100
1111
1000
Solve Hermite Matrix
h
g
f
e
d
c
b
a
dtdp
dtdp
p
p
dtdp
dtdpp
p
y
y
y
y
x
x
x
x
2
1
2
1
1
1
2
11
0123
0100
1111
1000
Spline and Geometry Matrices
h
g
f
e
d
c
b
a
dtdp
dtdp
p
p
dtdp
dtdpp
p
y
y
y
y
x
x
x
x
2
1
2
1
1
1
2
1
0001
0100
1233
1122
MHermite GHermite
Resulting Hermite Spline Equation
Sample Hermite Curves
Blending Functions
By multiplying first two matrices in lower-left By multiplying first two matrices in lower-left equation, you have four functions of ‘t’ that equation, you have four functions of ‘t’ that blend the four control parametersblend the four control parameters
These are blendingThese are blendingfunctionsfunctions
By multiplying first two matrices in lower-left By multiplying first two matrices in lower-left equation, you have four functions of ‘t’ that equation, you have four functions of ‘t’ that blend the four control parametersblend the four control parameters
These are blendingThese are blendingfunctionsfunctions
Hermite Blending Functions
If you plot the If you plot the blending blending functions on functions on the parameter the parameter ‘t’‘t’
If you plot the If you plot the blending blending functions on functions on the parameter the parameter ‘t’‘t’
Hermite Blending Functions
Remember, eachRemember, eachblending functionblending functionreflects influencereflects influenceof Pof P11, P, P22, , PP11, , PP22
on spline’s shapeon spline’s shape
Remember, eachRemember, eachblending functionblending functionreflects influencereflects influenceof Pof P11, P, P22, , PP11, , PP22
on spline’s shapeon spline’s shape
CS 445 / 645Introduction to Computer Graphics
Lecture 23Lecture 23
BBézier Curvesézier Curves
Lecture 23Lecture 23
BBézier Curvesézier Curves
Splines - History
Draftsman use ‘ducks’ and Draftsman use ‘ducks’ and strips of wood (splines) to strips of wood (splines) to draw curvesdraw curves
Wood splines have second-Wood splines have second-order continuityorder continuity
And pass through the And pass through the control pointscontrol points
Draftsman use ‘ducks’ and Draftsman use ‘ducks’ and strips of wood (splines) to strips of wood (splines) to draw curvesdraw curves
Wood splines have second-Wood splines have second-order continuityorder continuity
And pass through the And pass through the control pointscontrol points
A Duck (weight)
Ducks trace out curve
Bézier Curves
Similar to Hermite, but more intuitive definition of Similar to Hermite, but more intuitive definition of endpoint derivativesendpoint derivatives
Four control points, two of which are knotsFour control points, two of which are knots
Similar to Hermite, but more intuitive definition of Similar to Hermite, but more intuitive definition of endpoint derivativesendpoint derivatives
Four control points, two of which are knotsFour control points, two of which are knots
Bézier Curves
The derivative values of the Bezier Curve at the The derivative values of the Bezier Curve at the knots are dependent on the adjacent pointsknots are dependent on the adjacent points
The scalar 3 was selected just for this curve The scalar 3 was selected just for this curve
The derivative values of the Bezier Curve at the The derivative values of the Bezier Curve at the knots are dependent on the adjacent pointsknots are dependent on the adjacent points
The scalar 3 was selected just for this curve The scalar 3 was selected just for this curve
Bézier vs. Hermite
We can write our Bezier in terms of HermiteWe can write our Bezier in terms of Hermite
• Note this is just matrix form of previous equationsNote this is just matrix form of previous equations
We can write our Bezier in terms of HermiteWe can write our Bezier in terms of Hermite
• Note this is just matrix form of previous equationsNote this is just matrix form of previous equations
Bézier vs. Hermite
Now substitute this in for previous HermiteNow substitute this in for previous HermiteNow substitute this in for previous HermiteNow substitute this in for previous Hermite
MMBezierBezierMMBezierBezier
Bézier Basis and Geometry Matrices
Matrix FormMatrix Form
But why is MBut why is MBezierBezier a good basis matrix? a good basis matrix?
Matrix FormMatrix Form
But why is MBut why is MBezierBezier a good basis matrix? a good basis matrix?
Bézier Blending Functions
Look at the blending Look at the blending functionsfunctions
This family of This family of polynomials is calledpolynomials is calledorder-3 Bernstein order-3 Bernstein PolynomialsPolynomials• C(3, k) tC(3, k) tkk (1-t) (1-t)3-k3-k; 0<= k <= 3; 0<= k <= 3
• They are all positive in interval [0,1]They are all positive in interval [0,1]
• Their sum is equal to 1Their sum is equal to 1
Look at the blending Look at the blending functionsfunctions
This family of This family of polynomials is calledpolynomials is calledorder-3 Bernstein order-3 Bernstein PolynomialsPolynomials• C(3, k) tC(3, k) tkk (1-t) (1-t)3-k3-k; 0<= k <= 3; 0<= k <= 3
• They are all positive in interval [0,1]They are all positive in interval [0,1]
• Their sum is equal to 1Their sum is equal to 1
Bézier Blending Functions
Thus, every point on curve is Thus, every point on curve is linear combination of the linear combination of the control pointscontrol points
The weights of the The weights of the combination are all positivecombination are all positive
The sum of the weights is 1The sum of the weights is 1
Therefore, the curve is a Therefore, the curve is a convex combination of the convex combination of the control pointscontrol points
Thus, every point on curve is Thus, every point on curve is linear combination of the linear combination of the control pointscontrol points
The weights of the The weights of the combination are all positivecombination are all positive
The sum of the weights is 1The sum of the weights is 1
Therefore, the curve is a Therefore, the curve is a convex combination of the convex combination of the control pointscontrol points
Convex combination of control points
Will always remain within bounding region Will always remain within bounding region (convex hull)(convex hull) defined by control points defined by control points
Will always remain within bounding region Will always remain within bounding region (convex hull)(convex hull) defined by control points defined by control points
Why more spline slides?
Bezier and Hermite splines have global influenceBezier and Hermite splines have global influence• One could create a Bezier curve that required 15 points to define the One could create a Bezier curve that required 15 points to define the
curve…curve…
– Moving any one control point would affect the entire curveMoving any one control point would affect the entire curve
• Piecewise Bezier or Hermite don’t suffer from this, but they don’t Piecewise Bezier or Hermite don’t suffer from this, but they don’t enforce derivative continuity at join pointsenforce derivative continuity at join points
B-splinesB-splines consist of curve segments whose polynomial consist of curve segments whose polynomial coefficients depend on just a few control pointscoefficients depend on just a few control points• Local controlLocal control
Examples of Splines
Bezier and Hermite splines have global influenceBezier and Hermite splines have global influence• One could create a Bezier curve that required 15 points to define the One could create a Bezier curve that required 15 points to define the
curve…curve…
– Moving any one control point would affect the entire curveMoving any one control point would affect the entire curve
• Piecewise Bezier or Hermite don’t suffer from this, but they don’t Piecewise Bezier or Hermite don’t suffer from this, but they don’t enforce derivative continuity at join pointsenforce derivative continuity at join points
B-splinesB-splines consist of curve segments whose polynomial consist of curve segments whose polynomial coefficients depend on just a few control pointscoefficients depend on just a few control points• Local controlLocal control
Examples of Splines
B-Spline Curve (cubic periodic)
Start with a sequence of control pointsStart with a sequence of control points
Select four from middle of sequence Select four from middle of sequence (p(pi-2i-2, p, pi-1i-1, p, pii, p, pi+1i+1) ) dd
• Bezier and Hermite goes between pBezier and Hermite goes between p i-2i-2 and p and pi+1i+1
• B-Spline doesn’t interpolate (touch) any of them but B-Spline doesn’t interpolate (touch) any of them but approximates going through papproximates going through p i-1i-1 and p and pii
Start with a sequence of control pointsStart with a sequence of control points
Select four from middle of sequence Select four from middle of sequence (p(pi-2i-2, p, pi-1i-1, p, pii, p, pi+1i+1) ) dd
• Bezier and Hermite goes between pBezier and Hermite goes between p i-2i-2 and p and pi+1i+1
• B-Spline doesn’t interpolate (touch) any of them but B-Spline doesn’t interpolate (touch) any of them but approximates going through papproximates going through p i-1i-1 and p and pii
pp00pp00 pp44pp44
pp22pp22pp11pp11
pp33pp33
pp55pp55
pp66pp66
QQ33QQ33
QQ44QQ44
QQ55QQ55
QQ66QQ66
tt33tt33
tt44tt44 tt55tt55
tt66tt66
tt77tt77
Uniform B-Splines
ApproximatingApproximating Splines Splines
Approximates n+1 control pointsApproximates n+1 control points
• PP00, P, P11, …, P, …, Pnn, n , n ¸̧ 3 3
Curve consists of n –2 cubic polynomial segmentsCurve consists of n –2 cubic polynomial segments
• QQ33, Q, Q44, … Q, … Qnn
t varies along B-spline as Qt varies along B-spline as Qii: t: tii <= t < t <= t < ti+1i+1
ttii (i = integer) are (i = integer) are knot pointsknot points that join segment Q that join segment Qii to Q to Qi+1i+1
Curve is Curve is uniformuniform because knots are spaced at equal intervals of because knots are spaced at equal intervals of parameter,parameter, tt
ApproximatingApproximating Splines Splines
Approximates n+1 control pointsApproximates n+1 control points
• PP00, P, P11, …, P, …, Pnn, n , n ¸̧ 3 3
Curve consists of n –2 cubic polynomial segmentsCurve consists of n –2 cubic polynomial segments
• QQ33, Q, Q44, … Q, … Qnn
t varies along B-spline as Qt varies along B-spline as Qii: t: tii <= t < t <= t < ti+1i+1
ttii (i = integer) are (i = integer) are knot pointsknot points that join segment Q that join segment Qii to Q to Qi+1i+1
Curve is Curve is uniformuniform because knots are spaced at equal intervals of because knots are spaced at equal intervals of parameter,parameter, tt
Uniform B-Splines
First curve segment, QFirst curve segment, Q33, is defined by first four , is defined by first four
control pointscontrol points
Last curve segment, QLast curve segment, Qmm, is defined by last four , is defined by last four
control points, Pcontrol points, Pm-3m-3, P, Pm-2m-2, P, Pm-1m-1, P, Pmm
Each control point affects four curve segmentsEach control point affects four curve segments
First curve segment, QFirst curve segment, Q33, is defined by first four , is defined by first four
control pointscontrol points
Last curve segment, QLast curve segment, Qmm, is defined by last four , is defined by last four
control points, Pcontrol points, Pm-3m-3, P, Pm-2m-2, P, Pm-1m-1, P, Pmm
Each control point affects four curve segmentsEach control point affects four curve segments
B-spline Basis Matrix
Formulate 16 equations to solve the 16 unknownsFormulate 16 equations to solve the 16 unknowns
The 16 equations enforce the CThe 16 equations enforce the C00, C, C11, and C, and C22
continuity between adjoining segments, Qcontinuity between adjoining segments, Q
Formulate 16 equations to solve the 16 unknownsFormulate 16 equations to solve the 16 unknowns
The 16 equations enforce the CThe 16 equations enforce the C00, C, C11, and C, and C22
continuity between adjoining segments, Qcontinuity between adjoining segments, Q
0141
0303
0363
1331
6
1splineBM
B-Spline
Points along B-Spline are computed just as with Points along B-Spline are computed just as with Bezier CurvesBezier Curves
Points along B-Spline are computed just as with Points along B-Spline are computed just as with Bezier CurvesBezier Curves
PUMtQ SplineBi
3
2
123
0141
0303
0363
1331
6
11
i
i
i
i
i
p
p
p
p
ttttQ
B-Spline
By far the most popular spline usedBy far the most popular spline used
CC00, C, C11, and C, and C22 continuous continuous
By far the most popular spline usedBy far the most popular spline used
CC00, C, C11, and C, and C22 continuous continuous
Nonuniform, Rational B-Splines(NURBS)
The native geometry element in MayaThe native geometry element in Maya
Models are composed of surfaces defined by Models are composed of surfaces defined by NURBS, not polygonsNURBS, not polygons
NURBS are smoothNURBS are smooth
NURBS require effort to make non-smoothNURBS require effort to make non-smooth
The native geometry element in MayaThe native geometry element in Maya
Models are composed of surfaces defined by Models are composed of surfaces defined by NURBS, not polygonsNURBS, not polygons
NURBS are smoothNURBS are smooth
NURBS require effort to make non-smoothNURBS require effort to make non-smooth
Converting Between Splines
Consider two spline basis formulations for two Consider two spline basis formulations for two spline typesspline types
Consider two spline basis formulations for two Consider two spline basis formulations for two spline typesspline types
Converting Between Splines
We can transform the control points from one We can transform the control points from one spline basis to anotherspline basis to another
We can transform the control points from one We can transform the control points from one spline basis to anotherspline basis to another
Converting Between Splines
With this conversion, we can convert a B-Spline With this conversion, we can convert a B-Spline into a Bezier Splineinto a Bezier Spline
Bezier Splines are easy to renderBezier Splines are easy to render
With this conversion, we can convert a B-Spline With this conversion, we can convert a B-Spline into a Bezier Splineinto a Bezier Spline
Bezier Splines are easy to renderBezier Splines are easy to render
Rendering Splines
Horner’s MethodHorner’s Method
Incremental (Forward Difference) MethodIncremental (Forward Difference) Method
Subdivision MethodsSubdivision Methods
Horner’s MethodHorner’s Method
Incremental (Forward Difference) MethodIncremental (Forward Difference) Method
Subdivision MethodsSubdivision Methods
Horner’s Method
Three multiplicationsThree multiplications
Three additionsThree additions
Three multiplicationsThree multiplications
Three additionsThree additions
xxxx
xxxx
dtctbtatx
dtctbtatx
])[()(
)( 23
Forward Difference
But this still is expensive to computeBut this still is expensive to compute
• Solve for change at k (Solve for change at k (kk) and change at k+1 () and change at k+1 (k+1k+1))
• Boot strap with initial values for xBoot strap with initial values for x00, , 00, and , and 11
• Compute xCompute x33 by adding x by adding x00 + + 00 + + 11
But this still is expensive to computeBut this still is expensive to compute
• Solve for change at k (Solve for change at k (kk) and change at k+1 () and change at k+1 (k+1k+1))
• Boot strap with initial values for xBoot strap with initial values for x00, , 00, and , and 11
• Compute xCompute x33 by adding x by adding x00 + + 00 + + 11
)()23(3
)()()(2322
1
231
23
1
xxxkxxkxkkk
xkxkxkxk
xxxk
kkk
cbatbataxxx
dtctbtax
dtctbtax
xxx
Subdivision Methods
BezierBezier
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); }
ควอเทำอเน�ยน• ควอเทำอเน�ยนทำ��แทำนการหม!นเป็#นม!ม รอบแกน (x,y,z)
ค$อ
• ระว�งว&า (x,y,z) ตองเป็#นเวกเตอร์�หนึ่�งหนึ่ วย
¿cos
µ2;xsin
µ2;ysin
µ2;zsin
µ2
À
ต�วอย&าง• จงหาควอเทำอเน�ยนทำ��แทำนการหม!นเป็#นม!ม 60 องศารอบ
แกน (1,1,1)– เวกเตอร�หน)�งหน&วยของแกนค$อ– ค�านวณค&า cos แล้ะ sin
– แล้ะจะไดว&าควอเทำอเน�ยนค$อ
(1=p
3;1=p
3;1=p
3)
cos30± =
p3
2;sin30± =
12
¿ p3
2;
1
2p
3;
1
2p
3;
1
2p
3
À
ต�วอย&าง• ควอเทำอเน�ยนต&อไป็น��แทำนการหม!นก��องศา รอบแกน
อะไร?
– เราไดว&า– ฉะน��น– แกนทำ��หม!นรอบค$อ
¿12;0;
p6
4;
p6
4
À
cosµ2
=12
= cos60±
µ= 120±
1sin60±
µ0;
p6
4;
p6
4
¶=
2p
3
µ0;
p6
4;
p6
4
¶=
µ0;
p2
2;
p2
2
¶
การค.ณควอเทำอเน�ยน• หลี�กเลี��ยงการ์คู�ณคูวอเทอเนึ่�ยนึ่ตร์งๆ• เพราะการค�านวณย!&งยากแล้ะม�ส�ทำธิ์�0ผิ�ดมาก• ใช้ความเขาใจความหมายของควอเทำอเน�ยนทำ�าการ
ค�านวณด�กว&า
ต�วอย&าง• ให
จงค�านวณ
q1 =¿ p
22
;3p
210
;0;2p
25
À
q2 =¿ p
32
;310
;0;25
À
q1q2
ต�วอย&าง• q1 ค$อการหม!นเป็#นม!ม 90 องศา รอบแกน (3/5, 0, 4/5)
• q2 ค$อการหม!นเป็#นม!ม 60 องศา รอบแกน (3/5, 0, 4/5)
• ฉะน��น q1q2 ค$อการหม!นเป็#นม!ม 60 องศาแล้วจ)งหม!น 90 องศา
• รวมแล้วเป็#นการหม!น 150 องศารอบแกน (3/5, 0, 4/5)• ฉะน��น q1q2 =
¿cos75±;
35
sin75±;0;45
sin75±À
=¿ p
3¡ 1
2p
2;3+ 3
p3
10p
2;0;
4+ 4p
3
10p
2
À
Slerp
• อย&าค�านวณ slerp โดยตรงเช้&นก�น• สมมต�ว&าเราจะค�านวณ slerp(q0,q1,) โดยใหค&า ม�ค&าเพ��ม
ข)�นเร$�อยๆ จาก 0 ถึ)ง 1 ถึาเรา plot quaternion ค&าต&างๆ ทำ��เก�ดข)�น เราจะไดว&าม�นเร�ยงต�วก�นเป็#นเสน geodesic ซึ่)�งค$อเสนบนทำรงกล้ม 4 ม�ต�ทำ��ส� �นทำ��ส!ดทำ��ผิ&าน q0 แล้ะ q1
• ค&า เป็#นต�วบอกต�าแหน&งบนเสน geodesic น�� กล้&าวค$อ– ถึา = 0 จะอย.&ทำ�� q0
– ถึา = 1 จะอย.&ทำ�� q1
– ถึา = 0.5 จะอย.&ตรงกล้างระหว&าง q0 ก�บ q1 พอด�– ฯล้ฯ
Slerp
ต�วอย&าง• ให
จงค�านวณ
q1 =¿
1;0;0;0À
q2 =¿
0;0;1;0À
slerp(q0;q1;1=3)
ต�วอย&าง• ส�งเกตว&า x component แล้ะ z component เป็#น 0• ด�งน��นทำ��ผิล้ล้�พธิ์� x แล้ะ z ก9จะตองม�ค&าเป็#น 0 ดวย
เน$�องจากเสน geodesic จะไม&ผิ&านบร�เวณทำ�� x แล้ะ z ไม&เป็#น 0 (ถึาผิ&านม�นจะไม&ส� �นส!ด)
• ด�งน��นเราสามารถึค�ดว&าเสน geodesic เป็#นเสนรอบวงของวงกล้มใน 2 ม�ต� โดยทำ��แกนของระนาบสองม�ต�น� �นค$อแกน w แล้ะแกน y
ต�วอย&าง• ม!มระหว&าง q0 แล้ะ q1 ค$อ 90 องศา• slerp(q0,q1,1/3) ค$อต�าแหน&งทำ��ทำ�าม!มก�บ q0 เป็#น 1/3 เทำ&า
ของม!ม 90 องศา กล้&าวค$อทำ�าม!ม 30 องศาก�บ q0
• ฉะน��น slerp(q0,q1,1/3) จ)งม�พ�ก�ด (w,y) เทำ&าก�บ • กล้&าวค$อ
µ p3
2;12
¶
slerp(q0;q1;1=3) =¿ p
32
;0;12;0
À
ต�วอย&าง
q0
q1
w
y
slerp(q0,q1,1/3)
1/3
2/3
Top Related