chap 3 interpolating values

111
Chap 3 Interpolating Values Animation(U), Chap 3, Interpolating Values 1

Upload: chaim

Post on 23-Feb-2016

101 views

Category:

Documents


1 download

DESCRIPTION

Chap 3 Interpolating Values. Outline. Interpolating/approximating curves Controlling the motion of a point along a curve Interpolation of orientation Working with paths. Interpolation between key frames. Parameters to be interpolated Position of an object Normal - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chap 3 Interpolating Values

Chap 3Interpolating Values

Animation(U), Chap 3, Interpolating Values 1

Page 2: Chap 3 Interpolating Values

2

Outline Interpolating/approximating curves Controlling the motion of a point along a curve Interpolation of orientation Working with paths

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 3: Chap 3 Interpolating Values

3

Interpolation between key frames Parameters to be interpolated

Position of an object Normal Joint angle between two joints Transparency attribute of an object

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 4: Chap 3 Interpolating Values

4

Interpolation between key frames Interpolation between frames is not trivial

Appropriate interpolating function Parameterization of the function Maintain the desired control of the interpolated values

over time Example

(-5,0,0) at frame 22, (5,0,0) art frame 67 Stop at frame 22 and accelerate to reach a max speed by

frame 34 Start to decelerate at frame 50 and come to a stop at

frame 67

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 5: Chap 3 Interpolating Values

5

Interpolation between key frames

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

desired result undesired result

Need a smooth interpolation with user control

Page 6: Chap 3 Interpolating Values

Interpolation between key framesSolution

Generate a space curve Distribute points evenly along curve Speed control: vary points temporally

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang6

A

B

C

D

Time = 0

Time = 10

Time = 35

Time = 60

Page 7: Chap 3 Interpolating Values

7

Interpolation functions Interpolation vs. approximation

Interpolation Hermite, Catmull-Rom

approximation Bezier, B-spline

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 8: Chap 3 Interpolating Values

8

Interpolation functions Complexity => computational efficiency

Polynomials Lower than cubic

No inflection point, may not fit smoothly to some data points Higher than cubic

Doesn’t provide any significant advantages, costly to evaluate Piecewise cubic

Provides sufficient smoothness Allows enough flexibility to satisfy constraints such as end-

point position and tangents

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 9: Chap 3 Interpolating Values

9

Interpolation functions Continuity within a curve

Zero-order First order (tangential)

Suffices for most animation applications Second order

Important when dealing with time-distance curve Continuity between curve segments

Hermite, Catmull-Rom, cubic Bezier provide first order continuity between segments

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 10: Chap 3 Interpolating Values

10

Interpolation functions

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 11: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang11

Continuity

noneposition(0th order)

tangent(1st order)

curvature(2nd order)

At junction of two circular arcs

Animation(U), Chap 3, Interpolating Values

Page 12: Chap 3 Interpolating Values

12

Interpolation functions Global vs. local control

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 13: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang13

Types of Curve Representation Explicit y = f(x)

Good for generate points For each input, there is a unique output

Implicit f(x,y) = 0 Good for testing if a point is on a curve Bad for generating a sequence of points

Parametric x = f(u), y = g(u) Good for generating a sequence of points Can be used for multi-valued function of x

Animation(U), Chap 3, Interpolating Values

Page 14: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang14

Example: Representing Unit Circle Cannot be represented explicitly as a function

of x

Implicit form:f(x,y)=x2+y2=1

Parametric form:x=cos(u), y=sin(u), 0<u<2π u

f<0

f>0f=0

Animation(U), Chap 3, Interpolating Values

Page 15: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang15

More on 3-D Parametric Curves

Parametric form: P(u) = (Px(u), Py(u), Pz(u)) x = Px(u), y = Py(u), z = Pz(u)

Space-curve P = P(u) 0.0 <=u<=1.0

u=1/3

u=2/3

u=0.0

u=1.0

Animation(U), Chap 3, Interpolating Values

Page 16: Chap 3 Interpolating Values

Polynomial Interpolation

