CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using...

25
1 CS 231 Animation Using Dynamic Simulation CS 231 CS 231 Animation Using Dynamic Simulation Animation Using Dynamic Simulation What is dynamics for animation? What is dynamics for animation? forward dynamics integrator graphics state Loosely, using physical rules Loosely, using physical rules or principles to animate, a or principles to animate, a procedural approach procedural approach Usually, the use of a forward Usually, the use of a forward dynamics model and numeric dynamics model and numeric routine to compute motion routine to compute motion Got its start in engineering Got its start in engineering simulation and robotics simulation and robotics

Transcript of CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using...

Page 1: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

1

CS 231

Animation Using Dynamic Simulation

CS 231CS 231

Animation Using Dynamic Simulation Animation Using Dynamic Simulation

What is dynamics for animation?What is dynamics for animation?

forwarddynamics

integrator

graphics

state

Loosely, using physical rulesLoosely, using physical rulesor principles to animate, a or principles to animate, a procedural approach procedural approach

Usually, the use of a forwardUsually, the use of a forwarddynamics model and numeric dynamics model and numeric routine to compute motionroutine to compute motion

Got its start in engineeringGot its start in engineeringsimulation and roboticssimulation and robotics

Page 2: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

2

Forward Dynamics vs. Inverse DynamicsForward Dynamics vs. Inverse Dynamics

force andforce andtorquetorque

acceleration,acceleration,velocityvelocity

forwardforward

inverseinverse

Forward: given forces and torques, computeForward: given forces and torques, computeacceleration, velocity, and finally positionacceleration, velocity, and finally position

Inverse: given motion (positions), compute theInverse: given motion (positions), compute theforces and torques forces and torques

Why use forward dynamics?Why use forward dynamics?

Captures realistic movements because it isCaptures realistic movements because it isbased on physical constraintsbased on physical constraints

Can provide highCan provide high--level control over level control over animationanimation

Can allow principled methods for animatedCan allow principled methods for animatedelements to communicate elements to communicate –– leading toleading torich simulated worldsrich simulated worlds

AKA: initial value problemAKA: initial value problem

Page 3: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

3

Types of simulationsTypes of simulations

PassivePassiveParticle systemsParticle systems

Spring/Mass systems Spring/Mass systems

Rigid bodiesRigid bodies

ActiveActiveArticulated rigid bodies Articulated rigid bodies -- linkageslinkages

Passive Passive vsvs Active dynamicsActive dynamics

model ofdynamics

integrator

graphics

control

userinputs

model ofdynamics

integrator

graphicsuser

inputs

PassivePassive

Active Active

Page 4: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

4

Maya, etc support passive dynamics Maya, etc support passive dynamics Particles, deformations (cloth), rigid bodiesParticles, deformations (cloth), rigid bodiesGravity, collisions, frictionGravity, collisions, friction

SpringSpring--mass systemsmass systems

2D meshes = cloth2D meshes = cloth3D meshes = 3D meshes = jello,blobsjello,blobs

Page 5: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

5

Particle (Mass) SystemParticle (Mass) System

F(tF(t) = ma) = ma

xx’’’’ = = F(t)/mF(t)/m -- One second order equationOne second order equation

mtF

tv

tv

tx

dt

dY

dt

d

/)(

)(

)(

)(

or:or:

vv’’ = = F(t)/mF(t)/m -- Two first order equations Two first order equations

xx’’ = v= v

Particle (Mass) SystemParticle (Mass) System

Use Euler Integration to update:Use Euler Integration to update:

1) Find New Velocity:1) Find New Velocity:

