You are on page 1of 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 it’s 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)
N f • 1st order world.
fc • Legal velocity: tangent to
f' circle (N·v = 0).
• Project applied force f onto
tangent: f' = f + fc
• Added normal-direction
force fc: constraint force.
• No tug-of-war, no stiffness.
f ⋅N
fc = - N f′ = f + f c
N⋅N

SIGGRAPH ’97 COURSE NOTES SF5 PHYSICALLY BASED MODELING


f = ma • Same idea, but…
• Curvature (κ) has to match.
N f • κ depends on both a and v:
v – the faster you’re going, the
faster you have to turn.
f' fc • Calculate fc to yield a legal
κ combination of a and v.
• Blechh!

SIGGRAPH ’97 COURSE NOTES SF6 PHYSICALLY BASED MODELING


Now for the Algebra …
• Fortunately, there’s 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

• Start with legal position


C=0 C=0 and velocity.
• Use constraint forces to
ensure legal curvature.
C=0 C = 0 legal position
C = 0 legal velocity
C = 0 legal curvature

SIGGRAPH ’97 COURSE NOTES SF9 PHYSICALLY BASED MODELING


Constraint Gradient
∂C
N=
∂x
Implicit:
C(x) = x - r = 0
Differentiating C gives
a normal vector.
This is the direction
Point-on-circle our constraint force
will point in.

SIGGRAPH ’97 COURSE NOTES SF10 PHYSICALLY BASED MODELING


Constraint Forces

fc = λN Constraint force: gradient


vector times a scalar, λ.
Just one unknown to solve
for.
Assumption: constraint is
passive—no energy gain or
loss.
Point-on-circle

SIGGRAPH ’97 COURSE NOTES SF11 PHYSICALLY BASED MODELING


Constraint Force Derivation
C(x(t)) fc = λN

C=N⋅x x =
f + fc
∂ m
C= N⋅x
∂t
=N⋅x+N⋅x ¨ = 0, solve for λ:
Set C
N⋅x N⋅f
λ = -m -
N⋅N N⋅N
∂C ∂2C Constraint force is λN.
Notation: N = , N =
∂x ∂x∂t

SIGGRAPH ’97 COURSE NOTES SF12 PHYSICALLY BASED MODELING


Example: Point-on-circle
C= x -r Write down the constraint
equation.
∂C x
N= =
∂x x Take the derivatives.
∂2C 1 x⋅x Substitute into generic
N= = x- x
∂x∂t x x⋅x template, simplify.

N⋅x N⋅f (x⋅x)2


λ = -m - = m - m(x⋅x) - x⋅f 1
N⋅N N⋅N x⋅x 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 = x 1,x 2, ,x n
q: 3n-long state vector. Q = f 1,f 2, ,f n
m1
Q: 3n-long force vector. m1
m1
M: 3n x 3n diagonal mass M=
mn
matrix. mn
W: M-inverse (element- mn

wise reciprocal) W = M-1

SIGGRAPH ’97 COURSE NOTES SF17 PHYSICALLY BASED MODELING


Particle System Constraint Equations
Matrix equation for λ
More Notation
JWJT λ = -Jq - JW Q
C = C1,C2, ,Cm
Constrained Acceleration λ = λ 1,λ2, ,λ m
∂C
q = W Q + JTλ J=
∂q
∂2C
J=
∂q∂t
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


Matrix Block • Each constraint
Structure contributes one or more
blocks to the matrix.
C • Sparsity: many empty
∂C blocks.
∂x i xi • Modularity: let each
∂C constraint compute its
∂x j xj own blocks.
• Constraint and particle
J indices determine block
locations.

SIGGRAPH ’97 COURSE NOTES SF20 PHYSICALLY BASED MODELING


λ J J fc x
v
x
C f
v
m
f
C m
Global Stuff

Constraint
Global and Local

SIGGRAPH ’97 COURSE NOTES SF21 PHYSICALLY BASED MODELING


Constraint Structure

Each constraint
must know how ∂C ∂C ∂2C ∂2C
, ,
to compute these C C ∂x 1 ∂x 2 ∂x 1∂t ∂x 2∂t

x
p1
v x Distance Constraint
f
m
v p2 C = x1 - x2 - r
f
m

SIGGRAPH ’97 COURSE NOTES SF22 PHYSICALLY BASED MODELING


Constrained Particle Systems

particles n time forces nforces consts nconsts

x x x …F
F F F
v v v
f f … f
m m m C C C … C

Added Stuff

SIGGRAPH ’97 COURSE NOTES SF23 PHYSICALLY BASED MODELING


x x x Modified Deriv Eval Loop
v v v
1
f f … f
m m m 2
F F F …F
Clear Force Apply forces
Accumulators
Added Step
x x x
v v v
f f … f
C C C … C
m m m 4 3
Compute and apply
Return to solver Constraint Forces

SIGGRAPH ’97 COURSE NOTES SF24 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.

x I. Implicit:

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

Point-on-circle x = r cos θ,sin θ

SIGGRAPH ’97 COURSE NOTES SF27 PHYSICALLY BASED MODELING


Parametric Constraints

Parametric:
x
x = r cos θ,sin θ

θ • Constraint is always
met exactly.
• One DOF: θ.
Point-on-circle • Solve for θ.

SIGGRAPH ’97 COURSE NOTES SF28 PHYSICALLY BASED MODELING


Parametric bead-on-wire (f = mv)
N f x is not an independent
variable.
T
fc First step—get rid of it:
∂x
T=
∂θ x = f +mfc f = mv (constrained)

x = Tθ chain rule
f +
Tθ = m cf combine

SIGGRAPH ’97 COURSE NOTES SF29 PHYSICALLY BASED MODELING


For our As before, assume fc points in
next trick… the normal direction, so
T⋅fc = 0
We can nuke fc by dotting T
into both sides:
N f
Tθ = f +mfc from last slide
T
fc
T⋅f +T⋅fc blam!
T⋅Tθ = m
∂x T⋅f
T= θ=m
1 rearrange.
∂θ T⋅T

SIGGRAPH ’97 COURSE NOTES SF30 PHYSICALLY BASED MODELING


Parametric Constraints: Summary
• Generalizations: f = ma, particle systems
– Like implicit case (see notes.)
• Big advantages:
– Fewer DOF’s.
– 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

You might also like