An n-th degree polynomial fits a curve to n+1 points Example: fit a second degree curve to three points

y(x)= a x2 + b x + c points to be interpolated

(x1, y1), (x2, y2), (x3, y3) solve for coefficients (a, b, c):

3 linear equations, 3 unknowns called Lagrange Interpolation

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang16

Page 17: Chap 3 Interpolating Values

Polynomial Interpolation (cont.)

Result is a curve that is too wiggly, change to any control point affects entire curve (nonlocal) – this method is poor

We usually want the curve to be as smooth as possible minimize the wiggles high-degree polynomials are bad

Higher degree, higher the wiggles

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang17

Page 18: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang18

Composite Segments Divide a curve into multiple segments Represent each in a parametric form Maintain continuity between segments

position Tangent (C1-continuity vs. G1-continuity) curvature

P1(u) P2(u) P3(u) Pn(u)

Animation(U), Chap 3, Interpolating Values

Page 19: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang19

Splines: Piecewise Polynomials A spline is a piecewise polynomial - many low

degree polynomials are used to interpolate (pass through) the control points

Cubic polynomials are the most common lowest order polynomials that interpolate two

points and allow the gradient at each point to be defined - C1 continuity is possible

Higher or lower degrees are possible, of course

Animation(U), Chap 3, Interpolating Values

Page 20: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang20

A Linear Piecewise PolynomialThe simple form for interpolating two points.

p1

p2

Each segment is of the form: (this is a vector equation)

u0 1

1

Two basis (blending) functions

u

