32
Physically Based Animation: Mass-Spring Systems CS114, Spring 2016 Shuang Zhao Computer Science Department University of California, Irvine CS114, Spring 2016 Shuang Zhao 1

CS 114 Projects in Advanced 3D Computer Graphics

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 114 Projects in Advanced 3D Computer Graphics

Physically Based Animation:

Mass-Spring Systems

CS114, Spring 2016

Shuang Zhao

Computer Science Department

University of California, Irvine

CS114, Spring 2016 Shuang Zhao 1

Page 2: CS 114 Projects in Advanced 3D Computer Graphics

Previous Lectures

• WebGL

• Physics of light

• Radiometry

• Rendering equation

• Path tracing

CS114, Spring 2016 Shuang Zhao 2

Page 3: CS 114 Projects in Advanced 3D Computer Graphics

Today’s Lecture

• Physically-based animation

• Particle systems• Equations of motion

• Numerical integration (Euler’s method)

• Mass-spring systems

CS114, Spring 2016 Shuang Zhao 3

Page 4: CS 114 Projects in Advanced 3D Computer Graphics

Particle Systems

Physically Based Animation:Mass-Spring Systems

CS114, Spring 2016 Shuang Zhao 4

Page 5: CS 114 Projects in Advanced 3D Computer Graphics

Type of Dynamics

• Point (particle)

• Rigid body

• Deformable body(e.g., elastic materials, fluids, smoke)

CS114, Spring 2016 Shuang Zhao 5

[Zheng & James 2012]

Page 6: CS 114 Projects in Advanced 3D Computer Graphics

Particle Systems

• Collections of small particles maintaining certain states:

• E.g., position, velocity, etc.

• Particle motion affected by (internal/external) forces

• Simulating particle motion = solving ODEs

• To model:

• Sand, flame, fluid, cloth, etc.

CS114, Spring 2016 Shuang Zhao 6

Page 7: CS 114 Projects in Advanced 3D Computer Graphics

Particle Motion

• Mass m, position x, velocity v

• Equations of motion: at time t,

• Simulating a particle’s motion:• Given x(0), v(0);

• Need to find x(t), v(t) for t > 0.

CS114, Spring 2016 Shuang Zhao 7

Newton’s notation

Newton’s

Second Law

Velocity:

Acceleration:

Page 8: CS 114 Projects in Advanced 3D Computer Graphics

Solving Initial Value Problem

• Analytical solutions do NOT exist in general

• We find approximated solutions numerically• Euler’s method

• Mid-point method

• etc.

CS114, Spring 2016 Shuang Zhao 8

Page 9: CS 114 Projects in Advanced 3D Computer Graphics

Initial Value Problem: Example

CS114, Spring 2016 Shuang Zhao 9

Problem:

Analytical

solution:

t

x

Page 10: CS 114 Projects in Advanced 3D Computer Graphics

Euler’s Method

CS114, Spring 2016 Shuang Zhao 10

To solve x(t), one can pick small ∆t > 0 and set

Page 11: CS 114 Projects in Advanced 3D Computer Graphics

Initial Value Problem: Example

CS114, Spring 2016 Shuang Zhao 11

Problem:

Analytical

solution:

Euler’s method:

Page 12: CS 114 Projects in Advanced 3D Computer Graphics

Initial Value Problem: Example

CS114, Spring 2016 Shuang Zhao 12

Problem:

∆t = 5

∆t = 1

∆t = 0.2True

answer

t

x

Smaller ∆t = Better accuracy, lower performance

Page 13: CS 114 Projects in Advanced 3D Computer Graphics

Euler’s Method for 2nd Order ODEs

CS114, Spring 2016 Shuang Zhao 13

Known

Particle motion problem:

Page 14: CS 114 Projects in Advanced 3D Computer Graphics

Particle Motion: Example

CS114, Spring 2016 Shuang Zhao 14

x

y

Gravity!

Analytical solution:

Problem:

Trajectory of

the particle

Page 15: CS 114 Projects in Advanced 3D Computer Graphics

Particle Motion: Example

CS114, Spring 2016 Shuang Zhao 15

Euler’s method:

… …

Ste

p 2

Ste

p 1

Problem:

Page 16: CS 114 Projects in Advanced 3D Computer Graphics

Particle Motion: Example

CS114, Spring 2016 Shuang Zhao 16

Euler’s method:Problem:

x

y

Page 17: CS 114 Projects in Advanced 3D Computer Graphics

Mass-Spring Systems

Physically Based Animation:Mass-Spring Systems

CS114, Spring 2016 Shuang Zhao 17

Page 18: CS 114 Projects in Advanced 3D Computer Graphics

Mass-Spring System

