Interpolating values

Post on 03-Jan-2016

40 views 4 download

Tags:

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

Interpolating values

CSE 3541Matt 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?• Pathfinding data• Animator specified

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

Interpolation terms

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

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

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

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

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

Bilinear interpolation application

• Resizing an image

Bilinear vs. bicubic interpolation

Higher order interpolation requires more sample points

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

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

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

Lab 5

See specification

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?

Interpolation vs. Approximation

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

Continuity ordersC-1

discontinuous C0 continuous

C1 first derivative is continuous C2

first and second derivatives are continuous

Local vs. Global control

Information requirements

just the points

tangents

interior control points

just beginning and ending tangents

Curve Formulations

•General solution– Lagrange Polynomial

•Piecewise cubic polynomials– Catmull-Rom– Bezier

Lagrange Polynomial

x

jk

k kj

kjj xx

xxyxP

1

)(

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

Lagrange Polynomial

x

jk

k kj

kjj xx

xxyxP

1

)(

Written explicitly term by term is:

Lagrange Polynomial

Results are not always good for animation

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

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

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

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

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

Catmull-Rom spline derivation

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

Catmull-Rom spline derivation

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

Catmull-Rom spline derivation

• Solve for ci in terms of control points

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

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)

Bezier Curve

p0

p1

p2

p3

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

x(u)•

de Casteljau Algorithm

• Describe the curve as a recursive series of linear interpolations

• Intuitive, but not the most efficient form

de Casteljau Algorithm

p0

p1

p2

p3

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

de Casteljau Algorithm

p0

q0

p1

p2

p3

q2

q1

322

211

100

,,

,,

,,

ppq

ppq

ppq

uLerp

uLerp

uLerp

Lerp = linear interpolation

de Casteljau Algorithm

q0

q2

q1

r1

r0

211

100

,,

,,

qqr

qqr

uLerp

uLerp

de Casteljau Algorithm

r1x

r0•

10 ,, rrx uLerp

Bezier Curve

x•

p0

p1

p2

p3

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

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

Reparameterizing by Arc Length

AnalyticForward differencing

SupersamplingAdaptive approach

NumericallyAdaptive Gaussian

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

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

Speed Control

Time-distance functionEase-in Ease-out

SinusoidalCubic polynomialConstant acceleration

General distance-time functions

time

distance

Time Distance Function

s = S(t)

s

t the global time variable

S

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

Ease-in: Sinusoidal

2/)12/sin()( tteases

Ease-in: Single Cubic

23 32)( ttteases

Ease-in: Constant Acceleration

Ease-in: Constant Acceleration

Ease-in: Constant Acceleration

Ease-in: Constant Acceleration

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

Arbitrary Speed ControlAnimators can work in:

Distance-time space curves

Velocity-time space curves

Acceleration-time space curves

Set time-distance constraints