Position Based Dynamics: Matthias Mu Ller, Bruno Heidelberger, Marcus Hennix, John Ratcliff
Position Based Dynamics: Matthias Mu Ller, Bruno Heidelberger, Marcus Hennix, John Ratcliff
18 (2007) 109–118
www.elsevier.com/locate/jvci
q
Position based dynamics
a,*
Matthias Müller , Bruno Heidelberger a, Marcus Hennix a, John Ratcliff b
a
AGEIA Technologies, Technoparkstrasse 1, 8005 Zürich, Switzerland
b
AGEIA Technologies, 4041 Forest Park Avenue, St. Louis, MO 63108, USA
Abstract
The most popular approaches for the simulation of dynamic systems in computer graphics are force based. Internal and external
forces are accumulated from which accelerations are computed based on Newton’s second law of motion. A time integration method
is then used to update the velocities and finally the positions of the object. A few simulation methods (most rigid body simulators)
use impulse based dynamics and directly manipulate velocities. In this paper we present an approach which omits the velocity layer
as well and immediately works on the positions. The main advantage of a position based approach is its controllability. Overshooting
problems of explicit integration schemes in force based systems can be avoided. In addition, collision constraints can be handled easily
and penetrations can be resolved completely by projecting points to valid locations. We have used the approach to build a real time cloth
simulator which is part of a physics software library for games. This application demonstrates the strengths and benefits of the method.
2007 Elsevier Inc. All rights reserved.
Keywords: Physically based simulation; Game physics; Integration schemes; Cloth simulation
1047-3203/$ - see front matter 2007 Elsevier Inc. All rights reserved.
doi:10.1016/j.jvcir.2007.01.005
110 M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118
in connection with explicit integration. So the main fea- Müller et al. ([2]) simulate deformable objects by
tures and advantages of position based dynamics are moving points towards certain goal positions which are
found by matching the rest state to the current state of
• Position based simulation gives control over explicit the object. Their integration method is the closest to
integration and removes the typical instability problems. the one we propose here. They only treat one specialized
• Positions of vertices and parts of objects can directly be global constraint and, therefore, do not need a position
manipulated during the simulation. solver.
• The formulation we propose allows the handling of gen- Fedor ([9]) uses Jakobsen’s approach to simulate char-
eral constraints in the position based setting. acters in games. His method is tuned to the particular prob-
• The explicit position based solver is easy to understand lem of simulating human characters. He uses several
and implement. skeletal representations and keeps them in sync via
projections.
Faure ([10]) uses a Verlet integration scheme by modify-
2. Related work ing the positions rather than the velocities. New positions
are computed by linearizing the constraints while we work
The recent state of the art report ([1]) gives a good with the non linear constraint functions directly.
overview of the methods used in computer graphics to We define general constraints via a constraint function
simulate deformable objects, e.g. mass-spring systems, as ([11]) and ([12]). Instead of computing forces as the
the finite element method or finite difference approaches. derivative of a constraint function energy, we directly solve
Apart from the citation of ([2]), position based dynamics for the equilibrium configuration and project positions.
does not appear in this survey. However, parts of the posi- With our method we derive a bending term for cloth which
tion based approach have appeared in various papers is similar to the one proposed in ([13]) and ([14]) but
without naming it explicitly and without defining a com- adopted to the point based approach.
plete framework. In Section 4 we use the position based dynamics
Jakobsen ([3]) built his Fysix engine on a position approach for the simulation of cloth. Cloth simulation
based approach. His central idea was to use a Verlet has been an active research field in computer graphics in
integrator and manipulate positions directly. Because recent years. Instead of citing the key papers of the field
velocities are implicitly stored by current and the previ- individually we refer the reader to ([1]) for a comprehensive
ous positions, the velocities are implicitly updated by survey.
the position manipulation. While he focused mainly on
distance constraints, he only gave vague hints on how 3. Position based simulation
more general constraints could be handled. In this paper
we present a fully general approach which handles In this section we will formulate the general position
general constraints. We also focus on the important issue based approach. With cloth simulation, we will give a par-
of conservation of linear and angular momenta by posi- ticular application of the method in the subsequent and in
tion projection. We work with explicit velocities instead the results section. We consider a three dimensional world.
of storing previous positions which makes damping and However, the approach works equally well in two
friction simulation much easier. dimensions.
Desbrun ([4]) and Provot ([5]) use constraint projection
in mass spring systems to prevent springs from overstret- 3.1. Algorithm overview
ching. In contrast to a full position based approach, projec-
tion is only used as a polishing process for those springs We represent a dynamic object by a set of N vertices and
that are stretched too much and not as the basic simulation M constraints. A vertex i 2 [1, . . . , N] has a mass mi, a posi-
method. tion xi and a velocity vi.
Bridson et al. use a traditional force based approach A constraint j 2 [1, . . . , M] consists of
for cloth simulation ([6]) and combine it with a geomet-
ric collision resolving algorithm based on positions to • a cardinality nj,
make sure that the collision resolving impulses are kept • a function C j : R3nj ! R,
within stable bounds. The same holds for the kinemati- • a set of indices fi1 ; . . . inj g, ik 2 [1, . . . N],
cal collision correction step proposed by Volino et al. • a stiffness parameter kj 2 [0 . . . 1] and
([7]). • a type of either equality or inequality.
A position based approach has been used by Clavet
et al. ([8]) to simulate viscoelastic fluids. Their approach Constraint j with type equality is satisfied if
is not fully position based because the time step appears C j ðxi1 ; . . . ; xinj Þ ¼ 0. If its type is inequality then it is satis-
in various places of their position projections. Thus, the fied if C j ðxi1 ; . . . ; xinj Þ P 0. The stiffness parameter kj
integration is only conditionally stable as regular explicit defines the strength of the constraint in a range from zero
integration. to one.
M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118 111
Based on this data and a time step Dt, the dynamic the vertices to a physically valid configuration pi computed
object is simulated as follows: by the constraint solver. The only possible source for insta-
bilities is the solver itself which uses the Newton-Raphson
(1) forall vertices i method to solve for valid positions (see Section 3.3). How-
(2) initialize xi ¼ x0i , vi ¼ v0i , wi = 1/mi ever, its stability does not depend on the time step size but
(3) endfor on the shape of the constraint functions.
(4) loop The integration does not fall clearly into the category of
(5) forall vertices i do vi ‹ vi + Dtwifext(xi) implicit or explicit schemes. If only one solver iteration is
(6) dampVelocities(v1, . . . , vN) performed per time step, it looks more like an explicit
(7) forall vertices i do pi ‹ xi + Dtvi scheme. By increasing the number of iterations, however,
(8) forall vertices i do a constrained system can be made arbitrarily stiff and the
generateCollisionConstraints(xi fi pi) algorithm behaves more like an implicit scheme. Increasing
(9) loop solverIterations times the number of iterations shifts the bottleneck from collision
(10) projectConstraints(C 1 ; . . . ; C MþM coll ; p1 ; . . . ; pN ) detection to the solver.
(11) endloop
(12) forall vertices i 3.2. The solver
(13) vi ‹ (pi xi)/Dt
(14) xi ‹ p i The input to the solver are the M + Mcoll constraints
(15) endfor and the estimates p1, . . . , pN for the new locations of the
(16) velocityUpdate(v1, . . . , vN) points. The solver tries to modify the estimates such that
(17) endloop they satisfy all the constraints. The resulting system of
equations is non-linear. Even a simple distance constraint
Lines (1)–(3) just initialize the state variables. The core C(p1, p2) = jp1 p2j d yields a non-linear equation. In
idea of position based dynamics is shown in lines (7), (9)– addition, the constraints of type inequality yield inequali-
(11) and (13)–(14). In line (7), estimates pi for new locations ties. To solve such a general set of equations and inequal-
of the vertices are computed using an explicit Euler integra- ities, we use a Gauss–Seidel-type iteration. The original
tion step. The iterative solver (9)–(11) manipulates these Gauss–Seidel algorithm (GS) can only handle linear sys-
position estimates such that they satisfy the constraints. tem. The part we borrow from GS is the idea of solving
It does this by repeatedly project each constraint in a each constraint independently one after the other. How-
Gauss–Seidel type fashion (see Section 3.2). In steps (13) ever, in contrast to GS, solving a constraint is a non linear
and (14), the positions of the vertices are moved to the opti- operation. We repeatedly iterate through all the constraints
mized estimates and the velocities are updated accordingly. and project the particles to valid locations with respect to
This is in exact correspondence with a Verlet integration the given constraint alone. In contrast to a Jacobi-type iter-
step and a modification of the current position ([3]), ation, modifications to point locations immediately get vis-
because the Verlet method stores the velocity implicitly as ible to the process. This speeds up convergence significantly
the difference between the current and the last position. because pressure waves can propagate through the material
However, working with velocities allows for a more intui- in a single solver step, an effect which is dependent on the
tive way of manipulating them. order in which constraints are solved. In over-constrained
The velocities are manipulated in line (5), (6) and (16). situations, the process can lead to oscillations if the order
Line (5) allows to hook up external forces to the system is not kept constant.
if some of the forces cannot be converted to positional con-
straints. We only use it to add gravity to the system in 3.3. Constraint projection
which case the line becomes vi ‹ vi + Dtg, where g is the
gravitational acceleration. In line (6), the velocities can be Projecting a set of points according to a constraint
damped if this is necessary. In Section 3.5 we show how means moving the points such that they satisfy the con-
to add global damping without influencing the rigid body straint. The most important issue in connection with mov-
modes of the object. Finally, in line (16), the velocities of ing points directly inside a simulation loop is the
colliding vertices are modified according to friction and conservation of linear and angular momentum. Let Dpi
restitution coefficients. be the displacement of vertex i by the projection. Linear
The given constraints C1, . . . , CM are fixed throughout momentum is conserved if
X
the simulation. In addition to these constraints, line (8) mi Dpi ¼ 0; ð1Þ
generates the Mcoll collision constraints which change from i
time step to time step. The projection step in line (10) con-
which amounts to conserving the center of mass. Angular
siders both, the fixed and the collision constraints.
momentum is conserved if
The scheme is unconditionally stable. This is because the X
integration steps (13) and (14) do not extrapolate blindly ri mi Dpi ¼ 0; ð2Þ
into the future as traditional explicit schemes do but move i
112 M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118
Fig. 1. A known deformation benchmark test, applied here to a cloth character under pressure.
where the scaling factor Fig. 2. Projection of the constraint C(p1, p2) = jp1 p2j d. The correc-
tions Dpi are weighted according to the inverse masses wi = 1/mi.
M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118 113
ever, the resulting material stiffness is still dependent on the 3.5. Damping
time step of the simulation. Real time environments typi-
cally use fixed time steps in which case this dependency is In line (6) of the simulation algorithm the velocities are
not problematic. dampened before they are used for the prediction of the
new positions. Any form of damping can be used and many
3.4. Collision detection and response methods for damping have been proposed in the literature
(see ([1])). Here we propose a new method with some inter-
One advantage of the position based approach is how esting properties:
simply collision response can be realized. In line (8) of the P P
simulation algorithm the Mcoll collision constraints are gen- (1) xcm ¼ P i xi mi =P i mi
erated. While the first M constraints given by the object rep- (2) vcm ¼P i vi mi = i mi
resentation are fixed throughout the simulation, the (3) L =P iri · (mivi)
additional Mcoll constraints are generated from scratch at (4) I ¼ i~ri~rTi mi
each time step. The number of collision constraints Mcoll (5) x = I1L
varies and depends on the number of colliding vertices. (6) forall vertices i
Both, continuous and static collisions can be handled. For (7) Dvi = vcm + x · ri vi
continuous collision handling, we test for each vertex i the (8) vi ‹ vi + kdamping Dvi
ray xi fi pi. If this ray enters an object, we compute the entry (9) endfor
point qc and the surface normal nc at this position. An
inequality constraint with constraint function C(p) = Here ri = xi xcm, ~ri is the 3 by 3 matrix with the prop-
(p qc) Æ nc and stiffness k = 1 is added to the list of con- erty ~ri v ¼ ri v, and kdamping 2 [0 . . . 1] is the damping
straints. If the ray xi fi pi lies completely inside an object, coefficient. In lines (1)–(5) we compute the global linear
continuous collision detection has failed at some point. In velocity xcm and angular velocity x of the system. Lines
this case we fall back to static collision handling. We com- (6)–z(9) then only damp the individual deviations Dvi of
pute the surface point qs which is closest to pi and the surface the velocities vi from the global motion vcm + x · ri. Thus,
normal ns at this position. An inequality constraint with con- in the extreme case kdamping = 1, only the global motion
straint function C(p) = (p qs) Æ ns and stiffness k = 1 is survives and the set of vertices behaves like a rigid body.
added to the list of constraints. Collision constraint genera- For arbitrary values of kdamping, the velocities are globally
tion is done outside of the solver loop. This makes the sim- dampened but without influencing the global motion of the
ulation much faster. There are certain scenarios, however, vertices.
where collisions can be missed if the solver works with a fixed
collision constraint set. Fortunately, according to our 3.6. Attachments
experience, the artifacts are negligible.
Friction and restitution can be handled by manipulating With the position based approach, attaching vertices to
the velocities of colliding vertices in step (16) of the algo- static or kinematic objects is quite simple. The position of
rithm. The velocity of each vertex for which a collision con- the vertex is simply set to the static target position or
straint has been generated is dampened perpendicular to updated at every time step to coincide with the position
the collision normal and reflected in the direction of the of the kinematic object. To make sure other constraints
collision normal. containing this vertex do not move it, its inverse mass wi
The collision handling discussed above is only correct is set to zero.
for collisions with static objects because no impulse is
transferred to the collision partners. Correct response for 4. Cloth simulation
two dynamic colliding objects can be achieved by simulat-
ing both objects with our simulator, i.e. the N vertices and We have used the point based dynamics framework to
M constraints which are the input to our algorithm simply implement a real time cloth simulator for games. In this
represent two or more independent objects. Then, if a point section we will discuss cloth specific issues thereby giving
q of one objects moves through a triangle p1, p2, p3 of concrete examples of the general concepts introduced in
another object, we insert an inequality constraint with con- the previous section.
straint function C(q, p1, p2, p3) = ±(q p1) Æ [(p2 p1) ·
(p3 p1)] which keeps the point q on the correct side of 4.1. Representation of cloth
the triangle. Since this constraint function is independent
of rigid body modes, it will correctly conserve linear and Our cloth simulator accepts as input arbitrary triangle
angular momentum. Collision detection gets slightly more meshes. The only restriction we impose on the input mesh
involved because the four vertices are represented by rays is that it represents a manifold, i.e. each edge is shared by at
xi fi pi. Therefore the collision of a moving point against most two triangles. Each node of the mesh becomes a sim-
a moving triangle needs to be detected (see section about ulated vertex. The user provides a density q given in mass
cloth self collision). per area [kg/m2]. The mass of a vertex is set to the sum
114 M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118
Fig. 3. With the bending term we propose, bending and stretching are independent parameters. The top row shows ðk stretching ; k bending Þ ¼ ð1; 1Þ; ð12 ; 1Þ and
1
ð100 ; 1Þ. The bottom row shows ðk stretching ; k bending Þ ¼ ð1; 0Þ; ð12 ; 0Þ and ð100
1
; 0Þ.
M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118 115
and stiffness k = 1 to the set of constraints. Here ti1 , ti2 and The piece of cloth shown in Fig. 6 is composed of 1364
ti3 are the three indices of the vertices belonging to triangle vertices and 2562 triangles. The simulation runs at 30 fps
i. The sum computes the actual volume of the closed mesh. on average including self collision detection, collision han-
It is compared against the original volume V0 times the dling and rendering. The effect of friction is shown in
overpressure factor kpressure. This constraint function yields Fig. 9, where the same piece of cloth is tumbling in a rotat-
the gradients ing barrel.
X X X
rpi C ¼ ðptj ptj Þ þ ðptj ptj Þ þ ðptj ptj Þ: ð14Þ
2 3 3 1 1 2
j:t1j ¼i j:t2j ¼i j:t3j ¼i 5.4. Tearing and stability
These gradients have to be scaled by the scaling factor gi- Fig. 10 shows a piece of cloth consisting of 4264 vertices
ven in Eq. (7) and weighted by the masses according to and 8262 triangles that is torn open by an attached cube
Eq. (8) to get the final projection offsets Dpi. and finally ripped apart by a thrown ball. This scene is sim-
ulated and rendered with 47 fps on average. Tearing is sim-
5. Results ulated by a simple process: whenever the stretching of an
edge exceeds a specified threshold value, we select one of
We have integrated our method into Rocket ([17]), a the edge’s adjacent vertices. We then put a split plane
game-like environment for physics simulation. Various through that vertex perpendicular to the edge direction
Fig. 8. Cloth stripes are attached via one way interaction to static rigid bodies at the top and via two way constraints to rigid bodies at the bottom.
Fig. 9. Influenced by collision, self collision and friction, a piece of cloth tumbles in a rotating barrel.
Fig. 10. A piece of cloth is torn open by an attached cube and ripped apart by a thrown ball.
Fig. 11. Three inflated characters experience multiple collisions and self collisions.
and split the vertex. All triangles above the split plane are 5.5. Complex simulation scenarios
assigned to the original vertex while all triangles below are
assigned to the duplicate. Our method remains stable even The presented method is especially suited for complex
in extreme situations as shown in Fig. 1, a scene inspired by simulation environments (see Fig. 12). Despite the exten-
([18]). An inflated character model is squeezed through sive interaction with animated characters and geometrically
rotating gears resulting in multiple constraints, collisions complex game levels, simulation and rendering of multiple
and self collisions acting on single cloth vertices (Fig. 11). pieces of cloth can still be done at interactive speed.
M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118 117
Fig. 12. Extensive interaction between pieces of cloth and an animated game character (left), a geometrically complex game level (middle) and hundreds of
simulated plant leaves (right).
2 on onx onx
3
6. Conclusions op1x
x
op1y op1z
on 6 7
6 on ony ony 7
We have presented a position based dynamics frame- ¼ 6 op1xy op1y op1z 7 ðA:1Þ
op1 4 5
work that can handle general constraints formulated via onz onz onz
op1x op1y op1z
constraint functions. With the position based approach it 02 3 1
is possible to manipulate objects directly during the simula- 0 p2z p2y
1 B6 p
tion. This significantly simplifies the handling of collisions, ¼ @4 2z 0 p2x 7 TC
5 þ nðn p2 Þ A: ðA:2Þ
jp1 p2 j
attachment constraints and explicit integration and it p2y p2x 0
makes direct and immediate control of the animated scene
possible.
We have implemented a robust cloth simulator on top of Shorter and for both arguments we have
this framework which provides features like two way inter-
action of cloth with rigid bodies, cloth self collision and on 1 TÞ
response and attachments of pieces of cloth to dynamic ¼ ðp~2 þ nðn p2 Þ ; ðA:3Þ
op1 jp1 p2 j
rigid bodies.
on 1
¼ ðp~1 þ nðn p1 ÞTÞ ; ðA:4Þ
7. Future work op2 jp1 p2 j
A topic we have not treated in this paper is rigid body where ~p is the matrix with the property ~px ¼ p x.
simulation. However, the approach we presented could
quite easily be extended to handle rigid objects as well.
Instead of computing a set of linear and angular impulses
for the resolution of collisions as regular rigid body solvers Appendix B. Bending constraint projection
typically do, movements and rotations would be applied to
the bodies at the contact points and the linear and angular The constraint function for bending is C =
velocities would have to be adjusted accordingly after the arccos(d) u0, where d ¼ n1 n2 ¼ nT1 n2 . Without loss of
solver has completed. generality we set p1 = 0 and get for the normals
n1 ¼ jpp2 p 3
and n2 ¼ jpp2 p 4
. With dxd arccosðxÞ ¼ pffiffiffiffiffiffiffi
1
we
2 p3 j 2 p4 j 1x2
get the following gradients:
Acknowledgment
T !
The authors thank our employer AGEIA for making the 1 on1
research and development on this topic possible. rp3 C ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffi2 n2 ; ðA:6Þ
1d op3
T !
1 on2
rp4 C ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffi2 n1 ; ðA:7Þ
Appendix A. Gradient of the normalized cross product 1d op4
T T !
1 on1 on2
Constraint functions often contain normalized cross rp2 C ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffi2 n2 þ n1 ; ðA:8Þ
products. To derive the projection corrections, the gradient 1d op 2 op2
of the constraint function is needed. Therefore it is useful rp1 C ¼ rp2 C rp3 C rp4 C: ðA:9Þ
to know the gradient of a normalized cross product with
respect to both arguments. Given the normalized cross
product n ¼ jpp1 p2
, the derivative with respect to the first Using the gradients of normalized cross products, first
1 p2 j
vector is compute
118 M. Müller et al. / J. Vis. Commun. Image R. 18 (2007) 109–118