Sei sulla pagina 1di 32

Constrained

Dynamics

Andrew Witkin
Carnegie Mellon University

SIGGRAPH 97 COURSE NOTES

SF1

PHYSICALLY BASED MODELING

Beyond Points and Springs


You can make just about anything out of point
masses and springs, in principle.
In practice, you can make anything you want
as long as its jello.
Constraints will buy us:
Rigid links instead of goopy springs.
Ways to make interesting contraptions.

SIGGRAPH 97 COURSE NOTES

SF2

PHYSICALLY BASED MODELING

A bead on a wire
Desired Behavior:
The bead can slide freely
along the circle.
It can never come off,
however hard we pull.

Question:
How does the bead move
under applied forces?

SIGGRAPH 97 COURSE NOTES

SF3

PHYSICALLY BASED MODELING

Penalty Constraints
Why not use a spring to hold the
bead on the wire?
Problem:
Weak springs goopy
constraints
Strong springs neptune
express!

A classic stiff system.

SIGGRAPH 97 COURSE NOTES

SF4

PHYSICALLY BASED MODELING

The basic trick (f = mv version)


f

fc
f'

f N
fc = N
NN

SIGGRAPH 97 COURSE NOTES

1st order world.


Legal velocity: tangent to
circle (Nv = 0).
Project applied force f onto
tangent: f' = f + fc
Added normal-direction
force fc: constraint force.
No tug-of-war, no stiffness.

f = f + f c

SF5

PHYSICALLY BASED MODELING

f = ma
N

Same idea, but


Curvature () has to match.
depends on both a and v:

the faster youre going, the


faster you have to turn.

v
f'

fc

SIGGRAPH 97 COURSE NOTES

Calculate fc to yield a legal


combination of a and v.
Blechh!

SF6

PHYSICALLY BASED MODELING

Now for the Algebra


Fortunately, theres a general recipe
for calculating the constraint force.
First, a single constrained particle.
Then, generalize to constrained
particle systems.

SIGGRAPH 97 COURSE NOTES

SF7

PHYSICALLY BASED MODELING

Representing Constraints

I. Implicit:

C(x) = x - r = 0
II. Parametric:

x = r cos ,sin

Point-on-circle

SIGGRAPH 97 COURSE NOTES

SF8

PHYSICALLY BASED MODELING

Maintaining Constraints Differentially


C=0

C=0

Start with legal position


and velocity.
Use constraint forces to
ensure legal curvature.

C=0

SIGGRAPH 97 COURSE NOTES

C = 0 legal position
C = 0 legal velocity
C = 0 legal curvature

SF9

PHYSICALLY BASED MODELING

C
N=
x

Constraint Gradient
Implicit:

C(x) = x - r = 0
Differentiating C gives
a normal vector.
This is the direction
our constraint force
will point in.

Point-on-circle

SIGGRAPH 97 COURSE NOTES

SF10

PHYSICALLY BASED MODELING

Constraint Forces
fc = N

Point-on-circle

SIGGRAPH 97 COURSE NOTES

Constraint force: gradient


vector times a scalar, .
Just one unknown to solve
for.
Assumption: constraint is
passiveno energy gain or
loss.

SF11

PHYSICALLY BASED MODELING

Constraint Force Derivation


C(x(t))
C=Nx

C=
Nx
t
=Nx+Nx

fc = N

x =

f + fc
m

= 0, solve for :
Set C
Nx Nf
= -m
NN NN

C
2C
Notation: N = , N =
x
xt

SIGGRAPH 97 COURSE NOTES

Constraint force is N.

SF12

PHYSICALLY BASED MODELING

Example: Point-on-circle
Write down the constraint
equation.

C= x -r
C x
N=
=
x x
2C 1
xx
=
N=
xx
xx
xt x

Take the derivatives.


Substitute into generic
template, simplify.

Nx Nf
(xx)2
= m
= -m
- m(xx) - xf 1
xx
NN NN
x

SIGGRAPH 97 COURSE NOTES

SF13

PHYSICALLY BASED MODELING

Drift and Feedback


In principle, clamping C at zero is enough.
Two problems:

Constraints might not be met initially.


Numerical errors can accumulate.
A feedback term handles both problems:

C = - C - C, instead of
C=0

and are magic constants.

SIGGRAPH 97 COURSE NOTES

SF14

PHYSICALLY BASED MODELING

Tinkertoys
Now we know how to simulate a bead on a
wire.
Next: a constrained particle system.
E.g. constrain particle/particle distance to
make rigid links.

Same idea, but

SIGGRAPH 97 COURSE NOTES

SF15

PHYSICALLY BASED MODELING

Constrained particle systems


Particle system: a point in state space.
Multiple constraints:
each is a function Ci(x1,x2,)

Legal state: Ci= 0, i.


Simultaneous projection.
Constraint force: linear combination of
constraint gradients.
Matrix equation.

SIGGRAPH 97 COURSE NOTES

SF16

PHYSICALLY BASED MODELING

Compact Particle System Notation


q = WQ
q: 3n-long state vector.

