Interpolating values

61
Interpolating values CSE 3541 Matt Boggus

description

Interpolating values. CSE 3541 Matt Boggus. Problem: paths in grids or graphs are jagged. Path smoothing. Path smoothing example. Problem statement. How can we construct smooth paths? Define smooth in terms of geometry What is the input? Where does the input come from? - PowerPoint PPT Presentation

Transcript of Interpolating values

Page 1: Interpolating values

Interpolating values

CSE 3541Matt Boggus

Page 2: Interpolating values

Problem: paths in grids or graphs are jagged

Page 3: Interpolating values

Path smoothing

Page 4: Interpolating values

Path smoothing example

Page 5: Interpolating values

Problem statement

• How can we construct smooth paths?– Define smooth in terms of geometry– What is the input?– Where does the input come from?• Pathfinding data• Animator specified

Page 6: Interpolating values

Interpolation

• Interpolation: The process of inserting in a series an intermediate number or quantity ascertained by calculation from those already known.

• Examples– Computing midpoints– Curve fitting

Page 7: Interpolating values

Interpolation terms

• Order (of the polynomial)– Linear– Quadratic– Cubic

• Dimensions– Bilinear (data in a 2D grid)– Trilinear (data in a 3D grid)

Page 8: Interpolating values

Linear interpolation

• Given two points, P0 and P1 in 2D• Parametric line equation:

P = P0 + t (P1 – P0) ; OR

X = P0.x + t (P1.x – P0.x)

Y = P0.y + t (P1.y – P0.y)

• t = 0 Beginning point P0

• t = 1 End point P1

Page 9: Interpolating values

Linear interpolation• Rewrite the parametric equation

P = (1-t)P0 + t P1 ; OR

X = (1-t)P0.x + t P1.x

Y = (1-t)P0.y + t P1.y

• Formula is equivalent to a weighted average • t is the weight (or percent) applied to P1

• 1 – t is the weight (or percent) applied to P0

• t = 0.5 Midpoint between P0 and P1 = Pmid

• t = 0.25 1st quartile = midpoint between P0 and Pmid

• t = 0.75 3rd quartile = midpoint between Pmid and P1

Page 10: Interpolating values

Bilinear interpolation process

• Given 4 points (Q’s)

• Interpolate in one dimension– Q11 and Q21 give R1

– Q12 and Q22 give R2

• Interpolate with the results– R1 and R2 give P

Page 11: Interpolating values

Bilinear interpolation application

• Resizing an image

Page 12: Interpolating values

Bilinear vs. bicubic interpolation

Higher order interpolation requires more sample points

Page 13: Interpolating values

Curve fitting

•Given a set of points– Smoothly (in time and space) move an object

through the set of points

•Example of additional temporal constraints– From zero velocity at first point, smoothly accelerate

until time t1, hold a constant velocity until time t2, then smoothly decelerate to a stop at the last point at time t3

Page 14: Interpolating values

Example

Observations:

• Order of labels (A,B,C,D) is computed based on time values

• Time differences do not have to correspond to space or distance

• The last specified time is arbitrary

Page 15: Interpolating values

Solution steps

1. Construct a space curve that interpolates the given points with piecewise first order continuity

2. Construct an arc-length-parametric-value function for the curve

3. Construct time-arc-length function according to given constraints

p=P(u)

u=U(s)

s=S(t)

p=P(U(S(t)))

Page 16: Interpolating values

Lab 5

See specification

Page 17: Interpolating values

Choosing an interpolating functionTradeoffs and commonly chosen options

Interpolation vs. approximation

Polynomial complexity: cubic

Continuity: first degree (tangential)

Local vs. global control: local

Information requirements: tangents needed?

Page 18: Interpolating values

Interpolation vs. Approximation

Page 19: Interpolating values

Polynomial complexity

Low complexity reduced computational cost

Therefore, choose a cubic polynomial

With a point of inflection, the curvecan match arbitrary tangents at end points

Page 20: Interpolating values

Continuity ordersC-1

discontinuous C0 continuous

C1 first derivative is continuous C2

first and second derivatives are continuous

Page 21: Interpolating values

Local vs. Global control

Page 22: Interpolating values

Information requirements

just the points

tangents

interior control points

just beginning and ending tangents

Page 23: Interpolating values

Curve Formulations

•General solution– Lagrange Polynomial

•Piecewise cubic polynomials– Catmull-Rom– Bezier

Page 24: Interpolating values

Lagrange Polynomial

x

jk

k kj

kjj xx

xxyxP