2) Find New Position:2) Find New Position: tttvtxttx )()()(

tm

tFtvttv

)()()(

Page 6: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

6

Gravity(mg)

Particle (mass) systemParticle (mass) system

Gravity

External Force

Particle (mass) systemParticle (mass) system

Page 7: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

7

Differential equation Differential equation –– visual reviewvisual review

),( txfx

x(tx(t): a moving point): a moving pointf(x,tf(x,t): ): xx’’ss velocityvelocity

Vector fieldVector field

The differential equationThe differential equation

defines a vector fielddefines a vector fieldover xover x

),( txfx

Page 8: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

8

Initial value problemInitial value problem

Given the starting point,Given the starting point,follow the integral curvefollow the integral curve

Euler integrationEuler integration

),()()( txtftxttx

Simplest numerical solution methodSimplest numerical solution methodDiscrete time stepsDiscrete time stepsBigger steps, bigger errorsBigger steps, bigger errors

Page 9: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

9

InaccuracyInaccuracy

Error turns this Error turns this x(tx(t), ), a circle into different a circle into different spirals defined by spirals defined by step sizestep size

InaccuracyInaccuracy

Inaccuracy can lead to Inaccuracy can lead to instabilityinstability

Page 10: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

10

Midpoint methodMidpoint method

a)a) Compute a Compute a ““fullfull”” Euler stepEuler step

b) Evaluate f at midpoint, b) Evaluate f at midpoint, ffmidmid

c) Take a step from the original pointc) Take a step from the original pointusing the midpoint f value: using the midpoint f value:

