cs 775: advanced computer graphicsparagc/teaching/2019/cs775/lectures/05... · cs775: lecture 5...

22
CS 775: Advanced Computer Graphics Lecture 5 : Physically-Based Animation

Upload: others

Post on 27-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS 775: Advanced Computer Graphics

Lecture 5 : Physically-Based Animation

Page 2: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Physically-Based Animation● Given the state of a system,● Initial value problem

x= f (x , t)x x∼d xd t

x(t 0)=x0

The derivative function forms a vector field.

Start here

Follow the vectors.

http://www.pixar.com/companyinfo/research/pbm2001/

Page 3: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Numerical SolutionsEuler’s method x(t 0+h)=x0+h x (t 0)

●Simplest method●Discrete stepsize●Bigger steps, bigger error

●Integral curves of 2D function are concentric circles.

●Drift caused by Euler’s method moves the particle on a spiral instead

f● ● Oscillates● Diverges

f=−k xh>1/kh>2/k

http://www.pixar.com/companyinfo/research/pbm2001/

Page 4: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Numerical SolutionsEuler’s Method

x(t 0+h)=x0+h x (t 0)+h2

2 !x(t 0)+…+

hn

n!∂n x

∂ t n

Consider the Taylor series

Error in Euler’s method: O(h2)

h→h2

h→h2

ϵ→ ϵ4

ϵ

nsteps→2nsteps

For an interval t0 to t1

Page 5: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

5

Explicit Euler - Stability● Let the derivative function be linear● Consider the x parallel to the largest eigenvector of A● Euler update● Solution● Stable when

● Real, negative eigenvalues● Imaginary eigenvalues

xn+1=xn+hλ xn

d xd t

=A x

d xd t

=λ x

xn=(1+hλ)n x0

|1+hλ|≤1⇒−1<1+hλ<1⇒h<2

|λ|

Page 6: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Numerical SolutionsMid-point Method : Improving Euler

x(t 0+h)=x0+h x (t 0)+h2

2 !x(t 0)+O(h3

)

x=∂ f∂ xx=f ' f

f (x+Δ x)=f (x0)+Δ x f ' (x0)+O(Δ x2)

Now,

A Taylor series of the function f gives:

Substitute Δ x=h2f (x0)

x=f (x(t ))assuming

in the equation above, simplify, equations 1 and 2 give

x(t 0+h)=x0+h( f (x0+h2f (x0)))

- (1)

- (2)

Page 7: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Numerical SolutionsMid-point Method

http://www.pixar.com/companyinfo/research/pbm2001/

a. Compute an Euler Step

b. Evaluate f at midpoint

c. Take a step using fmid

Δ x=h2f (x0)

f mid=f (x(t0)+Δ x2

)

x(t 0+h)=x(t 0)+h f mid

x(t 0+h)=x0+h( f (x0+h2f (x0)))

Page 8: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

8

Midpoint Method - Stability● Midpoint update

● Let

● Then stable if

xn+1=(1+hλ+12(hλ)

2)xn

xn+1=xn+hλ xn+

12

xn+1=xn+hλ (xn+12hλ xn)

hλ=a+i b

(1+a+12(a2

−b2))

2

+(b+ab)2≤1

Page 9: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Numerical SolutionsRunge-Kutta of Order 4 (RK4)

k1=h f (x0, t0)

k2=h f (x0+k1

2, t 0+

h2)

k3=h f (x0+k2

2, t0+

h2)

k4=h f (x0+k3 , t0+h)

x(t 0+h)=x0+16k1+

16k3+

16k 3+

16k4

O(h5) error

Page 10: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

10

Runge-Kutta Stability● q-stage, pth-order Runge-Kutta evaluates the derivative function q times in

each iteration and its approximation of the next state is correct within O(hp+1).● RK4 is 4-stage, 4th-order

RK3 RK4

Page 11: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Particle Systems● Motion of the particle is governed by Newton’s laws of

motion.● Phase space equation of motion

● Every particle stores its position, velocity, mass and has a force accumulator.

● A particle system is just a collection of particles.