1

)(

See http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html for more details

Page 25: Interpolating values

Lagrange Polynomial

x

jk

k kj

kjj xx

xxyxP

1

)(

Written explicitly term by term is:

Page 26: Interpolating values

Lagrange Polynomial

Results are not always good for animation

Page 27: Interpolating values

Polynomial curve formation

• Given by the equationP(u) = au3 + bu2 + cu + d

• u is a parameter that varies from 0 to 1– u = 0 is the first point on the curve– u = 1 is the last point on the curve

• Remember this is a parametric equation!– a, b, c, and d are not scalar values, but vectors

Page 28: Interpolating values

Polynomial curve formation

P(u) = au3 + bu2 + cu + d

• The point P(u) = (x(u), y(u), z(u)) where

x(u) = axu3 + bxu2 + cxu + dx

y(u) = ayu3 + byu2 + cyu + dy

z(u) = azu3 + bzu2 + czu + dz

Page 29: Interpolating values

Polynomial Curve FormulationMatrix multiplication

MBUP T

123 uuuGeometric information (i.e the points or tangents)

Coefficient matrix (given by which type of curve you are using)

Where u is a scalar value in [0,1]

The point at “time” u

Page 30: Interpolating values

So how do we set a, b, c, and d?Or the matrices M and B?

Page 31: Interpolating values

Catmull-Rom spline

• Passes through control points

• Tangent at each point pi is based on the previous and next points: (pi+1 − pi−1)– Not properly defined at start and end• Use a toroidal mapping• Duplicate the first and last points

Page 32: Interpolating values

Catmull-Rom spline derivation

τ is a parameter for tension (most implementations set it to 0.5)

Page 33: Interpolating values

Catmull-Rom spline derivation

Page 34: Interpolating values

Catmull-Rom spline derivation

• Use with cubic equation

Note:- c values correspond to a, b, c, and d in the earlier cubic equation- c values are vectors

Page 35: Interpolating values

Catmull-Rom spline derivation

• Solve for ci in terms of control points

Page 36: Interpolating values

Catmull-Rom matrix form

• Set τ to 0.5 and put into matrix form

1

1

2

23 *

0010

05.005.0

5.025.21

5.05.15.15.0

*1)(

i

i

i

i

p

p

p

p

uuuuP

Page 37: Interpolating values

Blended Parabolas/Catmull-Rom*Visual example

1

1

2

23 *

0010

05.005.0

5.025.21

5.05.15.15.0

*1)(

i

i

i

i

p

p

p

p

uuuuP

* End conditions are handled differently(or assume curve starts at P1 and stops at Pn-2)

Page 38: Interpolating values

Bezier Curve

p0

p1

p2

p3

• Find the point x on the curve as a function of parameter u:

x(u)•

Page 39: Interpolating values

de Casteljau Algorithm

• Describe the curve as a recursive series of linear interpolations

• Intuitive, but not the most efficient form

Page 40: Interpolating values

de Casteljau Algorithm

p0

p1

p2

p3

• Cubic Bezier curve has four points (though the algorithm works with any number of points)

Page 41: Interpolating values

de Casteljau Algorithm

p0

q0

p1

p2

p3

q2

q1

322

211

100

,,

,,

,,

ppq

ppq

ppq

uLerp

uLerp

uLerp

Lerp = linear interpolation

Page 42: Interpolating values

de Casteljau Algorithm

q0

q2

q1

r1

r0

211

100

,,

,,

qqr

qqr

uLerp

uLerp

Page 43: Interpolating values

de Casteljau Algorithm

r1x

r0•

10 ,, rrx uLerp

Page 44: Interpolating values

Bezier Curve

x•

p0

p1

p2

p3

Page 45: Interpolating values

Cubic Bezier

3

2

123

0.00.00.00.1

0.00.00.30.3

0.00.30.60.3

0.10.30.30.1

1

i

i

i

i

p

p

p

p

uuuP

Curve runs through Pi and Pi+3

with starting tangent PiPi+1 and ending tangent Pi+2Pi+3

Page 46: Interpolating values

Controlling Motion along p=P(u)

Step 2. Reparameterization by arc lengthu = U(s) where s is distance along the curve

p=P(u)But segments may nothave equal length

Step 1. vary u from 0 to 1create points on the curve

Step 3. Speed control

s = ease(t) where t is timefor example, ease-in / ease-out

Page 47: Interpolating values

Reparameterizing by Arc Length

AnalyticForward differencing

SupersamplingAdaptive approach

NumericallyAdaptive Gaussian

Page 48: Interpolating values

Reparameterizing by Arc Length - supersample

1.Calculate a bunch of points at small increments in u2.Compute summed linear distances as approximation to arc

length3.Build table of (parametric value, arc length) pairs

Notes1.Often useful to normalize total distance to 1.02.Often useful to normalize parametric value for multi-

segment curve to 1.0

Page 49: Interpolating values

index u Arc Length

(s)

0 0.00 0.000

1 0.05 0.080

2 0.10 0.150

3 0.15 0.230

... ... ...

20 1.00 1.000

Build table of approx. lengths

Page 50: Interpolating values

Speed Control

Time-distance functionEase-in Ease-out

SinusoidalCubic polynomialConstant acceleration

General distance-time functions

time

distance

Page 51: Interpolating values

Time Distance Function

s = S(t)

s

t the global time variable

S

Page 52: Interpolating values

Ease-in/Ease-out Function

s = S(t)

s

t

S

0.0

0.01.0

1.0

Normalize distance and time to 1.0 to facilitate reuse

Page 53: Interpolating values

Ease-in: Sinusoidal

2/)12/sin()( tteases

Page 54: Interpolating values

Ease-in: Single Cubic

23 32)( ttteases

Page 55: Interpolating values

Ease-in: Constant Acceleration

Page 56: Interpolating values

Ease-in: Constant Acceleration

Page 57: Interpolating values

Ease-in: Constant Acceleration

Page 58: Interpolating values

Ease-in: Constant Acceleration

Page 59: Interpolating values

Motion on a curve – solution steps

1. Construct a space curve that interpolates the given points with piecewise first order continuity

2. Construct an arc-length-parametric-value function for the curve

3. Construct time-arc-length function according to given constraints

p=P(u)

u=U(s)

s=S(t)

p=P(U(S(t)))

Page 60: Interpolating values

Arbitrary Speed ControlAnimators can work in:

Distance-time space curves

Velocity-time space curves

Acceleration-time space curves

Set time-distance constraints