Marq Singer (marq@essentialmath)

42
Constrained Dynamics Marq Singer ([email protected])

description

Constrained Dynamics. Marq Singer ([email protected]). The Problem. What are they Why do we care What are they good for. The Basics. Constraint – something that keeps an entity in the system from moving freely - PowerPoint PPT Presentation

Transcript of Marq Singer (marq@essentialmath)

Page 1: Marq Singer  (marq@essentialmath)

Constrained Dynamics

Marq Singer ([email protected])

Page 2: Marq Singer  (marq@essentialmath)

Essential Math for Games

The Problem

• What are they• Why do we care• What are they good for

Page 3: Marq Singer  (marq@essentialmath)

Essential Math for Games

The Basics

• Constraint – something that keeps an entity in the system from moving freely

• For our purposes, we will treat each discreet entity as one particle in a system

• Particles can be doors on hinges, bones in a skeleton, points on a piece of cloth, etc.

Page 4: Marq Singer  (marq@essentialmath)

Essential Math for Games

Box Constraints

• Simplest case• Movement constrained within a 2D area

Page 5: Marq Singer  (marq@essentialmath)

Essential Math for Games

Box Constraints

P

10001000

y

x

PP

1000

Page 6: Marq Singer  (marq@essentialmath)

Essential Math for Games

Box Constraints (cont)

• Restrict P to extents of the box• Recover from violations in position (last

valid, rebound, wrap around)• Simple, yet the basis for the rest of this

Page 7: Marq Singer  (marq@essentialmath)

Essential Math for Games

Bead on a Wire

• The Problem: Restrict bead to path

• Solutions: Explicit (parametric)

method Implicit method

Page 8: Marq Singer  (marq@essentialmath)

Essential Math for Games