midtftxttx )()(

Approximation of Taylor SeriesApproximation of Taylor Series

Fourth Order Fourth Order –– RungaRunga--KuttaKutta IntegrationIntegration

Many kinds of integratorsMany kinds of integrators

Page 11: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

11

Many kinds of integratorsMany kinds of integrators

Adaptive Steps Adaptive Steps

Take a full step and two half steps from starting Take a full step and two half steps from starting pointpoint

Compare resultsCompare results

If difference is greater than threshold, then reduce If difference is greater than threshold, then reduce time steptime step

Else, possibly increase time stepElse, possibly increase time step

xx00(t)(t)

vv00(t)(t)

Particle PhysicsParticle Physics

xx11(t)(t)

vv11(t)(t)

YY00(t)(t) YY11(t)(t)ODE SolverODE Solver

mtF

tv

tv

tx

dt

dY

dt

d

/)(

)(

)(

)(

void void dydtdydt (double t, double* y, double *(double t, double* y, double *ydotydot))

Page 12: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

12

What is different about rigid body motion?What is different about rigid body motion?

positionposition,,velocityvelocityrotationrotationangular velocityangular velocity

Also, in addition to mass, Also, in addition to mass, mm, , and rotational inertia, and rotational inertia, II

iFtF )(

Net forceNet force

x(tx(t))

v(tv(t))

FF11FF22

FF33

Page 13: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

13

?

)(

?

)(

tF

tv

Yx(tx(t))

v(tv(t))

Body StateBody State

?

)(

?

)(

?

)(

?

)(

tF

tv

tMv

tx

dt

dY

dt

d

Rigid Body Equation of MotionRigid Body Equation of Motion

Page 14: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

14

How does a point move on the surface of the body?How does a point move on the surface of the body?

p(tp(t))

OrientationOrientation

Lets represent orientation as a rotation matrix, Lets represent orientation as a rotation matrix, R(tR(t))

Points move in world space due to rotation:Points move in world space due to rotation:

OrientationOrientation

(Actually, we use (Actually, we use quaternionsquaternions))

)()()( txptRtp o

Page 15: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

15

Lets represent angular velocity as a vector Lets represent angular velocity as a vector (t(t))which is both spin direction and speedwhich is both spin direction and speed

Orientation changeOrientation change

How are How are R(tR(t)) and and (t(t)) related?related?

(t(t))

)(

0)()(

)(0)(

)()(0

)( tR

tt

tt

tt

tRdt

d

xy

xz

yz

Angular VelocityAngular Velocity

**(t)(t) will be shorthand for this matrixwill be shorthand for this matrix

Change inChange in R(tR(t)) due to due to (t(t)) is specified as:is specified as:

Page 16: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

16

Need to relate Need to relate (t(t)) and and massmass to to F(tF(t))

?

)(

)()(

)(

)(

)(

)(

)(*

tF

tRt

tv

t

tMv

tR

tx

dt

dY

dt

d

Rigid Body Equation of MotionRigid Body Equation of Motion

Inertia TensorInertia Tensor

IzzIzyIzx

IyzIyyIyx

IxzIxyIxx

tI )(

Relate angular velocity derivative and mass Relate angular velocity derivative and mass distributiondistribution

Page 17: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

17

?

)(

?

)(

?

)(

?

)(

tF

tv

tMv

tx

dt

dY

dt

d

Rigid Body Equation of MotionRigid Body Equation of Motion

?

)(

)()(

)(

)()(

)(

)(

)(*

tF

tRt

tv

ttI

tMv

tR

tx

dt

dY

dt

d

Rigid Body Equation of MotionRigid Body Equation of Motion

Page 18: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

18

Rigid Body Equation of MotionRigid Body Equation of Motion

)(

)(

)()(

)(

)()(

)(

)(

)(*

t

tF

tRt

tv

ttI

tMv

tR

tx

dt

dY

dt

d

iFtF )(

Net forceNet force

x(tx(t))

v(tv(t))

FF11FF22

FF33

Page 19: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

19

Net torqueNet torque

x(tx(t))

FF11FF22

FF33

ii Ftxpt ))(()(

pp11

pp22

pp33

A few notes on the Inertia TensorA few notes on the Inertia Tensor……

IzzIzyIzx

IyzIyyIyx

IxzIxyIxx

tI )(

Page 20: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

20

dmdm

r = moment armr = moment arm

dmrI 2

Computing InertiaComputing Inertia

ParallelParallel--AxisAxis

Ix = Iy = 1/12 m (3r2 + l2)

Iz = mr2/2

I = Io + md2

d

Computing InertiaComputing Inertia

Page 21: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

21

Approximating Approximating IIbodybody –– Point SamplingPoint Sampling

Pros: Simple, fairly accuratePros: Simple, fairly accurateCons: Expensive, requires volume testCons: Expensive, requires volume test

Inertia tensor varies in world space,Inertia tensor varies in world space,but not in body spacebut not in body space

Page 22: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

22

Rigid Body Equations of MotionRigid Body Equations of Motion

)(

)(

)()(

)(

)()(

)(

)(

)(*

t

tF

tRt

tv

ttI

tMv

tR

tx

dt

dY

dt

d

)(

)(

)()(

)(

)()(

)(

)(

)(*

t

tF

tRt

tv

ttI

tMv

tR

tx

dt

dY

dt

d

Rigid Body Equations of MotionRigid Body Equations of Motion

L(tL(t) ) –– linear momentumlinear momentumH(tH(t) ) –– angular momentumangular momentum

Page 23: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

23

Additional forcesAdditional forces

Gravitational forcesGravitational forces

Wind/air resistanceWind/air resistance

Collisions/impactsCollisions/impacts

FrictionFrictionSliding Sliding –– box on planebox on planeRolling Rolling -- wheel wheel

Forces for collision responseForces for collision response

Page 24: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

24

Articulated rigid bodies Articulated rigid bodies

Linked chain of bodies, Linked chain of bodies,

Possibly branchingPossibly branching

Joint types:Joint types:Slider, telescopingSlider, telescopingHingeHingeUniversal JointUniversal JointGimbalGimbalBall and socketBall and socket

Equations of motion often computed Equations of motion often computed automatically (commercial solvers)automatically (commercial solvers)

No control = rag dollNo control = rag doll

Must provide control Must provide control

Articulated rigid bodies Articulated rigid bodies

Page 25: CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using Dynamic Simulation What is dynamics for animation? forward dynamics integrator graphics

25