418382...

128
418382 สสสสสสสสสสสสสส สสสสสสสสสสสสสสสสสสสสสสสสส สสสสสสสสสสสสสสสสส 7 [email protected]

Upload: ezra-elswick

Post on 01-Apr-2015

230 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

418382 สภาพแวดล้อมการทำ�างานคอมพ�วเตอร�กราฟิ�กส�การบรรยายคร��งทำ�� 7

[email protected]

Page 2: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 3: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 4: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 5: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 6: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 7: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 8: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 9: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 10: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 11: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 12: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 13: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 14: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 15: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 16: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 17: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 18: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 19: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 20: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 21: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 22: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

CS 445 / 645Introduction to Computer Graphics

Lecture 22Lecture 22

Hermite SplinesHermite Splines

Lecture 22Lecture 22

Hermite SplinesHermite Splines

Page 23: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Splines – Old School

DuckDuckDuckDuck

SplineSplineSplineSpline

Page 24: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 25: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 26: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 27: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 28: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 29: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 30: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 31: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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?

Page 32: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 33: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 34: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 35: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 36: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 37: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 38: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 39: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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(

Page 40: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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(

Page 41: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 42: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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(

Page 43: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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(

Page 44: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 45: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 46: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 47: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Resulting Hermite Spline Equation

Page 48: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Sample Hermite Curves

Page 49: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 50: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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’

Page 51: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 52: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

CS 445 / 645Introduction to Computer Graphics

Lecture 23Lecture 23

BBézier Curvesézier Curves

Lecture 23Lecture 23

BBézier Curvesézier Curves

Page 53: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 54: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 55: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 56: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 57: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 58: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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?

Page 59: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 60: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 61: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 62: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 63: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 64: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 65: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 66: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 67: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 68: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 69: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 70: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 71: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 72: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 73: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 74: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 75: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 76: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 77: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 78: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Horner’s Method

Three multiplicationsThree multiplications

Three additionsThree additions

Three multiplicationsThree multiplications

Three additionsThree additions

xxxx

xxxx

dtctbtatx

dtctbtatx

])[()(

)( 23

Page 79: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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

Page 80: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Subdivision Methods

BezierBezier

Page 81: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

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); }

Page 82: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 83: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 84: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 85: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 86: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 87: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 88: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 89: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 90: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 91: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 92: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 93: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 94: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 95: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 96: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 97: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 98: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 99: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 100: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 101: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 102: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 103: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 104: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 105: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 106: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 107: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 108: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 109: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 110: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 111: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 112: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 113: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 114: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 115: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 116: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com
Page 117: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ควอเทำอเน�ยน• ควอเทำอเน�ยนทำ��แทำนการหม!นเป็#นม!ม รอบแกน (x,y,z)

ค$อ

• ระว�งว&า (x,y,z) ตองเป็#นเวกเตอร์�หนึ่�งหนึ่ วย

¿cos

µ2;xsin

µ2;ysin

µ2;zsin

µ2

À

Page 118: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• จงหาควอเทำอเน�ยนทำ��แทำนการหม!นเป็#นม!ม 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

À

Page 119: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• ควอเทำอเน�ยนต&อไป็น��แทำนการหม!นก��องศา รอบแกน

อะไร?

– เราไดว&า– ฉะน��น– แกนทำ��หม!นรอบค$อ

¿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

Page 120: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

การค.ณควอเทำอเน�ยน• หลี�กเลี��ยงการ์คู�ณคูวอเทอเนึ่�ยนึ่ตร์งๆ• เพราะการค�านวณย!&งยากแล้ะม�ส�ทำธิ์�0ผิ�ดมาก• ใช้ความเขาใจความหมายของควอเทำอเน�ยนทำ�าการ

ค�านวณด�กว&า

Page 121: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• ให

จงค�านวณ

q1 =¿ p

22

;3p

210

;0;2p

25

À

q2 =¿ p

32

;310

;0;25

À

q1q2

Page 122: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• 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

À

Page 123: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Slerp

• อย&าค�านวณ slerp โดยตรงเช้&นก�น• สมมต�ว&าเราจะค�านวณ slerp(q0,q1,) โดยใหค&า ม�ค&าเพ��ม

ข)�นเร$�อยๆ จาก 0 ถึ)ง 1 ถึาเรา plot quaternion ค&าต&างๆ ทำ��เก�ดข)�น เราจะไดว&าม�นเร�ยงต�วก�นเป็#นเสน geodesic ซึ่)�งค$อเสนบนทำรงกล้ม 4 ม�ต�ทำ��ส� �นทำ��ส!ดทำ��ผิ&าน q0 แล้ะ q1

• ค&า เป็#นต�วบอกต�าแหน&งบนเสน geodesic น�� กล้&าวค$อ– ถึา = 0 จะอย.&ทำ�� q0

– ถึา = 1 จะอย.&ทำ�� q1

– ถึา = 0.5 จะอย.&ตรงกล้างระหว&าง q0 ก�บ q1 พอด�– ฯล้ฯ

Page 124: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

Slerp

Page 125: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• ให

จงค�านวณ

q1 =¿

1;0;0;0À

q2 =¿

0;0;1;0À

slerp(q0;q1;1=3)

Page 126: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• ส�งเกตว&า x component แล้ะ z component เป็#น 0• ด�งน��นทำ��ผิล้ล้�พธิ์� x แล้ะ z ก9จะตองม�ค&าเป็#น 0 ดวย

เน$�องจากเสน geodesic จะไม&ผิ&านบร�เวณทำ�� x แล้ะ z ไม&เป็#น 0 (ถึาผิ&านม�นจะไม&ส� �นส!ด)

• ด�งน��นเราสามารถึค�ดว&าเสน geodesic เป็#นเสนรอบวงของวงกล้มใน 2 ม�ต� โดยทำ��แกนของระนาบสองม�ต�น� �นค$อแกน w แล้ะแกน y

Page 127: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง• ม!มระหว&าง 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

À

Page 128: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 7 pramook@gmail.com

ต�วอย&าง

q0

q1

w

y

slerp(q0,q1,1/3)

1/3

2/3