Parametric Constraints

]sin,[cos rx

Page 9: Marq Singer  (marq@essentialmath)

Essential Math for Games

Bead on a Wire

• From Baraff, WitkinN = gradientf = forcefc = constraint force

f ‘ = f + fc

Nf

cf'f

NNNNffc

Page 10: Marq Singer  (marq@essentialmath)

Essential Math for Games

Implicit Representation

legal position legal velocity legal acceleration

N

Page 11: Marq Singer  (marq@essentialmath)

Essential Math for Games

Implicit Representation

Constraint force = gradient vector times scalar

N

xCN

0)( rxxC

Nfc

Page 12: Marq Singer  (marq@essentialmath)

Essential Math for Games

Spring Constraints

• Seems like a reasonable choice for soft body dynamics (cloth)

• In practice, not very useful• Unstable, quickly explodes

Page 13: Marq Singer  (marq@essentialmath)

Essential Math for Games

Stiff Constraints

• A special spring case does work• Ball and Stick/Tinkertoy • Particles stay a fixed distance apart• Basically an infinitely stiff spring• Simple• Not as prone to explode

Page 14: Marq Singer  (marq@essentialmath)

Essential Math for Games

Cloth Simulation

• Use stiff springs• Solving constraints by relaxation• Solve with a linear system

Page 15: Marq Singer  (marq@essentialmath)

Essential Math for Games

Cloth Simulation0P 1P

5P

1,0C 2,1C5,0C

Page 16: Marq Singer  (marq@essentialmath)

Essential Math for Games

Cloth Simulation

• Forces on our cloth

mtFtta

tatvttvtvtpttp

ii

iii

iii

)()(

)()()()(

Page 17: Marq Singer  (marq@essentialmath)

Essential Math for Games

Cloth Simulation

• Relaxation is simple• Infinitely rigid springs are stable

1. Predetermine Ci distance between particles

2. Apply forces (once per timestep)3. Calculate for two particles4. If move each particle half the distance5. If n = 2, you’re done!

Page 18: Marq Singer  (marq@essentialmath)

Essential Math for Games

Relaxation Methods0P 1P

1,0C

201

2011,0 )()( yyxx PPPPC

1,001 )( CPPp

0P 1P

1,0C

Page 19: Marq Singer  (marq@essentialmath)

Essential Math for Games

Relaxation Methods0P 1P

1,0C

1,0C0P 1P

2)()(,

2)()(:0 1100

ptPttPptPttPp

2)()(,

2)()(:0 1100

ptPttPptPttPp

Page 20: Marq Singer  (marq@essentialmath)

Essential Math for Games

Cloth Simulation• When n > 2, each particle’s movement

influenced by multiple particles• Satisfying one constraint can

invalidate another• Multiple iterations stabilize system

converging to approximate constraints• Forces applied before iterations• Fixed timestep (critical)

Page 21: Marq Singer  (marq@essentialmath)

Essential Math for Games

More Cloth Simulation

• Use less rigid constraints • Vary the constraints in each direction

(i.e. horizontal stronger than vertical)• Warp and weft constraints

Page 22: Marq Singer  (marq@essentialmath)

Essential Math for Games

Still More Cloth Simulation• Sheer Springs

Page 23: Marq Singer  (marq@essentialmath)

Essential Math for Games

Still More Cloth Simulation• Flex Springs

Page 24: Marq Singer  (marq@essentialmath)

Essential Math for Games

Articulated Bodies

• Pin Joints

• Hinges

Page 25: Marq Singer  (marq@essentialmath)

Essential Math for Games

Angular Constraints

• Restrict the angle between particles• Results in a cone-shaped constraint

Page 26: Marq Singer  (marq@essentialmath)

Essential Math for Games

1x

2x

Angular Constraints

• Unilateral distance constraint• Only apply constraint in one direction

10012 xx

Page 27: Marq Singer  (marq@essentialmath)

Essential Math for Games

Angular Constraints

• Dot product constraint • Recovery is a bit more involved

0102 xxxx

1x

2x

0x

Page 28: Marq Singer  (marq@essentialmath)

Essential Math for Games

Stick Man

• Uses points and hinges• Angular (not shown) allow

realistic orientations• Graphic example of why I’m

an engineer and not an artist

Page 29: Marq Singer  (marq@essentialmath)

Essential Math for Games

Using A Linear System

• Can sum up forces and constraints• Represent as system of linear

equations• Solve using matrix methods

Page 30: Marq Singer  (marq@essentialmath)

Essential Math for Games

Basic Stuff

Systems of linear equations

Where:A = matrix of coefficientsx = column vector of variablesb = column vector of solutions

bAx

Page 31: Marq Singer  (marq@essentialmath)

Essential Math for Games

Basic Stuff• Populating matricies is a bit tricky, see [Boxerman] for a good example

Isolating the ith equation:

i

n

j

jij bxa 1

Page 32: Marq Singer  (marq@essentialmath)

Essential Math for Games

Jacobi Iteration

Solve for xi (assume other entries in x unchanged):

ii

ijk

jijik

i a

xabx

)1(

)(

(Which is basically what we did a few slides back)

Page 33: Marq Singer  (marq@essentialmath)

Essential Math for Games

Jacobi IterationIn matrix form:

bDxULDx kk 1)1(1)( )(

D, -L, -U are subparts of AD = diagonal-L = strictly lower triangular-U = strictly upper triangular

Page 34: Marq Singer  (marq@essentialmath)

Essential Math for Games

Jacobi IterationDefinition (diagonal, strictly lower, strictly upper):

A = D - L - U

DLLLUDLLUUDLUUUD

Page 35: Marq Singer  (marq@essentialmath)

Essential Math for Games

Gauss-Seidel Iteration

Uses previous results as they are available

ii

ij ijk

jijk

jijik

i a

xaxabx

)1()(

)(

Page 36: Marq Singer  (marq@essentialmath)

Essential Math for Games

Gauss-Seidel Iteration

In matrix form:

)()( )1(1)( bUxLDx kk

Page 37: Marq Singer  (marq@essentialmath)

Essential Math for Games

Gauss-Seidel Iteration

• Components depend on previously computed components

• Cannot solve simultaneously (unlike Jacobi)

• Order dependant• If order changes the components of

new iterates change

Page 38: Marq Singer  (marq@essentialmath)

Essential Math for Games

Successive Over Relaxation (SOR)

• Gauss-Seidel has convergence problems

• SOR is a modification of Gauss-Seidel• Add a parameter to G-S

Page 39: Marq Singer  (marq@essentialmath)

Essential Math for Games

Successive Over Relaxation (SOR)

• = a Gauss-Seidel iterate• 0 < • If = 1, simplifies to plain old Gauss-

Seidel

)1()()( )1( ki

ki

ki xxx

x

Page 40: Marq Singer  (marq@essentialmath)

Essential Math for Games

Gauss-Seidel Iteration

In matrix form:

bLD

xDULDx kk

1

)1(1)(

)(

])1([)(

Page 41: Marq Singer  (marq@essentialmath)

Essential Math for Games

Lots More Math(not covered here)

• I highly recommend [Shewchuk 1994]• Steepest Descent• Conjugate Gradient• Newton’s Method (in some cases)• Hessian• Newton variants (Discreet, Quasi,

Truncated)

Page 42: Marq Singer  (marq@essentialmath)

Essential Math for Games

References• Boxerman, Eddy and Ascher, Uri, Decomposing Cloth, Eurographics/ACM

SIGGRAPH Symposium on Computer Animation (2004)• Eberly, David, Game Physics, Morgan Kaufmann, 2003.• Jakobsen, Thomas, Advanced Character Physics, Gamasutra Game

Physics Resource Guide • Mathews, John H. and Fink, Kurtis K., Numerical Methods Using Matlab,

4th Edition, Prentice-Hall 2004• Shewchuk, Jonathan Richard, An Introduction to the Conjugate Gradient

Method Without the Agonizing Pain, August 1994. http://www-2.cs.cmu.edu/~jrs/jrspapers.html

• Witken, Andrew, David Baraff, Michael Kass, SIGGRAPH Course Notes, Physically Based Modeling, SIGGRAPH 2002.

• Yu, David, The Physics That Brought Cel Damage to Life: A Case Study, GDC 2002