[ x1, x2, x3, v1, v2, v3]=[v1, v2, v3, f 1/m , f 2/m, f 3/m ]

Page 12: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Particle SystemsTypes of forces:● Unary forces – gravity, drag.

● n-ary forces – springs connecting a set of particles.

f=m g f=−k d v

f a=−[k s(|l|−r )+kd l⋅l|l| ] l|l| f b=−f a

http://www.pixar.com/companyinfo/research/pbm2001/

Page 13: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Particle SystemsTypes of forces:

● Spatial interaction forces – attraction, repulsion in a neighbourhood.

● Lennard-Jones : Pair of neutral atoms or molecules

V LJ=4 ϵ [(σr )12

−(σr )

6

]

Lennard-Jones Potential

Page 14: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Particle Systems

● Blender Fire, Boids

● Reeves, 1983: Particle Systems – A Technique for Modeling Fuzzy Objects

“Genesis Effect” from Start Trek 2: The Wrath of Khan Video Clip from “Particle Dreams” by Karl Sims

Page 15: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

CS775: Lecture 5

Particle Fluids

Saket Patkar, Parag Chaudhuri, Wetting of Porous Solids, IEEE TVCG 2013

Page 16: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

16

Stiff Systems

X (t)=[ x (t)y (t )] X (t)=ddt [ x (t)y (t )]=[ −x (t)−ky (t )]

● If we want to move a particle such that is always stays on the x-axis (particle on a wire), then we can model it as

● Use Euler’s method to update

● If |1-hk| > 1 then Euler’s method will not converge. ● For very large stiffness constant k, step size h is very small

Xnew=X0+h X (t0)=[ x (t)y (t)]+h [−x (t)−ky (t )]

Xnew=[ (1−h) x0

(1−hk) y0]

Page 17: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

17

Implicit EulerExplicit Euler

Implicit Euler

Solving for such that , at time points back at

Xnew=X0+h f (X0)

Xnew f t 0+h X0

f (Xnew)=f (X0)+Δ X f ' (X0) where Δ X=Xnew−X0

Xnew=X0+h f (Xnew)

⇒Xnew=X0+h f (X0)+hΔ X f ' (X0)

and Δ X=( 1hI−f ' (X0))

−1

f (X0)f (X , t )= X (t)

f (X , t ) '=∂ f∂X

Page 18: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

18

Implicit EulerSolving our stiff system with implicit Euler

Δ X=( 1hI−f ' (X0))

−1

f (X0)

f (X (t))=[ −x (t)−ky (t )]f (X (t)) '=[−1 0

0 −k ]

Δ X=[1+hh

0

01+khh

]−1

[ −x0

−ky0]=−[

hh+1

x0

h1+kh

ky0 ]

Page 19: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

19

Implicit Euler – Step SizeLargest step size the implicit solver can take for our problem

limh→∞

Δ X=limh→∞

−[hh+1

x0

h1+kh

ky0 ]=−[

x0

1kky0]=−[ x0

y 0]

i.e., Xnew=X0+(−X0)=0

Page 20: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

20

Implicit Euler - Stability● Implicit update

● Then the solver is stable if

xn+1=xn+hλ xn+1

⇒ xn=x0( 11−hλ )

n

1|1−hλ|

≤1 or |1−hλ|>1

Page 21: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

21

Implicit Euler ● Correct Soln● Explicit Euler● Implicit Euler

● Implicit solver causes numerical

damping. This is not always desirable.● Stability over large step size does not imply accuracy.

x (h)=−k x (h)

x (0)=1

x (h)=e−hk

x (h)=1−hk

x (h)=1

1+hk

x

h

Page 22: CS 775: Advanced Computer Graphicsparagc/teaching/2019/cs775/lectures/05... · CS775: Lecture 5 Numerical Solutions Mid-point Method : Improving Euler x(t0+h)=x0+hx˙ (t0)+ h2 2!

22

Trapezoidal Rule● Half explicit Euler, half implicit Euler

● Where is this stable?

xn+1=xn+h(12f (xn)+

12f (xn+1))