• A collection of particles connected with springs

• Forces to consider• Spring force

• Gravity

• Spatial fields

• Damping force

CS114, Spring 2016 Shuang Zhao 18

Page 19: CS 114 Projects in Advanced 3D Computer Graphics

Forces: Spring Force

CS114, Spring 2016 Shuang Zhao 19

Rest length: L0

L < L0

Force Force

L > L0

Force Force

Page 20: CS 114 Projects in Advanced 3D Computer Graphics

Forces: Spring Force

CS114, Spring 2016 Shuang Zhao 20

Rest length: L0

… …

K: stiffness

Page 21: CS 114 Projects in Advanced 3D Computer Graphics

Forces: Gravity

• Simple gravity:• Depends only on particle mass m

CS114, Spring 2016 Shuang Zhao 21

(g = 9.8 on earth)

Page 22: CS 114 Projects in Advanced 3D Computer Graphics

Forces: Spatial Fields

• Force on a particle only depends on its location• E.g., wind

• Can change over time

CS114, Spring 2016 Shuang Zhao 22

Page 23: CS 114 Projects in Advanced 3D Computer Graphics

Forces: Damping

• Force on a particle• Only depends on its velocity

• Opposes motion

• Removes energy, so system can settle

• Small amount of damping can stabilize solver

CS114, Spring 2016 Shuang Zhao 23

Page 24: CS 114 Projects in Advanced 3D Computer Graphics

Animating Mass-Spring System

• Input:• For each particle i:

• Mass mi, initial position xi(0), initial velocity vi(0)

• For each spring connecting particles i and j:• Stiffness Ki,j

• Output:• Trajectory of each particle xi(t), t > 0

• Normally represented with positions at discrete time-steps: xi(∆t), xi(2∆t), xi(3∆t), …

CS114, Spring 2016 Shuang Zhao 24

Page 25: CS 114 Projects in Advanced 3D Computer Graphics

Animating Mass-Spring System

• Pseudo-code

t = 0

while t < tmax:

for each particle i:

compute accumulated force Fi at this particle

# Euler’s method

ai = Fi/mi # acceleration

vi(t + ∆t) = vi(t) + (∆t)*ai # velocity

xi(t + ∆t) = xi(t) + (∆t)*vi(t) # position

t = t + ∆t

CS114, Spring 2016 Shuang Zhao 25

Page 26: CS 114 Projects in Advanced 3D Computer Graphics

Computing Accumulated Force

# Given particle i at time t

Fi = [0, 0, -mi*g] # gravity

Fi = Fi – cd*vi(t) # damping

for each particle j connected to i by a Spring:

e = Pi – Pj

# Ki,j: Stiffness, Li,j: rest length

Fspring = Ki,j*[Li,j – length(e)]*e/length(e)

Fi = Fi + Fspring

CS114, Spring 2016 Shuang Zhao 26

Page 27: CS 114 Projects in Advanced 3D Computer Graphics

Mass-Spring System for Cloth Simulation

Physically Based Animation:Mass-Spring Systems

CS114, Spring 2016 Shuang Zhao 27

Page 28: CS 114 Projects in Advanced 3D Computer Graphics

Cloth Simulation

• Studied for decades, still an active area

• Elastic sheet model

• Yarn-based model

CS114, Spring 2016 Shuang Zhao 28

[Kaldor et al. 2008]

[Provot 1995] [Baraff et al. 2003]

… …

Page 29: CS 114 Projects in Advanced 3D Computer Graphics

Mass-Spring System for Cloth

• Cloth = a “web” of particles and springs

CS114, Spring 2016 Shuang Zhao 29

Page 30: CS 114 Projects in Advanced 3D Computer Graphics

Mass-Spring System for Cloth

• Consider a rectangular cloth with m×n particles

CS114, Spring 2016 Shuang Zhao 30

… … … …

Structural

Shear

Flexion (bend)

Types of springs

[i, j]—[i, j + 1]; [i, j]—[i + 1, j]

[i, j]—[i + 1, j + 1]; [i + 1, j]—[i, j + 1]

[i, j]—[i, j + 2]; [i, j]—[i + 2, j]

j

i

Page 31: CS 114 Projects in Advanced 3D Computer Graphics

Mass-Spring System for Cloth

• Type of Forces• Spring

• Gravity

• Damping

• Contact

• …

CS114, Spring 2016 Shuang Zhao 31

Page 32: CS 114 Projects in Advanced 3D Computer Graphics

Discretization

• What happens if we discretize our cloth more or less finely?

• Do we get the same behavior?

• Usually NOT! It takes a lot of effort to design discretization-independent schemes.

CS114, Spring 2016 Shuang Zhao 32