21 )1()( puupup

Animation(U), Chap 3, Interpolating Values

Page 21: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang21

Hermite Curves—cubic polynomial for two points

Hermite interpolation requires Endpoint positions derivatives at endpoints

To create a composite curve, use the end of one as the beginning of the other and share the tangent vector

Hermite Interpolation

)0('P

control points/knots

dcubuauuP 23)(

)0(P

)1('P)1(P

))(),(),(()( uPuPuPuP zyx

Animation(U), Chap 3, Interpolating Values

Page 22: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang22

Hermite Curve Formation Cubic polynomial and its derivative

Given Px(0), Px(1), P’x(0), P’x(1), solve for a, b, c, d 4 equations are given for 4 unknowns

xxxxx ducubuauP 23)(

xxxx cubuauP 23)( 2'

xx dP )0(xxxxx dcbaP )1(

xx cP )0('

xxxx cbaP 23)1('Animation(U), Chap 3, Interpolating Values

Page 23: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang23

Hermite Curve Formation (cont.) Problem: solve for a, b, c, d

Solution:

)0()0(

)1()0(2))0()1((3

)1()0())1()0((2

'

''

''

xx

xx

xxxxx

xxxxx

PdPc

PPPPb

PPPPa

xx dP )0(xxxxx dcbaP )1(

xx cP )0('

xxxx cbaP 23)1('

Animation(U), Chap 3, Interpolating Values

Page 24: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang24

Hermite Curves in Matrix Form

ith segment incomposite curves

dcubuauuP 23)(

MBUuP T)(

parameter theis ]1 , , ,[ 23 uuuU T

matrixt coefficien theis Mninformatio geometric theis B

000101001233

1122

M

)1()0()1()0(

B

'

'

x

x

x

x

PPPP

'1

'1B

i

i

i

i

PPPP

Animation(U), Chap 3, Interpolating Values

Page 25: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang25

Blending Functions of Hermite Splines Each cubic Hermite spline is a linear combination of

4 blending functions

geometric information

2

1

2

1

23

23

23

23

''2

32

132

)(

pppp

uu

uuu

uu

uu

up

BMUuP T )(

Animation(U), Chap 3, Interpolating Values

Page 26: Chap 3 Interpolating Values

Composite Hermite Curve Continuity between connected segments is

ensured by using ending tangent vector of one segment as the beginning tangent vector of the next.

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang26

Page 27: Chap 3 Interpolating Values

Bezier Curves Similar to Hermite Curve Instead of endpoints and tangents, four control

points are given points P1 and P4 are on the curve points P2 and P3 are used to control the shape p1 = P1, p2 = P4, p1' = 3(P2-P1), p2' = 3(P4 - P3)

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang27

4321

0001003303631331

1)( 23

PPPP

uuuup

Page 28: Chap 3 Interpolating Values

Bezier Curves Another representation

Blend the control point position using Bernstein polynomials

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang28

)!(!!),(

)1(),()(

spolynomialBernstein are )( where

)()(

,

,

0,

knknknC

uuknCuB

uB

PuBup

knknk

nk

n

kknk

Page 29: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang29

Bezier Curves

Animation(U), Chap 3, Interpolating Values

Page 30: Chap 3 Interpolating Values

Composite Bezier Curves

How to control the continuity between adjacent Bezier segment?

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang30

Page 31: Chap 3 Interpolating Values

De Casteljau Construction of Bezier Curves

How to derive a point on a Bezier curve?

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang31

Page 32: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang32

Bezier Curves (cont.) Variant of the Hermite spline

basis matrix derived from the Hermite basis (or from scratch)

Gives more uniform control knobs (series of points) than Hermite

Scale factor (3) is chosen to make “velocity” approximately constant

Animation(U), Chap 3, Interpolating Values

Page 33: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang33

Catmull-Rom Splines With Hermite splines, the designer must arrange

for consecutive tangents to be collinear, to get C1 continuity. Similar for Bezier. This gets tedious.

Catmull-Rom: an interpolating cubic spline with built-in C1 continuity.

Compared to Hermite/Bezier: fewer control points required, but less freedom.

Animation(U), Chap 3, Interpolating Values

Page 34: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang34

Catmull-Rom Splines (cont.) Given n control points in 3-D: p1, p2, …, pn,

Tangent at pi given by s(pi+1 – pi-1) for i=2..n-1, for some s.

Curve between pi and pi+1 is determined by pi-1, pi, pi+1, pi+2.

Animation(U), Chap 3, Interpolating Values

Page 35: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang35

Catmull-Rom Splines (cont.) Given n control points in 3-D: p1, p2, …, pn,

Tangent at pi given by s(pi+1 – pi-1) for i=2..n-1, for some s

Curve between pi and pi+1 is determined by pi-1, pi, pi+1, pi+2

What about endpoint tangents? (several good answers: extrapolate, or use extra control points p0, pn+1)

Now we have positions and tangents at each knot – a Hermite specification.

Animation(U), Chap 3, Interpolating Values

Page 36: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang36

Catmull-Rom Spline Matrix

Derived similarly to Hermite and Bezier s is the tension parameter; typically s=1/2

2

1

1

002001011452

1331

)(

,2/1When

i

i

i

i

T

PPP

P

Uup

s

Animation(U), Chap 3, Interpolating Values

Page 37: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang37

Catmull-Rom Spline What about endpoint tangents?

Provided by users Several good answers: extrapolate, or use extra

control points p0, pn+1

Animation(U), Chap 3, Interpolating Values

)2(21

)))(((21

021

0121'

0

PPP

PPPPP

Page 38: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang38

Catmull-Rom Spline Example

Animation(U), Chap 3, Interpolating Values

Page 39: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang39

Catmull-Rom Spline Drawback

An internal tangent is not dependent on the position of the internal point relative to its two neighbors

Animation(U), Chap 3, Interpolating Values

Page 40: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang41

Splines and Other Interpolation Forms

See Computer Graphics textbooks Review

Appendix B.4 in Parent

Animation(U), Chap 3, Interpolating Values

Page 41: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang42

Now What?

We have key frames or points We have a way to specify the space curve Now we need to specify velocity to traverse

the curve

Speed Curves

Animation(U), Chap 3, Interpolating Values

Page 42: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang43

Speed Control The speed of tracing a curve needs to be under the

direct control of the animator Varying u at a constant rate will not necessarily

generate P(u) at a constant speed.

Animation(U), Chap 3, Interpolating Values

Page 43: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang44

Generally, equally spaced samples in parameter space are not equally spaced along the curve

Non-uniformity in Parametrization

A

B

C

D

Time = 0

Time = 10

Time = 35

Time = 60

)()( 1212 ususuu

duuPuPuPus zyx222 )()()()(

Animation(U), Chap 3, Interpolating Values

Page 44: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang45

Arc Length Reparameterization

To ensure a constant speed for the interpolated value, the curve has to be parameterized by arc length (for most applications)

Computing arc length Analytic method (many curves do not have, e.g., B-

splines) Numeric methods

Table and differencing Gaussian quadrature

Animation(U), Chap 3, Interpolating Values

Page 45: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang46

Arc Length Reparameterization

Space curve vs. time-distance function Relates time to the distance traveled along the

curve, i.e., Relates time to the arc length along the curve

Animation(U), Chap 3, Interpolating Values

Page 46: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang47

Arc Length Reparameterization Given a space curve with arc length

parameterization Allow movement along the curve at a constant speed by

stepping at equal arc length intervals Allows acceleration and deceleration along the curve by

controlling the distance traveled in a given time interval Problems

Given a parametric curve and two parameter values u1 and u2, find arclength(u1,u2)

Given an arc length s, and parameter value u1, find u2 such that arclength(u1,u2) = s

Animation(U), Chap 3, Interpolating Values

Page 47: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang48

Arc Length Reparameterization

Converting a space curve P(u) to a curve with arc-length parameterization Find s=S(u), and u=S-1(s)=U(s) P*(s)=P(U(s))

Analytic arc-length parameterization is difficult or impossible for most curves, e.g., B-spline curve cannot be parameterized with arc length. Approximate arc-length parameterization

Animation(U), Chap 3, Interpolating Values

Page 48: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang49

Forward Differencing Sample the curve at small intervals of the parameter Compute the distance between samples Build a table of arc length for the curve

u Arc Length0.0 0.00

0.1 0.08

0.2 0.19

0.3 0.32

0.4 0.45

… …

Animation(U), Chap 3, Interpolating Values

Page 49: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang50

Arc Length Reparameterization Using Forward Differencing

Given a parameter u, find the arc length Find the entry in the table closest to this u Or take the u before and after it and interpolate arc

length linearlyu Arc Length

0.0 0.00

0.1 0.08

0.2 0.19

0.3 0.32

0.4 0.45

… …

Animation(U), Chap 3, Interpolating Values

Page 50: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang51

Arc Length Reparameterization Using Forward Differencing

Given an arc length s and a parameter u1, find the parametric value u2 such that arclength(u1, u2)=s Find the entry in the table closest to this u using binary search Or take the u before and after it and interpolate linearly

u Arc Length0.0 0.00

0.1 0.08

0.2 0.19

0.3 0.32

0.4 0.45

… …

Animation(U), Chap 3, Interpolating Values

Page 51: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang52

Arc Length Reparameterization Using Forward Differencing

Easy to implement, intuitive, and fast Introduce errors

Super-sampling in forming table 1000 equally spaced parameter values + 1000 ebtries in

each interval Better interpolation Adaptive forward differencing

Animation(U), Chap 3, Interpolating Values

Page 52: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang53

Arc Length Reparameterization Using Adaptive forward differencing

Animation(U), Chap 3, Interpolating Values

Page 53: Chap 3 Interpolating Values

Arc Length Reparameterization Using Numerical Integral

Arc length integral

Simpson’s and trapezoidal integration using evenly spaced intervals

Gaussian quadrature using unevenly spaced intervals

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang54

duuPuPuPus zyx222 )()()()(

Page 54: Chap 3 Interpolating Values

Speed Control

Given a arc-length parameterized space curve, how to control the speed at which the curve is traced? By a speed-control functions that relate an equally

spaced time interval to arc length Input time t, output arc length: s=S(t) Linear function: constant speed control Most common: ease-in/ease-out

Smooth motion from stopped position, accelerate, reach a max velocity, and then decelerate to a stop position

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang55

Page 55: Chap 3 Interpolating Values

Speed Control Function

Relates an equally spaced time interval to arc length Input time t, output arc length: s=S(t) Normalized arc length parameter

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang56

s=ease(t)

Start at 0, slowly increasein value and gain speed until themiddle value andthen decelerate as it approaches to 1.

Page 56: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang57

Constant Velocity Speed Curve

Moving at 1 m/s if meters and seconds are the units Too simple to be what we want

Animation(U), Chap 3, Interpolating Values

Page 57: Chap 3 Interpolating Values

Distance Time Functionand Speed Control

We have a space curve p=P(u) and a speed control function s=S(t).

For a given t, s=S(t) Find the corresponding value u=U(s) by looking

up an arc length table for a given s A point on the space curve with parameter u p=P(U(S(t)))

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang58

Page 58: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang59

Speed Control

u Arc Length0.0 0.00

0.1 0.08

0.2 0.19

0.3 0.32

0.4 0.45

… …

t*

s*u*)( *uP

Speed Control Curve

Arc Length Table

Animation(U), Chap 3, Interpolating Values

Page 59: Chap 3 Interpolating Values

Distance Time Function

Assumptions on distance time function The entire arc length of the curve is to be traversed

during the given total time Additional optional assumptions

The function should be monotonic in t The function should be continuous

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang60

Page 60: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang61

Ease-in/Ease-out

Most useful and most common ways to control motion along a curve

(distance)

Time

Arc length

Equally spaced samples in time specify arc length required for that frame

Animation(U), Chap 3, Interpolating Values

Page 61: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang62

Ease-in/Ease-outSine Interpolation

-1

1

p/2p/2

Time

Arc Length

22 ),sin( pp

10 ,21)

2( sin

21)(ease ttts pp

Animation(U), Chap 3, Interpolating Values

Page 62: Chap 3 Interpolating Values

Ease-in/Ease-outSine Interpolation

The speed of s w.r.t. t is never constant over an interval but rather is always accelerating or decelerating.

Zero derivatives at t=0 and t=1 indicating smooth accelerating and deceleration at end points.

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang63

Page 63: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang64

Ease-in/Ease-outPiecing Curves Together for Ease In/Out

Time

Linear segmentArc Length

Sinusoidal segments

Animation(U), Chap 3, Interpolating Values

Page 64: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang65

Ease-in/Ease-outPiecing Curves Together for Ease In/Out

Animation(U), Chap 3, Interpolating Values

Page 65: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang66

Ease-in/Ease-outIntegrating to avoid the sine function

acceleration

time

t1 t2

A

D

velocity

timet1 t2

v

arc length

time

V1 = V2 A*t1 = - D*(1-t2)

Find v such that area = 1

Animation(U), Chap 3, Interpolating Values

Page 66: Chap 3 Interpolating Values

Ease-in/Ease-outIntegrating to avoid the sine function

To avoid the transcendental function evaluation while providing a constant speed interval between ease-in and ease-out intervals Acceleration-time curve Velocity-time curve

Velocity-time curve is defined by integral of the acceleration-time curve

Distance-time curve is defined by integral of the velocity-time curve

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang67

Page 67: Chap 3 Interpolating Values

Ease-in/Ease-outIntegrating to avoid the sine function

In ease-in/ease-out function Velocity starts out at 0 and ends at 0

V1 = V2 inplies A*t1 = - D*(1-t2)

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang68

Page 68: Chap 3 Interpolating Values

Ease-in/Ease-outIntegrating to avoid the sine function

Total distance = 1 implies 1 = ½ V0 t + V0 (t2-t1)+1/2 V0 (1-t2) Users specifies any two of three variables t1, t2, and V0,

and the system can solve for the third

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang69

Page 69: Chap 3 Interpolating Values

Ease-in/Ease-outIntegrating to avoid the sine function

The result is Parabolic ease-in/ease-out More flexible than the sinusoidal ease-in/ease-out

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang70

Page 70: Chap 3 Interpolating Values

CS, NCTU, J. H. Chuang71

Videos Bunny (Blue Sky Studios, 1998)

Animation(U), Chap 3, Interpolating Values

Page 71: Chap 3 Interpolating Values

Review - Quaternions Similar to axis-angle representations

4-tuple of real numbers q=(s, x, y, z) or [s, v]s is a scalar; v is a vector

The quaternion for rotating an angle about an axis (an axis-angle rotation):

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang72

q

X

Y

Z

a=(ax, ay, az)

If a is unit length, then q will be also

),,()2

sin(),2

cos(

)),,(,(Rot

zyx

zyx

aaa

aaaq

qq

q

Page 72: Chap 3 Interpolating Values

Review - Quaternions

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang73

If a is unit length, then q will be also

112

sin2

cos2

sin2

cos

2sin

2cos

2sin

2sin

2sin

2cos

22222

22222

2222222

23

22

21

20

qqqq

qq

qqqq

a

q

zyx

zyx

aaa

aaa

qqqq

Page 73: Chap 3 Interpolating Values

Review - Quaternions Rotating some angle around an axis is the same as

rotating the negative angle around the negated axis

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang74

qzyxzyx

),,)(

2sin(),

2cos(Rot ),,(,

qqq

Page 74: Chap 3 Interpolating Values

75

Review - Quaternion Math Addition

Multiplication

Multiplication is associative but not commutative

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

21212211 , , , vvssvsvs

21122121212211 , , , vvvsvsvvssvsvs

1221 qqqq 321321 )()( qqqqqq

Page 75: Chap 3 Interpolating Values

76

Review - Quaternion Math (cont.)

Multiplicative identity: [1, 0,0,0]

Inverse

Normalization for unit quaternion

2222 zyxsq

0 ,0 ,0 ,11 qq

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

qqq

2222 zyxsq

qq 0 ,0 ,0 ,1

2

1 ,q

vsq 0 ,0 ,0 ,11 qq

qqq

Page 76: Chap 3 Interpolating Values

77

Review – Rotating Vectors Using Quaternion

A point in space, v, is represented as [0, v] To rotate a vector v using quaternion q

Represent the vector as v = [0, v] Represent the rotation as a quaternion q Using quaternion multiplication

The proof isn’t that hard Note that the result v’ always has zero scalar value

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

1)(' qvqvRotv q

Page 77: Chap 3 Interpolating Values

Review - Compose Rotations Rotating a vector v by first quaternion p

followed by a quaternion q is like rotation using qp

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang78

)()()(

)())((

1

11

1

vRotqpvqp

qqpvp

pvpRotvRotRot

qp

qpq

Page 78: Chap 3 Interpolating Values

Review - Compose Rotations To rotate a vector v by quaternion q followed

by its inverse quaternion q-1

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang79

vqqvqq

qvqRotvRotRotqqq

11

1)())(( 11

Page 79: Chap 3 Interpolating Values

80

Review - Quaternion Interpolation A quaternion is a point on a 4D unit sphere

Unit quaternion: q=(s,x,y,z), ||q|| = 1 Form a subspace: a 4D sphere

Interpolating quaternion means moving between two points on the 4D unit sphere A unit quaternion at each step – another point on the 4D unit sphere Move with constant angular velocity along the greatest circle between the two points on the 4D unit sphere

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

Page 80: Chap 3 Interpolating Values

81

Review - Linear Interpolation Linear interpolation generates unequal spacing

of points after projecting to circle

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

Page 81: Chap 3 Interpolating Values

82

Want equal increment along arc connecting two quaternion on the spherical surface Spherical linear interpolation (slerp)

Normalize to regain unit quaternion

Review – Spherical Linear Interpolation (slerp)

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

)(cos and 1 to0 from goes where

sin)sin(

sin))1sin((),,(

211

2121

qqu

ququuqqslerp

q

qq

qq

Page 82: Chap 3 Interpolating Values

83

Review – Spherical Linear Interpolation (slerp)

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

2121

1

21

21

sin)sin(

sin))1sin((),,(

give to

,

,1 :givenfor solvecan We

Let

ququuqqslerp

uqqqq

q

qqq

qq

qq

qq

Page 83: Chap 3 Interpolating Values

84

Review – Spherical Linear Interpolation (slerp)

2q

1q

2q

021 qq

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

Page 84: Chap 3 Interpolating Values

85

Review – Spherical Linear Interpolation (slerp)

Recall that q and –q represent same rotation What is the difference between:

Slerp(u, q1, q2) and Slerp(u, q1, -q2) ? One of these will travel less than 90 degrees while

the other will travel more than 90 degrees across the sphere

This corresponds to rotating the ‘short way’ or the ‘long way’

Usually, we want to take the short way, so we negate one of them if their dot product is < 0

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

Page 85: Chap 3 Interpolating Values

86

Review – Spherical Linear Interpolation (slerp)

Animation(U), Chap 2, Tech. Background CS, NCTU, J. H. Chuang

If we have an intermediate position q2, the interpolation from q1-->q2-->q3 will not necessarily follow the same path as the interpolation from q1 to q3.

Page 86: Chap 3 Interpolating Values

87

Interpolating a Series of Quaternions As linear interpolation in Euclidean space, we

can have first order discontinuity problem when interpolating a series of orientations.

Need a cubic curve interpolation to maintain first order continuity in Euclidean space

Similarly, slerp can have 1st order discontinuity We also need a cubic curve interpolation in 4D

spherical space for 1st order continuity

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 87: Chap 3 Interpolating Values

Interpolating a Series of Quaternions

Interpolated points […, pn-1, pn, pn+1, ….] in 3D Between each pair of points, two control

points will be constructed. e.g., For pn an : the one intermediate after pn

bn : the one immediately before pn

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang88

pn+(pn-pn-

1)Take average

Page 88: Chap 3 Interpolating Values

Interpolating a Series of Quaternions Interpolated points […, pn-1, pn, pn+1, ….] in 3D

Between each pair of points, two control points will be constructed. e.g., For pn

an : the one intermediate after pn

bn : the one immediately before pn

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang89

bn =pn+(pn-an)

Page 89: Chap 3 Interpolating Values

Interpolating a Series of Quaternions Interpolated points […, pn-1, pn, pn+1, ….] in 3D

End conditions

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang90

Page 90: Chap 3 Interpolating Values

Interpolating a Series of Quaternions Interpolated points […, pn-1, pn, pn+1, ….] in 3D

Between any 2 interpolated points pn and pn+1, a cubic Bezier curve segment is defined by pn, an, bn+1, and pn+1

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang91

Page 91: Chap 3 Interpolating Values

Interpolating a Series of Quaternions

How to evaluate a point on Bezier curve? De Casteljau Construction

Constructing Bezier curve by multiple linear interpolation

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang92

u=1/3

p(1/3)

Page 92: Chap 3 Interpolating Values

Interpolating a Series of Quaternions

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang93

Animation: Seehttp://en.wikipedia.org/wiki/File:Bezier_3_big.gif

Page 93: Chap 3 Interpolating Values

Interpolating a Series of Quaternions

Bezier interpolation on 4D sphere? How are control points generated? How are cubic Beziers defined?

Control points are automatically generated as it is not intuitive to manually adjust them on a 4D sphere

Derive Bezier curve points by iteratively subdivision s on pn, an, bn+1, and pn+1

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang94

Page 94: Chap 3 Interpolating Values

95

1

11 '

'),'(sec

nn

nnnn qq

qqqqtBi

Interpolating a Series of QuaternionsConnecting Segments on 4D Sphere

Automatically generating interior (spherical) control points

qn-1

qn

qn+1

qn’an

1. Double the arc

2. Bisect the span

111' )(2),( nnnnnnn qqqqqqdoubleq

bn

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

),( nnn qadoubleb

Page 95: Chap 3 Interpolating Values

96

1nqnq

Interpolating a Series of QuaternionsDe Casteljau Construction on 4D Sphere

p1 slerp(qn ,an, 13)

p2 slerp(an ,bn1, 13)

p3 slerp(bn1,qn1, 13)

p12 slerp(p1, p2, 13)

p23 slerp(p2, p3, 13)

p slerp(p12, p23, 13)

u=1/3

P(1/3)

na1nb

1p

2p

3p

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang

Page 96: Chap 3 Interpolating Values

Path Following

Issues about path following Arc length parameterization and speed control Changing the orientation Smoothing a path Path along a surface

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang97

Page 97: Chap 3 Interpolating Values

Orientation Along a Curve

A local coordinate system (u, v, w) is defined for an object to be animated Position along the path P(s), denoted as POS w-axis: the direction the object is facing v-axis: up vector u-axis: perpendicular to w and v (u, v, w): a right-handed coordinate system

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang98

Page 98: Chap 3 Interpolating Values

Orientation Along a Curve

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang99

Page 99: Chap 3 Interpolating Values

Orientation Along a CurveFrenet Frame

Frenet frame: a moving coordinate system determined by curve tangent and curvature

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang100

wuvsPsPu

sPw

)(')("

)('

Page 100: Chap 3 Interpolating Values

Orientation Along a CurveFrenet Frame

Problems No concept of “up” vector Is undefined in segments that has no curvature;

i.e., P”(u)=0 Can be dealt with by interpolating a Frenet frame from

the Frenet frames at segment’s boundary, which differ by only a rotation around w

A discontinuity in the curvature vector Frenet frame has a discontinuous jump in orientation

Resulting motions are usually too extreme and not natural looking

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang101

Page 101: Chap 3 Interpolating Values

Orientation Along a CurveFrenet Frame

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang102

Page 102: Chap 3 Interpolating Values

Orientation Along a CurveFrenet Frame

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang103

Page 103: Chap 3 Interpolating Values

Orientation Along a CurveCamera Path Following

COI: center of interest A fixed point in the scene Center point of an object in the scene Points along the path itself Points on a separate path in the scene Points on the interpolation between points in the

scene

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang104

wuvwu

w

y_axis

POSCOI

wuvwu

sPsCw

y_axis

)( )(

wuvsPsUwu

sPsCw

))()((

)( )(

Page 104: Chap 3 Interpolating Values

Smoothing a Pathwith Linear Interpolation

Two points on either sides of a point are averaged, and this point is averaged with the original point.

Repeated application

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang105

11

11

41

21

41

22'

iii

iii

i PPP

PPPP

Page 105: Chap 3 Interpolating Values

Smoothing a Pathwith Linear Interpolation

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang106

Page 106: Chap 3 Interpolating Values

Smoothing a Pathwith Cubic Interpolation

Four points on either sides of a point are fitted by a cubic curve, and the midpoint of the curve is averaged with the original point.

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang107

dcbaPP

dcbaPP

dcbaPP

dPP

dcubuauuP

i

i

i

i

)1(43

169

6427)4/3(

41

161

641)4/1(

)0(

)(

2

1

1

2

23

Page 107: Chap 3 Interpolating Values

Smoothing a Pathwith Cubic Interpolation

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang108

Page 108: Chap 3 Interpolating Values

Smoothing a Pathwith Cubic Interpolation

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang109

Page 109: Chap 3 Interpolating Values

Determine a Path on a Surface

If one object is to move across the surface of another object, we need to specify a path across the surface. Given start and destination points

Find a shortest path between the points – expensive Determine a plane that contain two points and is

generally perpendicular to the surface (averaged normal of two points)

Intersection of the plane with the surface (mesh)

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang110

Page 110: Chap 3 Interpolating Values

Determine a Path on a Surface

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang111

Page 111: Chap 3 Interpolating Values

Determine a Path on a Parametric Surface

Given start and destination points on parametric domain

Define the straight line connecting two points in the parametric space

The curve on the surface corresponding to this line

Animation(U), Chap 3, Interpolating Values CS, NCTU, J. H. Chuang112