Transcript Document

Penalty Methods for Contact
Resolution
interactive
contact resolution
that usually works
pi
david s wu
1
P
d.s.wu
objective
Determine the force vector to ensure
appropriate behavior for contacting
objects
or alternatively:
make the game do the right thing when
objects collide with one another
- also make it work when they rest on
one another
2
P
d.s.wu
customer requirements


Consistency
Stability
Stability

Perceived accuracy


Customer
Satisfaction

Performance

avoid O(2n) complexity
Iteration that never converges
is not acceptable
Stability

3
known actions may be applied
to produce consistent effect
Performance

Accuracy
behavior should appear correct
Perceived precision or
consistency


uncommon circumstances
should not prevent further play
really important
P
d.s.wu
“what methods are there for
solving the problem?”
•
•
•
•
4
Apply impulses for collisions and forces for
resting contact
Solve using iterative constraints
Declare collision resolution “beyond the
scope of this simulator”
Use Potentials that “encourage”
appropriate behavior (penalty methods)
P
d.s.wu
“which are you currently using?”
•
5
please review title page
P
d.s.wu
“why penalty methods?”






6
penalty methods are trivial to implement
classic analytical methods have many
degenerate configurations
a lot of special cased code is required to
‘elegantly handle’ these
penalty methods decay gracefully in awkward
situations
analytic methods tend to have worst case
performance that is O(n!), O(2n), or O(n3)
penalty methods extend robustly to more
complex problems such as deformable
P
d.s.wu
meeting the needs

Penalty methods

Stability
Doesn’t
explode
Few degenerate
cases
Tends to converge
7
P
d.s.wu
“penalty methods are numerical
hacks”
Before continuing, you will need to accept the
following axioms:
Penalty Methods are not all that bad
I.
They robustly solve many difficult problems
Implementation is intuitive
Most physics researchers and programmers don’t trust
penalty methods
Most programmers who are about to write their first
physics code will implement penalty methods, armed with
their first year physics text





8
Potential methods are not a good place to start, before you
go off and throw arbitrary potentials at every problem you
encounter, learn and understand the more established
methods, these will specify the desired behavior for nondegenerate situations
P
d.s.wu
more persuasion
II. independence between
numerical integration and
contact resolution is a
luxury



9
combining the two can be
justified
solving the problems
independently is the most
most common
implementation
modular, independent
components are nice, but in
this case, they limit your
P
d.s.wu
more persuasion
III. Implicit Euler is not a joke

First order accuracy is really not all that bad


Stiff decay is a good thing




10
provided that it is stable
when things get really nasty, diminishing high frequency
components is desirable
A-Stability is not just an inconsequential feature of obscure
integration schemes
Explicit integration schemes are not suitable for stiff systems
No implicit or explicit multi-step methods are A-Stable
P
d.s.wu
implementation synopsis


Each contact is classified as either a collision or a
resting contact
if (relative velocity * normal > [insert magic
threshold] )




11
collision
otherwise,
 resting contact
Two linear potentials are created. One acts along
normal to repel objects, the other acts on the
tangent plane to represent friction.
nonlinear force along contact normal is
approximated by a piecewise cubic spline
P
d.s.wu
Conventions
(what do those obscure letters mean?)






12
Scalar: lower case
italic, e.g. ‘k’
Vector: lower case
e.g. ‘q’ vector
Matrix: upper case
e.g. ‘M’
q = position
q’ = velocity
q’’ = acceleration
P
d.s.wu
more letters





13
nf = unit vector along collision normal
f = a vector constrained to the tangent plane
sp = jacobian that projects the relative velocity
contact point into the velocity space of the
potential
fn= contact normal reaction force
ff= friction reaction force
P
d.s.wu
Equations

Resting contact normal force:


Collision normal force:



fn=L*(snt*kb+ksn*snt*q+kdn*snt*q’)
ksn is 0
kdn is large
in both cases:

L is a piecewise cubic spline that
smoothly interpolates (e.g. with
continuity of G2)


14
0 when |f| <= 0
1 when |f| >= [insert magic threshold]
P
d.s.wu
continued

Friction forces:
= L * (q’ / |q’| *(k1 + k2*|q’| + k3*|q’|2) )
L is a piecewise cubic spline that smoothly
interpolates (e.g. with continuity of G2)
 ff

0 when |f| <= [insert small magic threshold]
 1 when |f| >= [insert big magic threshold]

15
P
d.s.wu
“discontinuous potentials break
my integrator”


First and second derivatives w.r.t in q and q’ are
continuous (due to the spline being C2), this
should be sufficient for robust equation solvers)
the numerical integration equation is nonlinear
(for Implicit Euler, q(t1) = q(t0) + [step size] * f(q(t1), t1))
 a technique that use a quadratic manifold to
approximate equations will require multiple iterations
(techniques such as Newton/Rhampson Iteration and
Linear Conjugate Gradient)
 in my experience, Quasi-Newton and Nonlinear
Conjugate Gradient are more effective
16
P
d.s.wu
Where do ksx, kdz, etc come
from?

Resting contact


kdz = msz*p
ksz = msz*sqr(p)/8.0


Collision:

kdzc = Msz*p

17
Over damped, velocity half life of p
p is very high, chosen such that 95% of desired velocity will
be reached one after one step
P
d.s.wu
“kdz is too high”

18
use a stable integrator
P
d.s.wu
“you are using potentials to emulate
velocity constraints and impulses”


With backward Euler integration, an impulse
occurring at any point within a time step is
equivalent to a force during the time step with an
equal integral over the time step
Solving the system: q(t1) = q(t0) + [step size] *
f(q(t1), t1) handles over-determined systems
gracefully


19
Each potential is given an explicit priority
Solution applies a weighted least square minimization
to error
P
d.s.wu
Questions

20
Ask questions
P
d.s.wu