q = x 1,x 2, ,x n
Q = f 1,f 2, ,f n
m1

Q: 3n-long force vector.


M: 3n x 3n diagonal mass
matrix.
W: M-inverse (elementwise reciprocal)

SIGGRAPH 97 COURSE NOTES

SF17

m1
m1

M=
mn
mn
mn

W = M-1

PHYSICALLY BASED MODELING

Particle System Constraint Equations


Matrix equation for

JWJT

= -Jq - JW Q

Constrained Acceleration

q = W Q + JT

More Notation
C = C1,C2, ,Cm
= 1,2, , m
C
J=
q
2C
J=
qt

Derivation: just like bead-on-wire.

SIGGRAPH 97 COURSE NOTES

SF18

PHYSICALLY BASED MODELING

How do you implement all this?


We have a global matrix equation.
We want to build models on the fly, just like
masses and springs.
Approach:

Each constraint adds its own piece to


the equation.

SIGGRAPH 97 COURSE NOTES

SF19

PHYSICALLY BASED MODELING

Each constraint
contributes one or more
blocks to the matrix.

Matrix Block
Structure

Sparsity: many empty


blocks.

C
C
x i

xi

C
x j

xj

Modularity: let each


constraint compute its
own blocks.
Constraint and particle
indices determine block
locations.

SIGGRAPH 97 COURSE NOTES

SF20

PHYSICALLY BASED MODELING

fc

x
v
f
m

C
Global Stuff

Global and Local

SIGGRAPH 97 COURSE NOTES

x
v
f

SF21

Constraint

PHYSICALLY BASED MODELING

Constraint Structure
Each constraint
must know how
to compute these C
x
v
f
m

p1
x
v
f

C C
,
x 1 x 2

2C 2C
,
x 1t x 2t

Distance Constraint

C = x1 - x2 - r

p2

SIGGRAPH 97 COURSE NOTES

SF22

PHYSICALLY BASED MODELING

Constrained Particle Systems


particles n time forces nforces consts nconsts

x x
v v
f f

m m

x
v
f

F F F

F
C C C

Added Stuff

SIGGRAPH 97 COURSE NOTES

SF23

PHYSICALLY BASED MODELING

x x
v v
f f

m m

Modified Deriv Eval Loop

x
1
v
f

Clear Force
Accumulators
x x
v v
f f

m m

x
v
f
m

Apply forces
Added Step

C C C

Return to solver

SIGGRAPH 97 COURSE NOTES

F F F

SF24

Compute and apply


Constraint Forces

PHYSICALLY BASED MODELING

Constraint Force Eval


After computing ordinary forces:

Loop over constraints, assemble


global matrices and vectors.
Call matrix solver to get , multiply
by JT to get constraint force.
Add constraint force to particle
force accumulators.

SIGGRAPH 97 COURSE NOTES

SF25

PHYSICALLY BASED MODELING

Impress your Friends


The requirement that constraints not
add or remove energy is called the
Principle of Virtual Work.
The 's are called Lagrange Multipliers.
The derivative matrix, J, is called the
Jacobian Matrix.

SIGGRAPH 97 COURSE NOTES

SF26

PHYSICALLY BASED MODELING

A whole other way to do it.

I. Implicit:

C(x) = x - r = 0

II. Parametric:

x = r cos ,sin

Point-on-circle

SIGGRAPH 97 COURSE NOTES

SF27

PHYSICALLY BASED MODELING

Parametric Constraints
Parametric:
x = r cos ,sin

Constraint is always
met exactly.
One DOF: .
Solve for .

Point-on-circle

SIGGRAPH 97 COURSE NOTES

SF28

PHYSICALLY BASED MODELING

Parametric bead-on-wire (f = mv)


N

x is not an independent
variable.

f
fc

SIGGRAPH 97 COURSE NOTES

x
T=

First stepget rid of it:


x = f +mfc

f = mv (constrained)

x = T

chain rule

f
+
f
T = m c

combine

SF29

PHYSICALLY BASED MODELING

For our
next trick

f
fc

x
T=

SIGGRAPH 97 COURSE NOTES

As before, assume fc points in


the normal direction, so
Tfc = 0
We can nuke fc by dotting T
into both sides:
from last slide
T = f +mfc
Tf +Tfc blam!
TT =
m
Tf
1
=m
TT

SF30

rearrange.

PHYSICALLY BASED MODELING

Parametric Constraints: Summary


Generalizations: f = ma, particle systems
Like implicit case (see notes.)

Big advantages:
Fewer DOFs.
Constraints are always met.

Big disadvantages:
Hard to formulate constraints.
No easy way to combine constraints.

Offical name: Lagrangian dynamics.

SIGGRAPH 97 COURSE NOTES

SF31

PHYSICALLY BASED MODELING

Things to try at home:


A bead on a wire (implicit, parametric)
A double pendulum.
A triple pendulum.
Simple interactive tinkertoys.

SIGGRAPH 97 COURSE NOTES

SF32

PHYSICALLY BASED MODELING

Potrebbero piacerti anche