Murilo G. Coutinho (Auth.) - Dynamic Simulations of Multibody Systems-Springer-Verlag New York (2001)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 386

Dynamic Simulations

of
Multibody Systems
Springer Science+Business Media, LLC
Murilo G. Coutinho

Dynamic Simulations
of
Multibody Systems

With 148 Illustrations

i Springer
Murilo G. Coutinho
1745 Selby Avenue, #11
Los Angeles, CA 90024
USA
[email protected]

Library of Congress Cataloging-in-Publication Data


Coutinho, Murilo G. (Murilo Gondim)
Dynamic simulations of multibody systems 1 Murilo G. Coutinho.
p. cm.
Includes bibliographical references and index.
ISBN 978-1-4419-2902-0 ISBN 978-1-4757-3476-8 (eBook)
DOI 10.1007/978-1-4757-3476-8
1. Computer simulation. 2. Dynamics, Rigid. I. Title.
QA76.9.C65 C695 2001
003'.3--dc21 2001018409

Printed on acid-free paper.

© 2001 Springer Science+Business Media New York


Originally published by Springer-Verlag New York, Inc. in 2001
Softcover reprint of the hardcover 1st edition 2001

All rights reserved. This work may not be translated or copied in whole or in part without the
written permission of the publisher Springer Science+Business Media, LLC ,
except for brief excerpts in connection with reviews or scholarly analysis. Use
in connection with any form of information storage and retrieval, electronic adaptation, computer
software, or by similar or dissimilar methodology now known or hereafter developed is forbidden.
The use of general descriptive names, trade names, trademarks, etc., in this publication, even if the
former are not especially identified, is not to be taken as a sign that such names, as understood by
the Trade Marks and Merchandise Marks Act, may accordingly be used freely by anyone.

Production managed by Jenny Wolkowicki; manufacturing supervised by Jeffrey Taub.


Photocomposed copy prepared from the author's J8.'IEX files.

987654 32 1

ISBN 978-1-4419-2902-0 SPIN 10789999


To my girls
Izabella and Leticia
Preface

Physically based modeling is increasingly gaining acceptance within the


computer graphics and mechanical engineering industries as a way of achiev-
ing realistic animations and accurate simulations of complex systems. Such
complex systems are usually hard to animate using scripts, and difficult
to analyze using conventional mechanics theory, which makes them perfect
candidates for physically based modeling and simulation techniques.
The field of physically based modeling is broad. It includes everything
from modeling a ball rolling on the floor, to a car engine working, to a hang-
ing shirt being moved by a gust of wind. The theory varies from precise
mathematical methods to purpose-specific approximated solutions that are
mathematically incorrect, but produce realistic animations for the partic-
ular situation being considered. Depending on the case, an approximated
solution might serve the purpose, however, there are times when approx-
imations are not admissible, and the use of accurate simulation engines
is a requirement. Developing and implementing physically based dynamic-
simulation engines that are robust is difficult. The main reason is that it
requires a breadth of knowledge in a diverse set of subjects, each of them
standing alone as a broad and complex topic.
Instead of attempting to address all types of simulation engines available
in the broad area of physically based modeling, this book provides in-depth
coverage of the most common simulation engines. These simulation engines
restrict the general case of physically based modeling to the particular case
wherein the objects interacting are either particles or rigid bodies.
This book is a comprehensive introduction to the techniques needed to
produce realistic simulations and animations of particle and rigid-body sys-
viii Preface

tems. It focuses on both the theoretical and practical aspects of developing


and implementing physically based dynamic-simulation engines that can be
used to generate convincing animations of physical events involving parti-
cles and rigid bodies, such as a jet flow of water pushing dry flowers away on
a patio. It can also be used to produce accurate simulations of mechanical
systems, such as a robotic parts feeder where parts are dropped on a con-
veyor belt and then positioned and aligned as they hit fences strategically
placed on the conveyor and used to align the parts at a specific orientation.
Dynamic Simulations of Multibody Systems was written for computer
graphics, computer animation, computer-aided mechanical design and mod-
eling software developers who want to learn to incorporate physically based
dynamic-simulation features into their own systems. The goal of this book is
to make the principles and methods of physically based modeling of particle
and rigid-body systems accessible to a broader audience of software devel-
opers who are familiar with mainstream computer-graphics techniques, and
the associated mathematics.
The book is organized into three main topics: particle systems, rigid-
body systems, and articulated rigid-body systems. The first chapter is an
overview of how all techniques covered in this book fit together as inde-
pendent modules constituting a simulation engine. The following chapters
and appendices go into more detailed explanations for each technique. The
techniques developed can be used to create simulation engines capable of
combining particles, rigid bodies and articulated rigid bodies into a single
system. Each chapter presents many algorithms and covers them in consid-
erable depth, yet makes their design and analysis accessible to all levels of
readers. We have tried to keep explanations elementary without sacrificing
depth or mathematical rigor.
The most complex mathematical algorithms are described in detail in the
appendices. Our goal here is to focus the reader's attention to the details of
the topic being covered, and not be distracted by mathematical issues that
can be viewed as "black box" modules having specific functionality (such as
a numerical integrator or a rigid-body-mass-properties computation mod-
ule). Readers should be able to develop their own software implementation
of a simulation engine using the techniques covered in-depth in this book,
or shorten their software development effort by taking advantage of the
several resources available on the Web. Links to several Web sites with
commercial and non-commercial software, as well as pointers to all cited
references electronically available, can be found at the Web site supporting
this book at http://hometown.aol.com/ animationengine.
Preface ix

Acknowledgments
I wish to thank my wife, Izabella, who supported me from the start in writ-
ing this book during my nonexistent spare time, and for not complaining
too much about the annoying light emanating from my desk throughout
the endless nights of writing. I also wish to thank our daughter Leticia,
who was born when I was half way through the book, for being such an
incredible baby. I love you both.
As for detailed technical readings of the book, I wish to thank David
Remba for commenting on several chapters and appendices. I also wish to
thank Thiago Coutinho, Antonio Diegues and Eduardo Campos for prepar-
ing an innovative book cover during the pre-production phase.
Lastly, I wish to thank my parents, Murilo and Marilia, for their support,
encouragement and friendship throughout my life.

Murilo Coutinho
Los Angeles, CA April 2001
Contents

Preface vii

1 Computational Dynamics 1
1.1 Introduction............ 1
1.2 Particle and Rigid-Body Systems 2
1.3 Dynamic Simulation Engines .. 3
1.4 A Computationally Efficient Implementation 7
1.4.1 Interface with the Rendering Engine 7
1.4.2 Moving the Objects . . . 10
1.4.3 Checking for Collisions. . 11
1.4.4 Responding to Collisions. 12
1.5 Guide to Readers . . . . . . . . . 14

2 Hierarchical Representation of 3D Polyhedra 17


2.1 Introduction............... 17
2.2 Hierarchical Representation of Objects. 19
2.2.1 Axis-Aligned Bounding Boxes. 20
2.2.2 Oriented Bounding Boxes 22
2.2.3 Bounding Spheres . . . . . . . 25
2.2.4 Convex Hull. . . . . . . . . . . 27
2.3 Hierarchical Representation of the Simulated World 32
2.3.1 Uniform Grid . . 33
2.3.2 Multi-Level Grid . . . . . . . . . . . . . . . . 37
xii Contents

2.4 Collision Detection Between Different Hierarchical Repre-


sentations . . . . . . . . . . . . . . . . . . . . . 42
2.4.1 Computing Box-Box Intersections 42
2.4.2 Computing Sphere-Sphere Intersections 45
2.4.3 Computing Triangle-Triangle Intersections. 46
2.4.4 Point-in-Triangle Test ........ 49
2.4.5 Computing Box-Sphere Intersections . . . 51
2.4.6 Computing Box-Triangle Intersections . . 52
2.4.7 Computing Sphere-Triangle Intersections 53
2.4.8 Computing Line Segment-Sphere Intersections 54
2.4.9 Computing Line Segment-Triangle Intersections. 55
2.5 Notes and Comments. . . . . . . . . . . . . . . . . . . . 57

3 Particle Systems 61
3.1 Introduction. 61
3.2 Particle Dynamics 63
3.3 Interaction Forces. 68
3.3.1 Gravity .. 69
3.3.2 Viscous Drag 69
3.3.3 Damped Springs 70
3.3.4 Spatially Dependent Forces 71
3.3.5 User Interaction . . . . . 76
3.4 Collision Detection: Overview . . . 76
3.4.1 Particle-Particle Collision 78
3.4.2 Particle-Rigid Body Collision 81
3.5 Collision-Detection Implementation. 86
3.5.1 Computing Cylinder-Cylinder Intersections 87
3.5.2 Computing Cylinder-Box Intersections . . . 90
3.5.3 Computing Cylinder-Sphere Intersections 94
3.5.4 Computing Cylinder-Triangle Intersections 97
3.5.5 Point-in-Cylinder Test . . . . . . . . . . . . 105
3.6 Particle-Particle Collision Response. . . . . . . . . 106
3.6.1 Computing Impulsive Forces for a Single Collision 107
3.6.2 Computing Impulsive Forces for Multiple Simultane-
ous Collisions . . . . . . . . . . . . . . . . . . . . 115
3.6.3 Computing Contact Forces for a Single Contact. 120
3.6.4 Computing Contact Forces for Multiple Contacts 129
3.7 Particle-Rigid Body Collision Response 134
3.7.1 Computing Impulsive Forces 136
3.7.2 Computing Contact Forces 137
3.8 Particle Emitter . . . . . . . . . . 138
3.8.1 User-Definable Parameters 140
3.9 Specialized Particle Systems. . . . 142
3.9.1 User-Adjustable Parameters. 143
3.9.2 Overview of Cloth Simulation. 146
Contents xiii

3.10 Notes and Comments. 152

4 Rigid-Body Systems 155


4.1 Introduction . . . . 155
4.2 Rigid-Body Dynamics 156
4.3 Interaction Forces. . 165
4.3.1 Gravity . . . . 165
4.3.2 Viscous Drag 166
4.3.3 Damped Springs 167
4.3.4 User-Interaction Forces 167
4.4 Collision Detection . . . . . . . 168
4.5 Collision Detection between Non-Convex Bodies 172
4.6 Collision Detection between Convex Bodies 174
4.7 The Voronoi Clip Algorithm. 174
4.7.1 Feature b2 is a Vertex 178
4.7.2 Feature b2 is an Edge 179
4.7.3 Feature b2 is a Face 193
4.7.4 Dealing with Interpenetration. 193
4.7.5 Avoiding Local Minima 193
4.7.6 The GJK Algorithm . . . . . . 195
4.7.7 Termination Condition. . . . . 203
4.8 Rigid Body-Rigid Body Collision Response 204
4.8.1 Computing Impulsive Forces for a Single Collision 205
4.8.2 Computing Impulsive Forces for Multiple Collisions 218
4.8.3 Computing Contact Forces for a Single Contact . 225
4.8.4 Computi~g Contact Forces for Multiple Contacts 234
4.9 Particle-Rigid Body Contact Revisited 238
4.10 Notes and Comments. . . . . . . . . . . . . . . . . . . . 242

5 Articulated Rigid-Body Systems 245


5.1 Introduction............ 245
5.2 Articulated Rigid-Body Dynamics 247
5.3 Collision Detection . . . . . . . . . 253
5.4 Collision Response . . . . . . . . . 256
5.4.1 Computing Impulsive Forces for Single or Multiple
External Collisions . . . . . . . . . . . . . . . . . . . 258
5.4.2 Computing Contact Forces for Single or Multiple Ex-
ternal Contacts 260
5.5 Notes and Comments . . . . . . . . . 262

A Useful 3D Geometric Constructions 265


A.l Introduction . . . . . . . . . . . . 265
A.2 Projection of a Point on a Line . . . 266
A.3 Projection of a Point on a Plane . . 266
A.4 Intersection of a Line Segment and a Plane 267
xiv Contents

A.5 Closest Point between a Line and a Line Segment . . . . . . 268


A.6 Computing the Collision- or Contact-Local Frame from the
Collision- or Contact-Normal Vector . . . . . . . . . . . . . 270
A.7 Representing Cross-Products as Matrix-Vector multiplication 271
A.8 Suggested Readings. . . . . . . . . . . . . . . . . . . . . . . 272

B Numerical Solution of Ordinary Differential Equations of


Motion 273
B.1 Introduction. . . . . . 273
B.2 Euler Method. . . . . 276
B.2.1 Explicit Euler. 276
B.2.2 Implicit Euler. 278
B.3 Runge-Kutta Method 280
B.3.1 Second-Order Runge-Kutta Method 280
B.3.2 Forth-Order Runge-Kutta Method . 283
B.4 Using Adaptive Time-Step Sizes to Speed Computations. 285
B.5 Suggested Readings. . . . . . . . . . . . . . . . . . . . .. 287

C Quaternions 289
C.1 Introduction. . . . . . . . . . 289
C.2 Basic Quaternion Operations 290
C.2.1 Addition.... 290
C.2.2 Dot product. . 290
C.2.3 Multiplication. 290
C.2.4 Conjugate. 291
C.2.5 Module . 292
C.2.6 Inverse.. . 292
C.3 Unit Quaternions . 292
C.4 Rotation-Matrix Representation Using Unit Quaternions . 293
C.5 Advantages of Using Unit Quaternions 295
C.6 Suggested Readings. . . . . . . . . . . . . . . . . . . . .. 297

D Rigid-Body Mass Properties 299


D.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . 299
D.2 Mirtich's Algorithm . . . . . . . . . . . . . . . . . . . 300
D.2.1 Volume-Integral to Surface-Integral Reduction 303
D.2.2 Surface-Integral to Projected-Surface-Integral Reduc-
tion . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
D.2.3 Projected-Surface-Integral to Line-Integral Reduction 308
D.2.4 Computing the Line Integrals from the Vertex Coor-
dinates . . . 309
D.3 Suggested Readings. . . . . . . . . . . . . . . . . . . . . . . 310

E Useful Time Derivatives 313


E.1 Introduction. . . . . . 313
Contents xv

E.2 Computing the Time Derivative of a Vector Attached to a


Rigid Body . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
E.3 Computing the Time Derivative of a Contact-Normal Vector 314
E.3.1 Particle-Particle Contact . . . . . . . . . . . . 314
E.3.2 Rigid Body-Rigid Body Contact . . . . . . . . 315
E.4 Computing the Time Derivative of the Tangent Plane 317
E.5 Computing the Time Derivative of a Rotation Matrix 318
E.6 Computing the Time Derivative of a Unit Quaternion 320
E.7 Suggested Readings. . . . . . . . . . . . . . . . . . . . 323

F Convex Decomposition of 3D Polyhedra 325


F.l Introduction. . . . . . . . . . . . . . . . . 325
F.2 Joe's Algorithm. . . . . . . . . . . . . . . 327
F.2.1 Determining Candidate Cut Planes. 329
F.2.2 Computing the Cut Face Associated with a Cut Plane331
F.2.3 Termination Conditions 334
F.3 Suggested Readings. . . . . . . . . . . . . . . . . . . . . . . 334

G The Linear-Complementarity Problem 337


G.l Introduction . . . . . . . . . . . . . . . . 337
G.2 Dantzig's Algorithm: The Frictionless Case 339
G.2.1 Termination Conditions ...... 347
G.3 Baraf!'s Algorithm: Coping with Friction 348
G.3.1 Static-Friction Conditions 351
G.3.2 Dynamic Friction . . . . 361
G.3.3 Termination Conditions 362
G.4 Suggested Readings . . . 363

H Software Implementation 365

References 367

Index 375
1
Computational Dynamics

1.1 Introduction
The quest for realism and precision in computer-graphics simulations of
complex systems started decades ago, when engineers realized the impor-
tance and cost effectiveness of having reliable computer models for their
products. The ability to study the inner workings of a system according
to several different scenarios long before the beginning of the manufacture
cycle was compelling enough to lead to an impressive amount of work on
physically-based simulation and modeling.
The physically based modeling of the interactions between parts in such
systems is particularly attractive because they are not limited to a single-
domain analysis. On the contrary, the simulations are extremely useful
because they can be extended to multiple-domain analysis of the system,
such as the combination of thermal and stress-test analysis of the materials
used to manufacture the parts, with the forces exerted on them obtained
from the mechanical-contact analysis. In this case, the combination can
be used to predict the maximum force that can be exerted on each part
before it cracks. The set of applications with the potential of benefiting
from such work is diverse, ranging from aircraft and automobile design, to
structural analysis of buildings, to weather simulations and toxic-plume-
spread analyzers, and even to video games.
The challenge in combining multi-domain simulations is that usually each
domain of interest being simulated requires the development of specialized
mathematical models capable of expressing subtle interactions that match

M. G. Coutinho, Dynamic Simulations of Multibody Systems


© Springer Science+Business Media New York 2001
2 1. Computational Dynamics

the correct theoretical physical behavior of the system. In many cases, such
specialized mathematical models are implemented using different numerical
methods that mayor may not be compatible with one another. When the
numerical methods are compatible, the models can be easily merged and
the coupling effects between the different domains can be quickly evaluated.
However, there are cases when the numerical methods are incompatible and
a direct merge is infeasible. In these cases, the models are usually combined
in an interleaved fashion. The interleaved approach consists of solving one
method at a time, with their coupling being represented by a set of external
forces and constraints that are applied from the system that was just solved
to the system that will be solved next. By so doing, each system interacts
with the others using its own· specialized techniques.
The generation of reliable models for each domain also turns out to be
of great interest, since the results that can be drawn from the simulation
experiments directly depend on the models used. The models can range
from simple first-order approximations for a quick evaluation of the system,
to highly complex and accurate models of the theoretical physical behavior,
capable of capturing several aspects of the system more realistically. The
choice of the model to be used depends on the simulation goals that need
to be met, as well as on the computational efficiency required. For example,
the dynamic simulation of a wall being blown out by an explosive in a video
game does not need to use a highly accurate model of the internal structure
of the wall. It suffices to use a simple model that gives a sufficiently accurate
feeling of authenticity to the scene. Nevertheless, the same simulation in
the context of a miliary operation may need a more accurate model of the
wall so that the appropriate weapon can be chosen for the task.
Even though the number of models and specialized mathematical meth-
ods that can be used in a physically based simulation is significant, there are
two types of multi-domain simulations that represent the most commonly
used simulation engines. These simulation engines restrict the general case
of physically based modeling to the particular case wherein things inter-
acting are either particles or rigid bodies.

1.2 Particle and Rigid-Body Systems


Arguably, particle and rigid-body systems are the most important and com-
monly used models in physically based dynamic simulations. They repre-
sent a very good trade-off between mathematical complexity and accuracy
of the models used to capture the observed real-world behavior of the sys-
tem.
1.3 Dynamic Simulation Engines 3

Particle systems can range from basic implementations of point-mass


systems that use discrete particles to represent gaseous or fluid motion 1 ,
to specialized systems that use computational fluid mechanics to simu-
late turbulent gases and liquids such as swirling steam, gusts of wind, and
flooding, to name a few. The former applies standard Newtonian physics to
each particle in the system to determine the dynamics of motion, whereas
the latter uses sophisticated numerical methods to solve the Navier-Stokes
volumetric differential equations of motion.
Rigid-body systems, on the other hand, take into account the shape and
mass distribution of the objects being simulated. They are especially suit-
able to simulate systems where the internal bending, extension or compres-
sion of the object can be neglected, meaning, the object does not change its
shape during the entire simulation. The rigidity assumption also simplifies
the computations, since it makes forces being applied at any point on the
object equivalent to a force-torque pair being applied at its center of mass,
which can be easily computed.
Rigid bodies can also be combined into systems of articulated rigid bod-
ies, where bodies are attached to each other using joints. There are several
types of joints that can be used to connect bodies, and they differ from
each other by the degree of freedom of relative motion allowed. An uncon-
strained rigid body has six degrees of freedom, three degrees to translate
and another three degrees to rotate along and about the coordinate axis,
respectively.

1.3 Dynamic Simulation Engines


In this section, we shall discuss the general structure of a dynamic-simula-
tion engine for non-penetrating particle and rigid-body systems. Figure 1.1
shows a block diagram representation of the main loop of a dynamic-
simulation engine. The engine starts at some time to, and advances by
some time-step values, executing four high-level steps.
The first step moves all objects from the beginning to the end of the
current time step, ignoring any possible collisions that might happen during
the movement. This consists of determining the dynamic state of the system
at the beginning of the current time step, and using this information to solve
the ordinary differential equations (ODEs) of motion for each object. The
dynamic state of the system is given by all linear and angular positions,
velocities and accelerations, as well as by the net external force-torque pair
acting on each object2 in the system. Since the positions, velocities and

1 In this book, we shall focus the study of particle systems to the case in which
particles are approximated by point-mass objects.
2In this book, we shall sometimes refer to object as a synonym to particle or rigid
body.
4 1. Computational Dynamics

r----.<. Yes

Update Rendering
I + - - - -.......- - - - - - i Respond to Collisions
Engine

FIGURE 1.1. Block diagram illustrating the general structure of a dy-


namic-simulation engine.

accelerations at the beginning of the current time step are already known
from the previous time step (they are the same as the ones computed at
the end of the previous time step, with the exception of the very first time
step), the only variables that need to be computed in this task are the
net external force-torque pairs. Examples of external forces possibly acting
on an object are gravity, contact forces, constraint forces owing to joint
attachments if the object is part of an articulated system, and any other
external force the environment exerts on the object. The net external force
is computed as the combination of each external force acting on the object.
If object is a rigid body, each external force is transformed to an external
force-torque pair acting on its center of mass, before the combination takes
place. Having determined the dynamic state of the system at the beginning
of the current time step, we use this information to numerically integrate
the differential equations of motion and compute the dynamic state of each
object in the system at the end of the current time step.
The second step checks for collisions that may occur between one or more
objects during their motion. Collisions are usually detected by checking for
geometric intersections between the objects' boundary representations. The
collision check can be a very time-consuming task, especially if every object
is checked against all others for collisions. In practice, the simulation engine
uses auxiliary structures to speed the collision checking.
The first auxiliary structure considered in this book is used to speed the
determination of which pairs of objects should be checked for collisions.
It consists of some sort of cell decomposition of the simulated world that
is guaranteed to contain all objects for the entire simulation. As objects
move around the world, the simulation engine keeps track of which of the
cells intersect their boundary representations, and checks for collision only
between objects that share a common cell.
1.3 Dynamic Simulation Engines 5

The second auxiliary structure also covered in this book is used to speed
the collision detection between pairs of objects. It consists of decomposing
each object in a hierarchical tree of simple structures that can be quickly
checked for intersections, such as boxes, spheres or convex polygons. The
tree is constructed in a pre-processing step before the simulation engine
starts, in such a way that the structure associated with each parent node
in the tree contains the structures of all its children. For example, a hi-
erarchical bounding-box representation of an object would consist of one
top-level bounding box that contains the entire object, several intermedi-
ate levels of possibly overlapping bounding boxes that contain sub-parts
of the object, down to leaf bounding boxes that contain one or more faces
of the object. The goal is to postpone the more expensive check for colli-
sions between the object's faces as long as possible, substituting them for
inexpensive collision checks between their hierarchical representations.
Whenever a pair of objects shares a common cell of the world-cell decom-
position, their hierarchical structures are checked for intersections, start-
ing with their top-level structures, and moving down to their intermediate
structures until reaching a leaf. Objects that are farther apart, yet in the
same cell of the world decomposition, are quickly discarded after checking
for intersections between their top-most level representation. Objects that
are closer together may require checking for intersections between several
intermediate levels of their hierarchical tree representation. Objects that
are really close will probably require the more expensive check for collisions
between the faces associated with the intersecting leaf nodes. As Figure 1.1
illustrates, if no collisions are detected, then the movement of the objects
for the current time step is valid and their new positions and orientations
are sent to the rendering engine, which is in charge of updating the display
showing the simulation. However, if a collision is detected, the simulation
engine moves on to the third step.
The third and most difficult step is to establish the non-penetrating con-
straints for all collisions and contacts detected in the second step. This
consists of responding to collisions that may occur between two or more
objects during their motion. Because collisions introduce discontinuities
into the accelerations and velocities of the colliding objects, it is necessary
to stop the numerical integration of the ODEs of motion just before the
collision, resolve the collision to determine the new velocities of the ob-
jects just after the collision, and re-start the numerical integration for the
remaining time using the updated position and velocity values.
In practice, whenever an intersection is detected, the collision-detection
algorithm moves backwards in time to determine an adequate approxima-
tion of the exact time just before the collision occurs, that is, just before
the colliding objects intersect. Collisions can involve more than two ob-
jects, can be coincident in time (Le., multiple simultaneous collisions), and
can be at multiple locations (Le., several collision points.) The simulation
6 1. Computational Dynamics

engine keeps track of the most recent simultaneous collisions detected and
responds to them as follows.
The collision point, collision normal and relative velocities associated
with the most recent collisions detected are computed from the relative
geometric displacement of the colliding objects, as well as from their dy-
namic state just before the collision. This information is passed along to
the collision-response algorithm to compute the collision impulses and con-
tact forces, as appropriate. The distinction between contact and collision
is usually made by measuring the relative velocity of the colliding objects
along the collision normal, just before the collision. If the relative velocity
is less than a threshold value, the collision is assumed to be a contact.
Having distinguished between all simultaneous contacts and collisions
associated with the most recent collisions detected, the collision-response
module computes the collision impulses first, and uses this information
to update the relative accelerations and relative velocities of the colliding
objects just after the collision. This update may cause some of the contact
points to break apart. This happens whenever the relative velocities at
contact points after the update become greater than the threshold value.
In this case, after the collision impulses are resolved, the relative velocities
of the objects at the contact point demonstrate that the objects are now
moving away from each other, meaning the contact will break apart and
there is no need to take into account the contact force associated with this
contact. For the remaining contacts, a contact force is computed to prevent
the contacting objects from interpenetrating.
Because resolving collisions requires moving the colliding objects back-
ward in time to place them just before the collision was detected, the simu-
lation engine needs to recompute the dynamic state of the colliding objects
for the remaining time until the end of the current time step. This is done
by restarting the numerical integration using the new dynamic state of the
colliding objects just after the collision. The final position and orientation
of the colliding objects is then updated to reflect the changes introduced
by the collision. Because these changes affect the path of the objects during
time remaining, the simulation engine needs to check again for new colli-
sions. This loop continues until there are no collisions within the current
time step.
The forth and final step consists of communicating the final position and
orientation of each object in the system to the rendering engine being used.
Here, we assume the actual display of the simulation is carried out by the
rendering engine, which communicates with the simulation engine through
a well defined interface.
1.4 A Computationally Efficient Implementation 7

1.4 A Computationally Efficient Implementation


Even though the general structure of a dynamic simulation engine is rela-
tively easy to understand, its implementation is usually an involved task.
Despite the fact that a naive implementation works, its operation can be
frustrating and disappointing, even for a small number of simple rigid bod-
ies and particles being simulated. Naive implementations carry out unnec-
essary time-consuming computations, since they tend to ignore coherence
between time steps, as well as the spatial distribution of the rigid bod-
ies and particles in the scene when computing their interactions. This can
easily distort the consumption of important computer resources such as
memory and CPU run-time. As it happens, the use of computationally ef-
ficient algorithms in dynamic-simulation engines is a necessity than rather
a luxury.
In this section, we discuss in detail a possible architectural design of a
computationally efficient implementation of a dynamic-simulation engine
for non-penetrating particle and rigid-body systems. In doing so, we are
mostly interested in studying algorithms that can produce real-time or
near real-time performance. The actual description of the algorithms used
in each step of the simulation engine proposed in this book, as well as
reference software implementations of several modules that make up the
entire simulation, are provided in the remaining chapters and appendices.
In the particular case of software implementations, we are supporting a
Web site with links to the author's own software, as well as other software
packages developed by the computer graphics and mechanical engineering
industries. The main goal of this section is to justify the book's organiza-
tion, and describe the high-level steps necessary to implement an efficient
dynamic-simulation engine.

1.4.1 Interface with the Rendering Engine


The portability of the simulation engine across a multitude of computer
platforms is the first important issue that needs to be addressed. Usually,
the results of a dynamic simulation are rendered in a computer display
using one of the several sophisticated rendering engines available in the
market. Such rendering engines have an internal representation of the scene
being rendered, which contains lots of information that is also necessary
for the dynamic-simulation engine. At first, the temptation to use the same
internal representation of the rendering engine is almost irresistible, since a
considerable amount of source-code development can be forgone. However,
the fact that there exists a diverse set of internal representations, each
tailored to capitalize upon the underlying hardware capabilities, makes it
critical to have our own internal representation of objects in the scene that
is independent of the specifics of the rendering engine being used. The
way this can be done in a dynamic-simulation engine, without sacrificing
8 1. Computational Dynamics

portability, is to create an interface between the rendering engine and the


simulation engine. The number of methods implemented by the interface
should be kept small, to avoid unnecessary interactions.
In an efficient implementation, the interface between the rendering and
simulation engines should contain at least three basic features. The first
feature lets the rendering engine register objects with the simulation en-
gine, and update their status as appropriate. The registration process may
consist of passing to the simulation engine some basic information about
the object being registered, and receiving back a handle to the internal rep-
resentation of the object in the simulation engine. This handle (a unique
identification number) is used to map the internal representation of objects
in the simulation engine to their counterparts in the rendering engine.
The basic information the rendering engine passes to the simulation en-
gine when registering an object should include a list of vertices and faces
defining its boundary representation3 . Upon registering an object, the simu-
lation engine computes its extended representation, which includes the fol-
lowing information in addition to the information already obtained from
the rendering engine:

1. Edge list.
2. Face neighbor list.
3. Face normal list.
4. Convex decomposition of the object.
5. Hierarchical representation of the object.
All this information is computed only once, when an object is registered,
with respect to the object's local-coordinate system. This information is
then used in several modules throughout the simulation engine to speed
computations and optimize the overall efficacy, as the object moves within
the global-coordinate system.
At the end of each simulation time step, the simulation engine returns
to the rendering engine a list of object handles and their updated positions
and orientations. The object handles can be used by the rendering engine
to quickly get a pointer to the internal representations of the objects, and
apply the necessary transformations to position and orient them in the
scene. Not all objects registered with the simulation engine are on this list,
just those that changed position or orientation since the last time step.
As far as efficacy is concerned, it is very important to implement a fast
mechanism to retrieve the object structure from its handle (such as a hash
table) in both rendering and simulation engines.

3In this book, we assume the object's geometry is defined by its boundary represen-
tation, that is, by its vertices, edges and faces.
1.4 A Computationally Efficient Implementation 9

The rendering engine should also be capable of updating the status of


objects registered with the simulation engine. This consists of carrying out
operations ranging from removing the object from the simulation engine,
to changing its current position, orientation and velocities, to adjusting its
simulation status. Possible values for the simulation status are inactive,
static and dynamic. By default, all registered objects can be initially set
to the inactive state. In this state, even though the objects exist in the
simulation engine, they are ignored during the run-time execution. Static
objects, on the other hand, are taken into account during the simulation
execution, but are considered fixed objects in the scene. Only dynamic ob-
jects have their positions and orientations determined using the physically
based computations of the dynamic-simulation engine.
The distinction between static and dynamic objects makes it possible to
interface script-based motion with the simulation engine. This can be done
by setting the dynamic state of all objects that have a predefined script-
based motion to static, and updating their positions between each simula-
tion frame following the script. We just need to be careful when updating
the position of each object following the script so as not to overlap any
other object. The dynamic-simulation engine enforces the non-penetration
constraints on all registered objects for every time step, and if the script-
based object is forced to move on top of another object, then the simulation
engine will not work properly and will yield an abnormal result for the sub-
sequent simulation time steps. We can overcome this problem by using a
kinematically constrained motion based on the scripted position and ori-
entation of the object. By kinematically constrained, we mean that the
linear and angular positions, velocities and accelerations of the bodies are
obtained from an animation system, possibly by interpolating their values
between two consecutive animation frames
The second feature to be implemented in the interface between the ren-
dering and simulation engines lets the rendering engine specify the dimen-
sions of the scene to which the dynamic-simulation engine is constrained.
The goal is to impose bounds on the distance an object can move inside the
simulation engine. Objects that fall outside these bounds have their status
automatically set to inactive, and are left out of the simulation execution
for the rest of the simulation.
In order to simplify things, the dimensions of the scene can be given by
the coordinates of a bounding box containing the entire simulated world.
Once the bounding box is defined, the simulation engine decomposes it into
subregions (or cells) that are used to speed the collision-detection phase.
The decomposition can be single- or multi-level. In the single-level case,
a coarse uniform grid is constructed from the bounding box that contains
the entire simulated world. The size of each cell in the grid is determined
as a combination of the size of the objects being simulated. In the multi-
level case, several uniform grids with cells of different sizes are constructed,
forming a coarse-to-fine decomposition of the simulated world. Objects are
10 1. Computational Dynamics

then assigned to the grids with cells that can completely contain them.
The techniques to decompose the simulated world will be explained in
more detail in Section 2.3.1.
Last, but not least, the third desired feature of the interface between the
rendering and simulation engines should let the rendering engine specify
the sampling time to be used, that is, the amount of time the dynamic-
simulation engine needs to be executed between two consecutive frames.
Usually, the sampling time is set to be the inverse of the desired frame
rate, so that the dynamic simulation returns the state of the system after
each frame, and the rendering engine can update the computer display ac-
cordingly. The state of the system can be returned as a list of objects that
moved since the last sampling time, with their new positions and orienta-
tions given by a translation vector and a rotation matrix, respectively.
It is important to notice that the actual time step used in the simulation
engine to numerically integrate the differential equations of motion of each
dynamic object may be different from the sampling time. This is most
often the case when the numerical method uses adaptive time steps to
automatically adjust the current time step used, depending on the value of
the estimated integration error.

1.4.2 Moving the Objects


As soon as the simulation engine starts, the first step to be executed con-
sists of moving all dynamic objects from the beginning to the end of the
current sampling time, ignoring any collisions that may happen during the
movement (see Figure 1.1). For each dynamic object in the system, the
simulation engine undertakes the following actions to complete this step.
1. Computes the net force acting on the object. The net force is obtained
from the addition of all external forces the environment exerts on the
object, such as gravity, contact forces and joint forces, if applicable.
If the object is a rigid body or an articulated rigid body, then each
external force is transformed to an external force-torque pair acting
on its center of mass before they are added to form one net force-
torque pair.
2. Numerically integrates the ODEs of motion associated with the ob-
ject, assuming no collisions occur during the entire movement.
3. Adjusts the cell decomposition of the simulated world to account for
the object's movement. This step consists of removing the object from
cells it no longer intersects and adding it to the new intersecting cells.
When executing this loop, the simulation engine uses the world-cell de-
composition to construct a list of potential collisions. This list contains pairs
of objects that are within the same cell or group of cells, and therefore may
be colliding with each other during their movements.
1.4 A Computationally Efficient Implementation 11

1.4.3 Checking for Collisions


The collision check is undertaken only for the pairs of objects that are
in the list of potential collisions. Here, the simulation engine builds one
global-collision list for the entire world, and one local-collision list for each
object involved in a collision. The global-collision list contains information
about all collisions, sorted by increasing order of collision time. The local-
collision list contains information about the most recent collision associated
with its corresponding object. Notice that we should keep a list, as opposed
to a single reference to the most recent collision, in order to account for
any multiple simultaneous collisions the object might undergo. As new
collisions are detected, both the global list and the local references of the
objects involved in the collisions are dynamically updated to reflect the
changes in the collision times.
For each pair of objects in the list of potential collisions, the simulation
engine goes through the following steps before removing the pair from the
list.

4. Checks whether the objects' hierarchical representations intersect.


The pair of objects is discarded if no intersections are found.
5. If an intersection is detected, the approximate collision time is de-
termined by regressing in time the colliding objects' motion to just
before the collision. If either of the colliding objects is already in-
volved in another collision, then the simulation engine needs to check
whether the new collision time is smaller than the one just detected,
and if so needs to update both global and local lists of collisions to
reflect the changes. For example, assume the current pair of objects
obtained from the list of potential collisions is (BI' B 2 ), and that a
new collision C i was detected between them at time ti. The simula-
tion engine will then update the local lists of collisions for each object,
as follows .

• Checks whether BI is already involved in another collision Gj


that occurs before Gi . In this case, collision Gi should be dis-
carded, since it may no longer exist after collision Gj is pro-
cessed. Otherwise, proceed to the next step .
• Updates BI's local list of collisions to account for the new col-
lision Gi . There are three possible situations to be considered.
If this is the first time object BI is involved in a collision, then
the simulation engine just adds G i to BI's local list of collisions.
However, if BI was already involved in a collision that happens
to have occured simultaneously with collision Gi , then BI has
multiple simultaneous collisions at time t i , and collision Gi is
also added to BI's local list of collisions. Finally, if BI was al-
ready involved in a collision occurring after collision Gi , then the
12 1. Computational Dynamics

simulation engine deletes B1's local list of collisions, and resets


it to include Ci only (Le., resets it to the most recent collision
involving Bd

The steps above are repeated to B 2 • At the end, the list of potential
collisions is empty, and the global list of collisions mayor may not have
entries. If no collisions were detected, then the dynamic state of the system
computed in Section 1.4.2 is correct, and the simulation engine returns to
the rendering engine the new positions and orientations of the objects that
were moved during the current sampling time. Otherwise, the simulation
engine has a global list of all collisions detected, ordered by their increasing
collision times. Each entry in this list is a list itself reflecting the cases when
we have simultaneous collisions between two or more objects. Each individ-
ual collision has references to both colliding objects. Also, each object has
a reference back to the entry in the global list of collisions that contains the
most recent collision it underwent. This flexibility is necessary to properly
respond to collisions, since the simulation engine needs to quickly move
back and forth between collision structures and the objects involved with
them.

1.4.4 Responding to Collisions


The collision response processes only the single or multiple collisions associ-
ated with the most recent collision time in the global list of collisions. Here,
the simulation engine creates yet another auxiliary list that contains the
collisions that are in fact contacts. This distinction is necessary because col-
lisions should be resolved before contacts are resolved. In other words, only
after the dynamic state of the system is updated with the collision impulses
can we compute the contact forces that will enforce the non-penetration
constraints between objects.
The simulation engine executes the following steps for all collisions asso-
ciated with the most recent collision time in the global list of collisions.

6. Moves all colliding objects backward in time to the moment just


before their collisions.
7. Checks whether the collisions are in fact contacts. This check is car-
ried out for each collision and consists of testing whether the module
of the relative velocity of the colliding objects at the collision point,
along the collision normal, is less than a threshold value. If this is the
case, then the collision is said to be a contact and is moved from the
global list of collisions to the global list of contacts.
8. Computes the collision impulses associated with each collision. As we
shall see later in the chapters to come, this step consists of solving a
sparse linear system.
1.4 A Computationally Efficient Implementation 13

9. Updates the dynamic state of the system with the collision impulses
computed in the previous step. This will update the linear and angu-
lar velocities of all colliding objects.

10. Checks whether the contacts, if any, are still valid. This check is
carried out for each contact associated with an object that was also
involved in a collision. This consists of testing one more time whether
the module of the relative velocity along the contact normal at the
contact point is less than the threshold value. Since the dynamic state
of the colliding objects has changed, the contacts that involve any of
them will have their relative velocity at the contact point changed as
well. In some cases, the contact may beak apart just after the collision
impulses are applied, making it necessary to remove them from the
global list of contacts.

11. Computes the contact forces at each contact point that prevent the
objects from interpenetrating. The contact-force computation involves
solving a Linear Complementarity Problem (LCP) that is obtained
from the current contact configuration of the system. The general
LCP problem formulation, as well as efficient techniques to solve such
systems, are addressed in details in Appendix G.

12. Adds the contact forces (and associated torques) to the net external
force-torque pair acting on the object. This will enforce the non pene-
tration constraints for the remaining time necessary to reach the end
of this sampling time.

After resolving all collisions and contacts, the simulation engine com-
putes the remaining time to reach the end of the current sampling time,
and numerically integrates the ODEs of motion only for the objects in-
volved in a collision or contact. Again, the simulation engine will move
these objects ignoring any collisions that may occur during the movement.
Objects that remain in contact for the rest of the current sampling time will
not interpenetrate owing to the updated net force and torque computed in
step 12.
The final position and orientation associated with each colliding object
is updated to reflect the effects of the collision or contact, and a new list
of potential collisions is created after the cell subdivision is updated. The
simulation engine then loops back to step 4 and continues checking and
responding for collisions until it reaches the end of the current sampling
time.
At the end of the current sampling time, the simulation engine sends to
the rendering engine the list of objects that had their positions or orienta-
tions changed since the last update. It t.hen continues moving the objects,
checking and responding to collisions, and updating the display until it
receives a stop command from the rendering engine.
14 1. Computational Dynamics

1. 5 Guide to Readers
The book's organization is justified according to the structure of the ef-
ficient dynamic-simulation engine presented in Section 1.4, and the tech-
niques needed to implement it. The book contains five chapters and eight
appendices. Each chapter presents many algorithms and covers them in
considerable depth, yet makes their design and analysis accessible to all
levels of readers, keeping the explanations as elementary as possible with-
out sacrificing depth of coverage or mathematical rigor. The more complex
mathematical algorithms and associated implementations are described in
details in the appendices. The goal of doing so is to focus the reader's
attention to the details of the topic being covered, and not distract him
with mathematical issues that can be viewed as"black box" modules that
have specific functionality, such as a numerical integrator or a rigid-body
mass-properties-computation module.
Chapter 1 introduces the computational-dynamics topic to readers, de-
scribing the general structure of a dynamic-simulation engine for non pene-
trating particle and rigid-body systems. It sets the stage for the remaining
chapters of the book by explaining what it takes to design and implement
a computationally efficient simulation engine. The following chapters and
appendices address the specialized tools and techniques mentioned in this
chapter.
Chapter 2 focuses on the problem of computing a hierarchical represen-
tation of the geometric description of each simulated object, as well as the
simulated world. This representation is used to speed collision-detection
checks by taking advantage of the geometric arrangement of the objects in
the simulated world, such that collision tests are only carried out on objects
that are "close enough" to collide. The hierarchical decomposition of the
colliding objects is used to prune unnecessary intersection tests and quickly
specify the collision points, or discard the collision if no intersections are
found.
Chapter 3 covers the design and implementation of particle systems as
a collection of point mass objects that can collide with each other and
other rigid-body objects in the simulation. Even though this is one of the
simplest models of particle systems that can be used, the computational
efficiency and degree of realism that can be attained with these systems is
highly attractive. This chapter also discusses in details the use of spring-
mass systems to model cloth, and how to implement such systems using
point-mass particles connected by a combination of strategically placed
springs.
Chapter 4 presents the theoretical and practical aspects of designing
and implementing dynamic-simulation engines for rigid-body systems. In
this chapter, special attention is given to one of the most difficult and least
understood topics in physically based modeling, namely, the computational
1.5 Guide to Readers 15

techniques needed for determining all impulsive and contact forces between
bodies with multiple simultaneous collisions and contacts.
Chapter 5 extends the techniques for rigid bodies to include articulated
rigid bodies. Here, we shall focus on linking rigid bodies with spherical
joints. The goal is to demonstrate and implement techniques that can be
used to dynamically simulate articulated rigid bodies. These techniques can
be easily applied to include other types of joints suitable to the reader's
interests.
The remaining part of the book is devoted to a set of appendices describ-
ing the mathematical algorithms used throughout the entire book, each of
these standing alone as a broad and complex topic in itself. The appendices
focus on the tools being used in the simulation engine. Nonetheless, they
provide pointers to the literature, wherein interested readers can get more
information about the topic.
Appendix A briefly covers some of the geometric constructions used as
building blocks to implement the several intersection tests that are part of
the particle-particle, particle-rigid body and rigid body-rigid body collision-
detection algorithms. It also discusses how the tangent plane of a collision or
contact can be determined given the collision or contact point and normal
vector.
Appendix B discusses some of the most common methods used to inte-
grate the differential equations of motion in dynamic simulations. These
methods range from simple explicit-Euler, to more sophisticated Runge-
Kutta methods, with adaptive time step sizing.
Appendix C presents an alternate representation of rotation matrices us-
ing quaternions. This representation is extremely useful in reducing round-
ing-error problems found when combining rotation matrices. Also, the inter-
polation between two quaternions representing the orientation of an object
is easier than using rotation matrices. This is especially useful when trac-
ing back in time the object's motion to determine the instant just before a
collision.
Appendix D shows an efficient algorithm to compute the mass proper-
ties of 3D polyhedra. The mass properties include the total volume, total
mass, center of mass, and inertia tensor. These quantities are used in the
physically based modeling of the dynamics and interactions of objects in
the simulated world.
Appendix E presents a detailed description of how the time derivatives of
a normal vector, a rotation matrix and a quaternion are computed. These
time derivatives are extensively used in Chapters 4 and 5 to describe the
dynamics a rigid-body system.
Appendix F addresses the technical barriers to using non-convex polyhe-
dra in a dynamic simulation. Most interesting objects to be simulated are
usually non-convex. However, most of the algorithms presented in this book
are especially tailored for convex objects. Therefore, it is often necessary to
preprocess all objects in the simulation with a convex decomposition mod-
16 1. Computational Dynamics

ule that decomposes the objects into a set of non-overlapping convex parts.
The algorithms can then be applied to the convex parts of each object.
Appendix G presents the Linear Complementarity Problem (LCP) in the
context of impulse and contact-force computation of multiple simultaneous
collisions. This appendix also presents an extension of the original algo-
rithm to cope with static and dynamic friction at the collision or contact
point.
Finally, Appendix H discusses architecture principles and design goals for
developing dynamic-simulation engines. It also includes information about
the Web site supporting this book, which contains pointers to several soft-
ware packages available for commercial and non-commercial use. The Web
site's URL is:

http://hometown.aol.com/ animationengine
Readers should be able to use the code (or parts thereof) available from
the Web site in their own systems, or develop their own software implemen-
tation from scratch using the techniques covered in depth in this book.
2
Hierarchical Representation of 3D
Polyhedra

2.1 Introduction
Collision detection is undoubtly the most time-consuming step in a dynamic-
simulation engine. In theory, as the simulation evolves, every object needs
to be checked for collisions against all other objects in the simulation.
Whenever a collision is detected, the simulation engine needs to trace back
in time to the instant before the collision, and determine the collision point
and collision normal from the relative geometric displacement of the col-
liding objects.
Usually, collisions are checked by looking for geometric intersections be-
tween the objects. When objects are given by their boundary representa-
tions, this check can be done by looking for geometric intersections between
the primitives of each object, that is, between the polygonal faces defining
the boundary of each object. Clearly, checking for collisions between objects
this way is a laborious task, and the use of intermediate representations to
speed collision checking is critical to achieve real-time performance, espe-
cially for simulations involving several hundred objects, each described by
several thousand primitives.
In this chapter, we study the use of hierarchical representations to speed
the collision-detection phase. Our aim is to compute in a preprocessing
stage the hierarchical volumetric decomposition of each object with respect
to its local-coordinate system. This usually consists of a tree hierarchy of
bounding volumes where the top-most bounding volume bounds the entire
object, the intermediate nodes of the tree bound sub-parts of the volume

M. G. Coutinho, Dynamic Simulations of Multibody Systems


© Springer Science+Business Media New York 2001
18 2. Hierarchical Representation of 3D Polyhedra

bounded by their parent, and the leaf nodes of the tree bound one or more
primitives that lie inside the bounding volume of their parent. Collision
checks are then carried out using the objects' hierarchical representations to
quickly determine that the objects do not intersect (i.e., are not colliding),
or to reduce the number of pair-wise primitive intersection tests needed
to check for collision. For example, if the top-most bounding volumes of
each object do not intersect, then we can safely conclude that the objects
are not colliding. However, if the top-most bounding volumes do intersect,
then we have to move down one level in the tree hierarchy to check whether
their children intersect. If not, then the objects are not colliding. Otherwise,
we move down one more level in the tree hierarchy to the children of the
intersecting parents. This process continues until we either reach the leaf
nodes of the trees, or detect that the objects do not intersect. Should we
reach the leaf nodes of the trees, the collision check proceeds by computing
the pair-wise primitive intersections of the primitives bounded by each
intersecting leaf.
In practice, there are two important points to consider when using hier-
archical representations in a simulation engine. The first is that the inter-
section test of the bounding volumes must be considerably faster than the
intersection test of the primitives. Otherwise, the collision check will take
longer using the hierarchical representation than using the original objects'
boundary representations. Therefore, our choice of bounding volumes is re-
stricted to simple geometric shapes such as boxes and spheres, which can
be quickly tested for intersection against each other. The primitives can
also be restricted to convex polygons, or even triangles, to further speed
the primitive-primitive intersection tests.
The second point addresses how the hierarchical representation is up-
dated as the object translates and rotates with respect to the world-co-
ordinate system. As mentioned before, the hierarchical decomposition is
computed with respect to the object's local-coordinate system. However, all
intersection tests should be carried out with respect to the world-coordinate
system, thus requiring a coordinate transformation from the object's local-
coordinate system to its position and orientation in the world-coordinate
system. One solution to this problem would be to transform the entire tree
hierarchy of all objects to the world-coordinate system, just before test-
ing for intersection. The drawback of so doing is the substantial waste of
time transforming entire tree hierarchies that have only their top-most, or
even some of their internal, nodes checked for intersection. All other in-
ternal nodes that were transformed but not used in the intersection tests
were unnecessary transformed to the world-coordinate system, and the time
spent applying the transformation could have been saved. The idea is then
to transform only what is absolutely necessary. We can do this as follows.
The simulation engine represents each object in the world-coordinate
system by its top-most bounding volume only, and keeps the entire tree
hierarchy, as well as the object's boundary representation, in the object's
2.2 Hierarchical Representation of Objects 19

local-coordinate system. At each time step, only the top-most bounding vol-
ume of each object is moved in the world-coordinate system. The movement
consists of updating the position and orientation of the object according to
the numerical method being used!, applying it to the top-most bounding
volume of the object.
The collision-detection phase then checks for geometric intersections be-
tween the top-most bounding volumes that can potentially collide. Poten-
tially colliding objects are determined from the world-cell decomposition
structure, as explained in Section 2.3. Whenever the top-most bounding
volumes intersect, the simulation engine transforms only their next-level
children from their local-coordinate system to the world-coordinate system.
If their next-level children do not intersect, the objects are not colliding and
no further transformations are required. Otherwise, the simulation engine
keeps transforming only the next-level children of the intersecting bound-
ing volumes until it concludes that the objects are not intersecting, or have
intersecting leaf nodes. In that case, each primitive associated with the in-
tersecting leaf node is then transformed from its local-coordinate system to
the world-coordinate system before the more expensive primitive-primitive
test is carried out. Using this scheme, the simulation engine is guaranteed
to transform only the parts of the objects that are absolutely necessary for
the collision check, thereby saving substantially on execution time.
Another interesting observation about this scheme is that, because the
simulation engine presented in this book is decoupled from the rendering
engine, it does not need to position and orient the objects' primitives in
the world-coordinate system throughout the simulation. After each time
step, the simulation engine just needs to position and orient the top-most
bounding volume of each object. Of course, it also needs to advise the
rendering engine of the new positions and orientations of the objects that
moved since the last simulation time step, so that the rendering engine
can itself place and render the objects' primitives at the correct position
and orientation. Therefore, as far as the simulation engine is concerned,
the cost of moving an object containing several thousand faces, and that
does not intersect any other objects in the scene, is the same as moving the
top-most bounding volume associated with the object. This in turn reduces
even more the simulation engine's execution time.

2.2 Hierarchical Representation of Objects


The hierarchical representations considered in this book are limited to the
case when the bounding volumes are either boxes or spheres. Moreover,
the object's primitives are assumed to be triangles. This assumption is

lThis is discussed in detail in Appendix B.


20 2. Hierarchical Representation of 3D Polyhedra

used not only to speed the primitive-primitive intersection tests, as dis-


cussed in Section 2.4, but also to simplify building Oriented Bounding
Boxes (OBB) trees, as explained in Section 2.2.2. The Axis-Aligned Bound-
ing Boxes (AABB) and the Bounding Spheres (BS) representations are not
affected by this assumption. These representations are covered in detail in
Sections 2.2.1 and 2.2.3, respectively.
In general, it is not clear which hierarchical representation is best, since
collision detection is highly dependent on the relative displacement of the
objects being considered. For example, if the objects are close enough to
each other, the OBB representation usually function better than the others,
in the sense that it considerably reduces the number of primitive-primitive
intersection tests owing to its tight fit. On the other hand, if the objects
are farther apart, the less expensive bounding volume intersection tests
of the AABB and BS representations offer a better choice of hierarchical
representation.
Independent of the hierarchical representation used, the tree hierarchy
can be constructed in a top-down or bottom-up fashion. In the top-down
case, the object's primitives are initially assigned to the top-most bounding
volume, which in turn is recursively decomposed into sub-volumes accord-
ing to some partitioning rule until there is only one primitive or group of
primitives assigned to each sub-volume. In the latter case, the sub-division
ends with the group of primitives if and only if they can no longer be
subdivided according to the partitioning rule. Examples of the top-down
approach will be discussed in Sections 2.2.1 and 2.2.2. In the bottom-up
case, the primitives are individually assigned to an initial bounding volume.
These bounding volumes are then merged according to some merging rule,
until there is only one top-most bounding volume in the tree containing all
primitives.
There are several techniques to partition (or merge) bounding volumes
into (or from) two or more sub-volumes to form a tree hierarchy. Examples
of such partitions are the binary tree (parent has two children), the quad-
tree (parent has four children) and the oct-tree (parent has eight children.)
In this book we limit our analysis to the most common case of building
binary tree hierarchies using the top-down approach. Section 2.5 has refer-
ences to the literature wherein the other possible partitions are covered in
detail.

2.2.1 Axis-Aligned Bounding Boxes


In the Axis-Aligned Bounding Box (AABB) representation, the tree hier-
archy is constructed from boxes bounding the primitives associated with
them, such that the boxes' axes are aligned to the axis of the object's
local-coordinate system. Figure 2.1 illustrates the top-down construction
of a binary AABB tree for a simple 2D object.
2.2 Hierarchical Representation of Objects 21

(a) (b) (c)


FIGURE 2.1. A 2D example of a binary AABB tree. The boxes at each interme-
diate level are aligned with the axis of the object's local-coordinate system. The
broken lines show the partition plane used at each level.

Initially, the top-most bounding box is constructed by looping through


the vertices of all primitives, keeping track of the minimum and maximum
values along each axis of the object's local-coordinate system. The mini-
mum and maximum values will define the lower-left and upper-right corners
of the of the top-most bounding box, respectively.
A partition plane is then selected such that it splits the top-most bound-
ing box into two regions along its longest axis. The intersection point be-
tween the partition plane and the longest axis is chosen such that the two
regions will be as balanced as possible, that is, with more or less the same
number of primitives assigned to each region of the subdivision. The subdi-
vision rule used here is to pass the partition plane through the mean point
of all vertices of all primitives associated with the top-most bounding box.
The primitives are then assigned to the region in which their midpoint falls.
At each subsequent level, intermediate bounding boxes are constructed
from the primitives associated with them, and new partition planes are cre-
ated to divide the boxes into two regions. The primitives are then assigned
to each region and the process recursively continues until there is only one
primitive assigned to each region of the subdivision.
In the event all primitives are assigned to just one region (or the subdi-
vision is unbalanced), another partition plane is chosen such that it divides
the second longest axis into two regions, passing through the mean point.
If this new partition plane still assigns all primitives to just one region,
then a last attempt is made with the partition plane dividing the last axis.
In the rare case that the group of primitives is assigned to just one region
for all three choices of partition plane, the group is said to be indivisible
and the current box containing the group becomes a leaf of the tree. How-
ever, in the most common case when the primitives are equally split into
both subdivisions, the leaves of the hierarchical tree end up having just one
primitive.
22 2. Hierarchical Representation of 3D Polyhedra

2.2.2 Oriented Bounding Boxes


In the Oriented Bounding Box (OBB) representation, the tree hierarchy
is constructed from bounding boxes forming a tight fit around the primi-
tives associated with them. In this case, each intermediate bounding box
has a different alignment with respect to the object's local-coordinate sys-
tem, since their orientation depends on the geometric displacement of their
primitives. Figure 2.2 illustrates the top-down construction of a binary
OBB tree for the same 2D object considered in the AABB case.

(a) (b) (c)

FIGURE 2.2. A 2D example of a binary OBB tree. The boxes at each interme-
diate level provide a tight fit around their primitives. The broken lines show the
partition plane used at each level.

The fact that OBB trees provide a tighter hierarchical representation if


compared with AABB trees clearly gives them an advantage over AABB
trees when testing for collisions between objects that are close together,
since this tightness generally reduces the number of primitive tests to be
carried out. However, this comes at the price of having to carry out a more
costly overlap test at each intermediate level of the OBB tree, as explained
in Section 2.4.
The OBB tree construction is much more complex than the simple AABB
tree construction, since the orientation of each intermediate bounding box
needs to be computed from the set of primitives associated with it. The
OBB tree construction algorithm described in this section assumes that
the object's primitives are all triangles, that is, that the object's boundary
representation is given by triangular faces. This assumption is especially
suited to implementing a simulation engine as described in Appendix H,
since by the time an object is registered with the simulation engine its
convex decomposition is computed (see Appendix F) and the faces of each
convex polyhedron that make up the object are triangulated. The final
internal representation of objects in the simulation engine is therefore made
up of triangular faces only.
The main difficulty when computing OBB bounding boxes is the deter-
mination of the direction of their axes such that the box provides a tight
2.2 Hierarchical Representation of Objects 2:3

fit around the vertices of the triangle primitives associated with it. This
can be done by considering the mean vector and the covariance matrix of
the triangle primitives. The mean vector for each triangle primitive n is
given by

where ih, 172 and V3 are the vertices defining the triangle. Each vector vr
is described by its components (vr)x, (vr)y and (vr)z. The mean vector of
the vertex set is then

~ 1 ~~
J-l=-~J-lk'
n
k=l

with n being the total number of triangles being considered when comput-
ing the OBB bounding box.
The elements of the 3 x 3 covariance matrix of each triangle Tk can be
computed as

where i, j E {x, y, z} and Pi = (Pi - f1) for i E 1,2,3. The covariance matrix
of the vertex set is then

with (Ck)ij being the {ij} element of the covariance matrix associated with
the kth triangle.
Since the covariance matrix is a real symmetric matrix, its eigenvectors
are guaranteed to be mutually orthogonal. Moreover, two of its three eigen-
vectors are the axes corresponding to the maximum and minimum variance
of the vertices' coordinates. Therefore, if we use the eigenvectors of the co-
variance matrix as a base, we can determine a tight-fitting bounding box
by transforming all vertices to this base and computing the AABB box of
the transformed vertices. In other words, the OBB bounding box has the
orientation of the eigenvector base and a size that bounds the maximum
and minimum coordinates of the transformed vertices.
It is important to notice that the direction of the eigenvectors of the
covariance matrix is influenced, not only by the vertices that define the
maximum and minimum coordinates, but by all vertices being considered.
This may cause problems because interior vertices, which should not affect
the bounding-box computation, can influence the direction of the eigen-
vectors. For example, a large number of interior vertices concentrated in a
small area can cause the eigenvectors to align with them, instead of aligning
24 2. Hierarchical Representation of 3D Polyhedra


••••••••
••••••••
••
••
• ::......
• •••••••
••
. • •••••••
•• •••••••
•• •••
•• ••
••
•• ••
•• •• ••
• •
'Ly
(a) (b) (c)

FIGURE 2.3. A 2D example of how interior points can degrade the quality of
OBB bounding boxes; (a) The initial set of points; (b) The OBB bounding box
created taking all points into account; (c) The OBB bounding box created taking
into account only the convex hull points.

with the boundary vertices, thereby creating a low-quality OBB bounding


box. This is illustrated in Figure 2.3.
The computation of the covariance matrix should therefore take into
account only the boundary vertices of the vertex set. It should also be
immune to clusters of boundary vertices, since they will tend to influence
the direction of the eigenvectors in the same manner clusters of interior
vertices do.
Interior vertices can be avoided if we consider only the vertices that are
in the convex hull of the vertex set 2 . Clusters of boundary vertices can
be ignored if we compute the mean vector and covariance matrix over the
surface of the convex hull, as opposed to its vertices. This can be done as
follows. The area Ak of each triangular face Tk of the convex hull can be
computed directly from its vertices, given by

Ak = ~I (V3 - VI) X (V3 - V2) I·


The total convex hull area At is then

where nk is the total number of triangular faces in the convex hull.


The mean vector i1t associated with the convex hull, weighted by the
total convex hull area, is obtained from

2The computation of the convex hull of a vertex set is described in Section 2.2.4.
2.2 Hierarchical Representation of Objects 25

The elements (Ck)ij of the 3 x 3 covariance matrix of each triangular


face Tk, also weighted by the total convex hull area, are given by

Finally, the elements (Ct )ij of the 3 x 3 covariance matrix associated with
the convex hull are computed from the elements (Ck)ij of the covariance
matrix of each of its triangular faces as

Having determined the covariance matrix, we proceed by computing its


associated eigenvectors using one of several methods available for comput-
ing eigenvalues and eigenvectors of real symmetric matrices. Section 2.5
has pointers to the literature describing such methods. The OBB axis will
be aligned with the direction of the eigenvectors and its dimensions will be
given by the extremal vertices along each axis.

2.2.3 Bounding Spheres


In the Bounding Sphere (BS) representation, the tree hierarchy is con-
structed from minimum-radius bounding spheres encapsulating the primi-
tives associated with them. Figure 2.4 illustrates the top-down construction
of a binary BS tree for the same 2D object considered in the AABB and
OBB cases.

(a) (b) (c)

FIGURE 2.4. A 2D example of a binary BS tree. The broken lines represent the
partition plane used at each level.

The BS hierarchical tree is usually of poorer quality than its OBB and
AABB counterparts, with respect to the tightness of the decomposition.
However, its overlap test is undoubtly the easiest and fastest to carry out
26 2. Hierarchical Representation of 3D Polyhedra

(see Section 2.4), thus giving this representation an advantage over the
others for quick rejection tests.
In this section we present a method for finding a near-optimal bounding
sphere from the set of primitives associated with it. The sphere calcu-
lated using this method is usually slightly larger than the minimum-radius
sphere, but this inacuracy is offset by the efficiency of the method.
The bounding sphere computation is carried out in two passes through
the list of vertices of all primitives associated with it. The first pass is used
to estimate the initial center and radius of the sphere. The second pass
goes through each vertex in the list and checks whether it is included in
the sphere. If it is not included, then the sphere is enlarged to include it.
At the end, the center and radius of the near-optimal bounding sphere are
determined.
In the first pass, we loop through the list of all vertices to obtain the
following six points.
1. The point with maximum x.
2. The point with minimum x.
3. The point with maximum y.
4. The point with minimum y.
5. The point with maximum z.
6. The point with minimum z.
From these six points, we select the two that are farthest apart. These two
points will define the first approximation of the diameter of the bounding
sphere. The center of the sphere is assumed to be at their midpoint.
In the second pass, we loop again through the list of all vertices, and
for each vertex, we compare the square of its distance to the center with
the square of the current radius of the bounding sphere. If the distance is
smaller than the radius, then the vertex is inside the sphere and we proceed
to the next vertex in the list. Otherwise, we adjust the sphere's radius and
center as follows.
Let Vi be the current vertex being tested against the bounding sphere,
and falling outside it. Let c be the center of the bounding sphere, r be its
radius and p be the point in the sphere diametrically opposed to Vi (see
Figure 2.5(a)).
Let d be the distance between Vi and C, that is

The enlarged sphere is then computed from the current sphere such that
Vi and p become the new diameter, as shown in Figure 2.5(b). The new
center cn and radius rn of the enlarged sphere are given by
2.2 Hierarchical Representation of Objects 27

(a) (b)

FIGURE 2.5. Efficient, incremental computation of a bounding sphere for a given


vertex set; (a) vertex Vi falls outside the sphere, and therefore the sphere needs
to be enlarged to bound it as well; (b) the sphere is augmented such that Vi and
p define its new diameter.

r+d
2
rc+(d-r)vi
~ = d
This process continues until all vertices are checked for inclusion against
the bounding sphere.
Having determined the top-most bounding sphere, a partition plane is
chosen such that it passes through the median point of all vertices of all
primitives associated with the bounding sphere. The partition plane subdi-
vides the bounding sphere into two regions, and the primitives are assigned
to each region following the same rules used on the AABB and OBB cases,
namely, the primitive is associated with the region that contains its mid-
point. The subdivision continues until there is only one primitive assigned
to each bounding sphere, or the primitives cannot be split, in which case
the group of primitives is assigned to the bounding sphere.

2.2.4 Convex Hull


The convex hull can be used not only to provide a hierarchical represen-
tation of the object's primitives as a tree of convex polyhedra, but also as
an intermediate step for computing other types of representations, such as
the OBB trees already covered in Section 2.2.2.
The convex hull of a given vertex set S is defined as being the smallest
convex set containing S. There are several algorithms and methods that can
be used to compute the convex hull in 2D, 3D, or even higher dimensions.
28 2. Hierarchical Representation of 3D Polyhedra

In this section, we focus on the gift wrapping method, which is intuitive,


easy to visualize in 3D, simple to implement, and applicable to higher-
dimensional spaces.
The basic idea of the gift-wrapping method consists of imagining folding
a piece of paper around the primitives being considered. We start with a
face that is guaranteed to be in the convex hull, and loop through its edges
determining its neighbor faces that are also part of the convex hull. The
algorithm then proceeds looping through the edges of the new neighbor
faces until all faces are discovered and the convex hull is completely deter-
mined. All faces will be discovered whenever the list of edges to be checked
is empty.
Given a set of vertices S = {VI, ... ,vn }, let's assume that the triangular
face II defined by vertices (Vb V2, V3) is the starting face guaranteed to be
in the convex hull. According to the high-level description of the algorithm
presented in the previous paragraph, we need to loop through the edges
of face fl and determine its associated neighbor faces that are also in the
convex hull. A face is said to be in the convex hull if all vertices of S that
are not vertices of the face lie on the same side of the plane defined by the
face. Since we are using the right-hand coordinate system in our simulation
engine, we want all vertices of S to lie on the inside region of the plane.
More specifically, we want to construct each face of the convex hull such
that its normal is always pointing outwards, as illustrated in Figure 2.6.

FIGURE 2.6. Determining the neighbor face that shares edge el with it. The
selected vertex ih will define a face h that forms the largest convex dihedral angle
with it. The ordering of the vertices defining the new face should be chosen so
that the normal vector of the new face always points towards the outside of the
object. Because we are using the right-hand coordinate system, the correct order
is (ift, Vi, V2).

Let's consider, for example, the determination of the neighbor face h


that shares edge e 1 = (VI, V2) with II. We want to find the vertex Vi E S,
with i =f. 1,2, such that the triangular face h defined by (ih, Vi, V2) forms
2.2 Hierarchical Representation of Objects 29

the largest convex internal dihedral angle at edge el. Figure 2.7 shows how
the internal dihedral angle can be computed.

FIGURE 2.7. The internal dihedral angle 8i associated with vertex Vi at edge e1
defined by vertices (Vl,V2), shown as the exterior angle at vertex il of triangle
(il, b, Vi). Notice that vertex b is the projection of Vi on the plane of face /1.

1i~
--~----~~~~----------------~b

FIGURE 2.8. The interior angle 01 at vertex il can be obtained from the dot
product of the face normals iiI and ih associated with faces /1 and /2, respec-
tively.

Let (}i be the internal dihedral angle associated with vertex Vi at edge
el. Let fit and ih be the normal vectors offaces It and 12, respectively. By
construction, since the normals at each face are pointing outwards, their
dot product gives the cosine of (7r - (}i) (see Figure 2.8). The dihedral angle
can then be computed directly from
30 2. Hierarchical Representation of 3D Polyhedra

We select the vertex Vi corresponding to the maximum 0i, and add face
h to the list of convex hull faces. The ordering of the vertices defining
the new face should be chosen so that the normal vector of the new face
always points towards the outside of the object. Because we are using the
right-hand coordinate system, the correct order is ('ih, Vi, V2). The edges of
h are then added to the list of edges that need to be checked, so that the
algorithm can compute the convex hull faces that share these edges with
h. It is important to notice that the algorithm assumes each edge is shared
by exactly two faces. Therefore, every time a new edge is added to the list
of edges that need to be checked, we should first check whether the edge is
already in the list. If the edge is already in the list, then one of the faces
that contains this edge was already discovered in some previous step, and
the other face that contains this edge has just being discovered. In this
case, there is no need to check for this edge because both faces that share
the edge are already included in the convex hull. Therefore, the edge can
be removed from the list. Otherwise, the edge should be added to the list.
Up till now we have assumed the existence of a starting face that is
guaranteed to be in the convex hull, and have determined all other faces
from it. The only step we still have to describe is how the first face of the
convex hull is computed. The computation of the vertices of the first face is
incremental, in the sense that we compute one of them at a time. We start
with one vertex that is guaranteed to be in the convex hull, then use it to
determine the second vertex, thus forming an edge of the starting face. We
then use the edge to determine the third vertex that makes up the first
face. Having the first face, we proceed as explained before and determine
all other convex hull faces.
The first face of the convex hull is computed as follows. Consider the
projection of all points on the xy-plane, as shown in Figure 2.9. Let al
be the vertex with the lowest projected y-coordinate value. This vertex is
guaranteed to be in the convex hull, since all other points of the vertex set
will lie on the same half-space defined by a plane orthogonal to the y-axis
(i.e., parallel to the xz-plane), passing through vertex VI. Therefore, vertex
VI is one of the vertices of the starting face.
The second vertex of the starting face can be found by looping through
the projected vertices and selecting a vertex a2 such that all other projected
vertices lie to the left of the edge ep = (al, (2). We can determine whether
the projected vertex ai lies to the left or right of edge e p by considering the
sign of the area of the triangle defined by (al, a2, ai). If the area is positive,
then the vertices are in counterclockwise order and the projected vertex ai
lies to the left of edge el. Otherwise, the projected vertex ai lies to the
right of edge ep •
The area A of the projected triangle (al, a2, ai) can be quickly computed
from the vertices' coordinates
2.2 Hierarchical Representation of Objects 31

FIGURE 2.9. The first edge of the starting face is computed using the projection
of the vertices on the xy-plane. Here the problem is reduced to its 2D counterpart.

Finally, the third vertex of the starting face can be obtained by consid-
ering the triangular faces Ii defined by vertices (VI, Vj, V2) in 3D space.
The order of the vertices defining the triangular face h is such that the
normal points to the outside of the convex hull 3 . Here, the third vertex V3
is selected such that all other vertices lie in the negative half-space defined
by the plane that contains the triangular face (VI, V3, V2) (see Figure 2.10).
Let ii j be the normal of the plane defined by the triangular face (VI, Vj,
V2), and let dj be the plane constant computed as

Vertex vp will lie on the negative half-space of the plane provided

Having the first face, we proceed as explained and compute all other
convex hull faces of the polyhedron.

3Recall that we are using the right-hand coordinate system.


32 2. Hierarchical Representation of 3D Polyhedra

FIGURE 2.10. The starting face is obtained by connecting a third vertex to the
starting edge, so that all other vertices lie on the negative half-space defined by
the plane that contains the face.

2.3 Hierarchical Representation of the Simulated


World
Even though the use of hierarchical representations does speed the collision-
detection phase, they themselves do not provide mechanisms to take ad-
vantage of the time coherence between consecutive frames in a simulation.
For instance, the fact that two or more objects are farther apart, such that
their top-most bounding volumes do not intersect, should be exploited in
the following simulation time steps to avoid unnecessary collision checks
between these objects. The hierarchical representation does minimize the
time spent on such unnecessary collision checks, since they are usually dis-
missed after the top-most bounding volumes are checked against each other.
However, the time expended on these unnecessary checks can be significant,
especially when the simulation contains several hundred objects.
The idea is then to create a partition of the simulated world into cells,
and assign objects to the cells in which their top-most bounding volume
intersects. Objects that are assigned to the same cell can be potentially
colliding and therefore should be checked for geometric intersections be-
tween their hierarchical representations. On the other hand, objects that
have no cells in common are clearly distant from each other and should not
be checked for collisions at all.
The simulated world considered in this book is assumed to be bounded by
a box that defines the maximum and minimum spans along each coordinate
axis. The cell decomposition is then a partition of the box into sub-volumes
that mayor may not contain objects during the simulation.
There are two important issues that should be taken into account when
decomposing the simulated world into cells. First, the cell decomposition
should be simple, that is, should have simple geometry such that the cost
2.3 Hierarchical Representation of the Simulated World 33

of updating the cells that intersect each moved object is negligible com-
pared with the cost of checking for collisions between their hierarchical
representations. This issue is addressed in Section 2.3.1, where the simu-
lated world is subdivided into boxes of uniform size. Second, the size of
each cell directly affects the efficacy of the decomposition. For instance,
a too-small size will assign several cells to each object, making it more
expensive to update the list of occupied cells after each simulation time
step. On the other hand, a too-large size will assign several objects to the
same cell and a large number of unnecessary collision checks between their
hierarchical representations may be carried out. This issue is addressed in
Section 2.3.2, where the uniform-grid approach presented in Section 2.3.1
is extended to a multi-level grid that better fits the different sizes of objects
being simulated.

2.3.1 [Tnifo~ (irid


Uniform-grid decomposition, as its name implies, subdivides the bounding
box of the simulated world into cubic cells of same size along each axis of
the world-coordinate system. A simple uniform-grid decomposition of an
hypothetical world is shown in Figure 2.11.

....
"
.... ....
.... ,,!oo. .... r-.I--
........ I-- ........ r-.I-- .... ::1-' ..-
" -
1-'-1-'
. . . . ~t . . ~~~ I-'

"
I-' -I-'
I-' ... _ -I-'
........ ........ ~"

l::'
. . ,,1-- ........ ~I-- .... I-'

........ ,,"
,,!oo. ............ ,,"
,,!oo. ....~ .... " -
-1-'1-'_ -I-'

....................... "........
--.. --I-'
-- 1-'-
1-"1-' I-' I-'
........... "I-- .... ~"I-'- -I-" __ ...I-' ...
.......... .... r-. ~

z ;9 .... ..-~

FIGURE 2.11. A simple uniform-grid decomposition of an hypothetical simulated


world with a resolution of fourteen boxes along each dimension. Each cell is
identified by the index ot its lower-left corner vertex. For example, the first cell
is indexed as cell (0,0,0). The shaded cell is indexed as cell (2,5, 13).

In the uniform-grid decomposition, the dimension of the cubic cells plays


an important role in minimizing the number of unnecessary objects to
cell assignments, and in maximizing the overall efficacy of the simulation.
Intuitively, the size of each cell should be:
34 2. Hierarchical Representation of 3D Polyhedra

• Large enough to allow objects to rotate and translate for a while


without leaving the cell, thus minimizing the number of dynamic
updates of objects assigned to each cell;

• Small enough to have as many objects as possible assigned to differ-


ent cells, thus minimizing the pair-wise collision checks between the
object's hierarchical representations.

Let di be the maximum diameter of the top-most bounding volume of


object i. For example, if the bounding volume is a box, then the maximum
diameter is the distance between the two diagonally opposing vertices defin-
ing box. If the bounding volume is a sphere, then the maximum diameter
is equal to the diameter of the sphere. The average maximum diameter of
the objects being simulated is then

where n is the total number of objects4. The size b of each cell in the
uniform-grid decomposition is also given by the cell's maximum diameter,
and can be related to the average maximum diameter of the objects being
simulated as

J
b = k, (2.1)

with k 2: 1. The variable k is used to adjust the size of the cell with respect
to the average maximum diameter of the objects being simulated. As a
rule, we suggest using k = 2, that is, the size of each cell in the uniform
grid is twice the average maximum diameter. The rationale behind this
choice is as follows. If all objects had the average size, then we could have
up to eight objects in each cell (two objects touching each other along each
dimension), giving some room to an object to move within the same cell.
Also, objects that are farther apart by more than twice their average size
are guaranteed not to be in the same cell. On average, this choice gives us
a reasonable trade-off between the number of objects assigned to each cell
and the number of pair-wise collision checks carried out at each time step
if the objects' sizes are close to the average. However, if the objects' sizes
vary by orders of magnitude, then a more sophisticated approach, such as
the one presented in Section 2.3.2, should be used.
Having selected the size of the boxes in the decomposition, the next step
is to provide an efficient mechanism to keep track only of cells that have at

4The size of particles in a particle system is not taken into account during this
computation because particles are usually considered as point mass, as explained in
detail in Chapter 3.
2.3 Hierarchical Representation of the Simulated World 35

least one object assigned to them, as opposed to allocating memory to all


cells. Clearly, the latter approach is not advisable for cases when the size
of each cell is orders of magnitude smaller than the size of the simulated
world, since the number of cells along each axis would be huge, and the
memory needed for a subdivision containing n cells is n 3 . The idea here is
to use a hash table to keep track of the occupied cells. There are many ways
this hash table of cells can be constructed, and some may be more effective
than others, depending on the specifics of the simulation being considered.
However, as a rule, we suggest using a hash table of size n, where the key is
the sum of the indexes of the cell along each axis. This will have the effect
of assigning one slice (plane) of the grid decomposition to each hash-table
entry.
The update mechanism using the hash table is used to efficiently detect
pairs of potentially colliding objects. Initially, the top-most bounding vol-
ume of each object is checked against the cell decomposition. Each cell that
intersects the object's bounding volume is added to the hash table of cells.
If the cell was already added to the hash table, then there are at least two
objects assigned to this cell, and a pointer to this cell is added to a list
of cells that need to be checked for collisions. At the end, after all objects
are checked against the cell decomposition, another list of potentially col-
liding objects is created from the list of cells that needs to be checked for
collisions. The former list contains pairs of objects that occupy the same
cell. For each of these pairs, the more expensive collision check using their
hierarchical representation is carried out.
The cells of the uniform-grid decomposition that intersect an object's
bounding volume can be efficiently determined if we consider an AABB
bounding box of the object's bounding volume in the world-coordinate
system. Notice that this selection is independent of the hierarchical tree
representation of the objects. The AABB bounding box is aligned with
the world coordinate system, as are all cubic cells in the uniform-grid de-
composition. The box-box intersection test between boxes that have their
axes aligned is extremely fast and can be used to determine the actual
cubic cells in the decomposition that need to be checked for intersection
with the object's bounding volume. Figure 2.12 illustrates this situation for
an object using the bounding-sphere representation. The AABB bounding
box of the bounding sphere is used to efficiently locate the cells in the
decomposition that need to be checked for intersection with the object's
bounding sphere, as opposed to checking the intersection of every cell with
the object's bounding sphere.
As objects translate and rotate during the simulation, their top-most
bounding volume will move. This movement may cause the bounding vol-
ume to no longer intersect some of the cells the object is assigned to, and
may also intersect new cells that did not have the object on their list.
Therefore, the list of objects assigned to each cell needs to be updated af-
ter each simulation time step to reflect these changes. This update can be
36 2. Hierarchical Representation of 3D Polyhedra

FIGURE 2.12. The AABB bounding box of the object's bounding sphere is used
to quickly determine which cells of the decomposition need to be checked for
intersection with the bounding sphere. In this case, the bounding sphere will be
checked further for intersections with cells (2,5,4), (2,6,4), (3,5,4), (3,6,4), (2,5,5),
(2,6,5), (3,5,5) and (3,6,5).

efficiently implemented using coherence between simulation time steps, as


follows.
Throughout the simulation, each object keeps track of the indexes of the
cells that intersect its bounding volume. At each time step, a new list of
indexes of cells that intersect the object's bounding volume is generated.
This new list is then compared with the old list. If the new list is the same
as the old list, then the object's cell assignment remains the same as in the
previous time step, and nothing else needs to be done. If there are cells on
the new list that are not on the old list, then we search for these cells in
the hash table of cells. If we find the cell in the hash table, then we add a
reference to this object and raise the cell's internal counter. Otherwise, we
create an entry for the cell in the hash table and set its internal counter
to one. Finally, if there are boxes on the old list that are no longer on the
new list, then the reference to this object should be removed from the cell's
entry in the hash table, and its internal counter is subtracted byone.
The cell's internal counter is used to keep track of the number of objects
currently intersecting the cell. The first time the counter is set to two, a
reference to this cell is added to the list of cells that contain potentially
colliding objects. The counter can be set to values greater than two, but as
long as it has at least two, the reference to this cell will be kept in the list.
The reference to this cell is removed from the list when the counter first is
reduced from two to one. The cell is removed from the hash table of cells
when the counter is set to zero.
2.3 Hierarchical Representation of the Simulated World 37

2.3.2 Multi-Level Grid


If the size of the objects being simulated differs by orders of magnitude,
the efficiency of the uniform-grid approach can be improved by extending
it to a multi-level grid. The idea is to group at the same level, objects with
sizes of the same order of magnitude such that each level can be treated
as an uniform grid in itself. The advantage is that each level attempts to
maximize the efficiency of its uniform grid, since it is guaranteed to have
objects of similar size. There are three important issues that need to be
addressed when using this method.

• How many levels should be chosen for a given set of objects?


• What should be the size of the cells at each level?
• How the levels are related so that collisions between objects assigned
to different levels can be efficiently detected?

In the uniform-grid case, since we have a single level, the size of the cell
is determined from equation (2.1) as a multiple of the average size of the
maximum diameter of the objects in the simulation. In the multiple-level
case, object i is assigned to level j if

(2.2)

where di is the maximum diameter of the top-most bounding volume of


object i, k min and k max are user-definable constants, and L j is the size of
the cells at level j, such that

o < L1 < L2 < ... < Lj < ... < Lm

for 1 ::; j ::; m. The idea is to assign object i to the largest level j such that
equation (2.2) is satisfied. In other words, the largest objects are assigned
to the largest boxes (largest levels), so that objects at level (j + 1) have
diameters greater than objects at level j. The constants k min and k max are
used to relate the size of the cells at different levels. They must satisfy

0< kmin <1


kmax 2: 1 .
Let dmin and dmax be the minimum and maximum diameters of all ob-
jects in the simulation. Clearly, the objects associated with dmin (the small-
est objects) should be assigned to level 1 (the lowest level). This is done by
substituting dmin and L1 into equation (2.2), that is
38 2. Hierarchical Representation of 3D Polyhedra

If we make
d min
k min = Lt'
then we have that the size of the cells at the lowest level is given by

L1_ dmin
---· (2.3)
k min
The objects associated with dmax should be assigned to the largest level
m. This is done by substituting dmax and Lm into equation (2.2), and
making
dmax
Lm = k max ,

that is

L _ dmax (2.4)
m- k max ·

Because we want the level assignment to be continuous, we need to make


sure the maximum value at level j is equal to the minimum value at level
(j + 1), that is

k max L j = k min Lj+1 . (2.5)


Equation (2.5) relates the size of the cells at two consecutive levels. We
can use this equation to recursively compute the size of the cells at level j
as a function of the size of the cells at levell, as follows:

k max L 1
--
k min

L 3=kmax L
-- 2
k min
( km~x)2
k mm
L1

(k ) m~x
j-1
L1 . (2.6)
k mm

Because we have the size of the boxes at the first level L1 and the largest
level Lm given by equations (2.4) and (2.5), respectively, we can substitute
these equations into (2.6) and compute the number of levels m needed as
a function of k min , k max , d min and d max . We have

d max _ (kmax)m-1 d min


k max - k min k min '

which gives
2.3 Hierarchical Representation of the Simulated World 39

m = rIOg(k"'~.r) (ddm~x)l
k'I'n',n m'tn
. (2.7)

Figure 2.13 shows an example of a multi-level grid assignment. At each


level j, the simulated world is subdivided in a uniform grid with boxes of
size L j •

4=16

FIGURE 2.13. An example of a multi-level grid assignment for kmax = 1, kmin


= 0.5, d max = 16 and dmin = 2. The maximum number of levels to be used and
their sizes can be directly computed from equations 2.7 and 2.6, respectively. In
this case, m = 3, Ll = 4, L2 = 8 and L3 = 16.

Therefore, the multi-level grid has one hash table of cells for each level,
and the sizes of their cells are given by equation (2.6). The update mech-
anism for each hash table is the same as that used in the uniform grid,
since we do have a uniform grid at each level. Consider, for example, the
bounding sphere of an object with center at (5,5,5) and maximum diam-
d
eter = 9.7 (see Figure 2.14). For the multi-level grid of the simulated
world shown in Figure 2.13, according to equation (2.2), the object should
be assigned to level 2. Within level 2, the cells that intersect the object's
bounding volume are computed the same way as shown in Figure 2.12 for
the uniform-grid case.
The only remaining issue is how this scheme can be used to efficiently
detect potential collisions between objects assigned to different levels of
the grid decomposition. We address this issue by adding a reference to the
object, not only to the cells that intersect the object at its level, but also to
all other cells that intersect the object at levels greater than its level. For
example, an object assigned to level j will have its reference added to all
cells that intersect its bounding volume at levels j, (j+l), ... ,m. In the case
shown in Figure 2.14, the cells at levels 2 and 3 that intersect the object's
bounding volume will keep a reference to this object (see Figures 2.15
and 2.16). Using this scheme, two objects b1 and b2 assigned to levels Lb 1
and Lb2 can potentially collide if and only if there exist at least one cell at
40 2. Hierarchical Representation of 3D Polyhedra

l:x z
~- -
--;r::9.7
....... ............
............
........................

FIGURE 2.14. An example of the multi-level grid assignment of an object to level


2, in the simulated world of Figure 2.13, containing 3 levels.

L,@j - ....... ...........


--- -- -- ......
...........
............
......

FIGURE 2.15. The cells at level 2 that intersect the object's bounding sphere.

L,GJ-- - ....... ......


--- -- ...........
............
...........
......
z

FIGURE 2.16. The multi-level grid assignment makes it necessary to determine


the cells at level 3 that intersect the object. This is in order to detect potential
collisions between this object and other objects assigned only to level 3.
2.3 Hierarchical Representation of the Simulated World 41

level max (Lb 1 , L b2 ) that has a reference to both of them. This situation is
illustrated in the one-dimensional case shown in Figure 2.17.

FIGURE 2.17. A one-dimensonal example of how potential collisions are detected


between objects assigned to different levels.

In this example, objects b1 and b2 are assigned to levels L1 and L 3 ,


respectively. Since there is a box at level m = max(Ll, L 3) = L3 that
contains a reference to both of them, the objects are added to the list
of potentially colliding objects. On the other hand, objects b3 and b4 are
assigned to levels L1 and L 2 , respectively. Since there are no boxes at level
m = max(Lb L 2) = L2 that contain a reference to both of them, they are
not considered to be on the list of potentially colliding objects, even though
there is a cell at level L3 referring to both of them.
As a rule, we suggest choosing kmin and kmax such that

k max = 2.
k min

This choice means the size of the cells will be a power of two times the
minimum diameter dmin . With this choice, given an object assigned to level
j, it is straightforward to ascertain which cells intersect the object at levels
(j + 1), ... , m.
12 2. Hierarchical Representation of 3D Polyhedra

2.4 Collision Detection Between Different


Hierarchical Representations
Up till now, we have described several types of hierarchical representations
that can be used to speed collision detection between objects in a simulation
engine, as well as how we can build them using simple primitives. In this
section we shall present efficient algorithms to quickly determine whether
two primitives are intersecting.
The primitives of the representations covered in this book are boxes and
spheres for the tree hierarchies, and triangles for the faces of the objects.
Therefore, we need algorithms for checking the intersection of each possible
pair-wise combination of such primitives. Moreover, for the triangle-triangle
intersection test, we need to go one step further and save pointers to the in-
tersecting triangles. This information will be used by the collision-response
module to estimate the collision (or contact) point between the objects,
and determine the collision impulses (or contact forces) needed to prevent
their interpenetration.

2.4.1 Computing Box-Box Intersections


The intersection test between two boxes is based on the separating-axis
theorem. This theorem states that two boxes A and B are disjoint if and
only if there exists a separating plane such that the boxes are located on
different sides of the plane.
Let fi be the normal of a plane P, and let d be its non-negative distance
to the origin. The plane P is a separating plane of boxes A and B if

fi . ii + d :::: 0, 'if ii E A (2.8)


and

(2.9)
that is, if the projections of A and B along the normal fall on opposite
sides of the plane. Equations (2.8) and (2.9) can then be combined into the
single equation

n. a < n . b, 'if a E A, 'if bE B . (2.10)


Equation (2.10) states that, if P is a separating plane of boxes A and B,
then their images are disjoint under axial projection along an axis parallel
to the plane normal n. In other words, n
is a separating axis of A and
B. It can be shown that the separating-axis candidates are the normals to
the faces of A and B, and the normals to the planes defined by one edge
of A and one edge of B. This results in 15 potential cases to be tested: 3
different face normals for each box plus 9 pair-wise combinations of edges.
2.4 Collision Detection Between Different Hierarchical Representations 43

If none of the potential separating axes actually separates the boxes, then
the boxes are guaranteed to be overlapping.
Let us first consider the simple intersection case, where the boxes are
aligned with each other and are parallel to the world-coordinate system's
axis. This case occurs in the hierarchical representation of the simulated
world, where all boxes in the uniform or multi-level grids have the same
orientation with respect to the world-coordinate system. In such situations,
the 15 potential cases are reduced to just 3, since the face normals of each
box are the same and the pair-wise combination of their edges always gives
another edge. Therefore, the three separating-axis candidates are the axes
of the world-coordinate system.
Let each box be represented by its minimum and maximum vertices, as
indicated in Figure 2.18.

A",;.~~-,
y

I I
X I I I

.1.----1'...... I : ----1'I . . . . .
I I I I I

-----........ I . . . . . J
. . . . . ::J---------~;:-
I
I ...............:
--:::------ ............ ~------~
-------------
FIGURE 2.18. Axis-aligned box-box intersection test. Each box is defined by its
minimum and maximum vertices. The intersection test is then carried out by
checking whether their projections along each coordinate axis overlap. In this
case, the z-axis is a separating axis and the objects do not overlap.

Let [(Amin)i, (Amax)i] and [(Bmin)i, (Bmax)i] be the projections of boxes


A and B along the coordinate axis i, for i = {x, y, z}. The boxes A and B
will not overlap if and only if

(2.11)

for at least one projection axis i E {x, y, z}. This projection axis is then
the separating axis for the boxes. On the other hand, if equation (2.11) is
not satisfied for all projection axes, then the boxes are guaranteed to be
overlapping.
Having considered the simple axis-aligned case, let's move on to the more
complex case wherein the boxes are arbitrarily oriented with respect to
each other. This happens when checking for intersections between boxes
44 2. Hierarchical Representation of 3D Polyhedra

in the AABB or OBB hierarchical representations, since they usually have


different orientations in the world-coordinate system.
Let TA and RA be the translation vector and rotation matrix from A's
local-coordinate system to the world-coordinate system. The axis of A in
the world-coordinate system will then be given by the columns of RA,
namely (RA)x, (RA)y and (RA)z. Similarly, let TB and RB be the trans-
lation vector and rotation matrix from B's local-coordinate system to the
world-coordinate system, and the axis of B in the world-coordinate system
be (RB)x, (RB)y and (RB)z. Let dbe the distance vector between the cen-
ter of the boxes in the world-coordinate system. The boxes A and B will
be disjoint if and only if the sum of the projections of their half-sides along
the candidate separating axis ii is less than the projection of their distance
vector d along ii, that is

(rA . ii + r"B . ii) < d· ii , (2.12)

where r A and rB are the sum of the projections of the half-sides of A and
B, respectively. Figure 2.19 illustrates this.

FIGURE 2.19. Arbitrarily oriented box-box test. The boxes will not intersect if
the axial projection of the distance between their centers is greater than the sum
of the axial projection of their half-sides. There are 15 possible axial directions
to be tested.

The distances between boxes A and B to the origin of the world-coordi-


nate system are given by TA and TB. Therefore, their distance vector can
be directly obtained from

(2.13)
2.4 Collision Detection Between Different Hierarchical Representations 45

The half-sides of each box can be computed from the boxes' minimum
and maximum vertices transformed to the world-coordinate system. Let
ax, ay and a z be the half-sides of box A along its axes (RA)x, (RA)y and
(RA)z. Similarly, let bx , by and bz be the half-sides of box B along its axes
(RB)x, (RB)y and (RB)z' The sum of the projections of the half-sides of
A and B along ii are then

(2.14)

Substituting equations (2.14) and (2.13) into (2.12), we have that ii is a


separating axis if and only if

(ax I (RA)x . ii 1+ ay I (RA)y . ii I + az I (RA)z . ii I +


bx I (RB)x . ii I + by I (RB)y . ii I + bz I (RB)z . ii I) < (2.15)
ITA -TB I· ii

is satisfied for the 15 possible combinations of ii, namely ii = (RA)i, ii =


(RB)i or ii = (RA)i x (RB)j for i,j E {x,y, z} and i i j.
Equation (2.15) can be simplified if we carry out the computations in
A's local-coordinate system, as opposed to the world-coordinate system.
This can be done by translating all points by -TA and rotating them by
RA -1 = RA t. This yields

TA (TA - TA) = (0,0,0)


RA RAtRA = Is
(2.16)
TB RAt (TB - T A )
RB RAtRB ,

where Is is the 3 x 3 identity matrix. Substituting equation (2.16) into


(2.15), we can explicitly derive the equations for all 15 possible tests for
finding a separating axis for boxes A and B with respect to A's local-
coordinate system. These results are summarized in Table 2.1, on page 59.

2.4.2 Computing Sphere-Sphere Intersections


The sphere-sphere intersection test is by far the simplest in this chapter.
Two spheres are not intersecting if and only if the distance between their
46 2. Hierarchical Representation of 3D Polyhedra

CA~-------r-------+----~

FIGURE 2.20. The sphere-sphere intersection test can be quickly conducted by


comparing the distance between the centers of the sphere with the sum of their
radii.

centers is greater than the sum of their radii. This is illustrated by Fig-
ure 2.20.
Let r A and CA be the radius and center of sphere A, respectively. Simi-
larly, let rB and CB be the radius and center of sphere B. The spheres will
not overlap if and only if

2.4.3 Computing Triangle-Triangle Intersections


The triangle-triangle intersection test is considered a primitive-primitive
intersection test, since the triangles are in fact faces of the objects in the
simulation. Let triangles A and B be defined by vertices aI, a2, a3 and 61,
b2 and 63 , respectively. The first step of the intersection test is to conduct a
quick rejection test. This test consists of determining whether all vertices of
one triangle lie on the same side of the plane defined by the other triangle.
Let P a and Pb be the planes defined by triangles A and B, respectively.
Let fia and fib be the normal vectors of P a and Pb. The normals can be
directly computed from the vertex list as

fia (a2 - aI) x (a3 - (1)

fib (b2 - b1 ) X (b3 - bI) .


The vertices of triangle B will lie on the same side of Pa if and only if

fia . (b1 - (1)


fia . (b2 - aI) (2.17)
fia . (b3 - aI)
are not zero and have the same sign. If they do not have the same sign,
then the following cases can occur.
2.4 Collision Detection Between Different Hierarchical Representations 47

Case 1:
Two of the three equations defined in (2.17) have the same sign and the
third evaluates to zero, say that corresponding to b2 • In this case, the inter-
section between triangle B and plane Pa is single point, that is, vertex b2
(see Figure 2.21). The triangle-triangle intersection test is then reduced to
check whether b2 lies inside triangle A. This point-in-triangle test can be
quickly done by considering the line segment connecting b2 to the barycen-
ter of A. If this line segment intersects one of the edges of triangle A,
then b2 lies outside the triangle. Otherwise, b2 lies inside triangle A, and
triangle B intersects triangle A. More details on how to implement the
point-in-triangle test are given in Section 2.4.4.

FIGURE 2.21. Case where just one vertex of triangle B touches the plane Pa
containing triangle A. As shown, b2 lies outside A and the triangles do not inter-
sect.

Case 2:
Two of the three equations defined in (2.17) evaluate to zero, say those
corresponding to b1 and b2 . In this case, the intersection between triangle
B and plane Pa is the line segment defined by (bb b2 ) (see Figure 2.22). We
can then apply the point-in-triangle intersection test for each one of the
vertices bl and b2. If both vertices lie outside triangle A, then triangle B
does not intersect triangle A. Otherwise, if one of the vertices lies inside and
the other outside, or if both lie inside, then triangle B intersects triangle
A.

Case 3:
All three equations defined in (2.17) evaluate to zero. In this case, triangles
A and B are coplanar (see Figure 2.23). The intersection test can then
be reduced to three point-in-triangle tests by considering the three line
segments connecting the vertices of B to the barycenter of A. If at least
one of these line segments intersects an edge of A, or the vertex of B
associated with this line segment lies on an edge of A, then this vertex
is guaranteed to be inside triangle A. In this case, triangle B intersects
triangle A. However, if all line segments do not intersect an edge of A,
48 2. Hierarchical Representation of 3D Polyhedra

FIGURE 2.22. Case whcre an edge of triangle B is coplanar with triangle A. As


shown, vertices ;;1 and ;;2 lie inside and outside A, respectively, and the triangles
intcrsect.

then triangle B does not intersect the edges of triangle A, but there is still
the possibility that A is completely inside B. Therefore, the same test is
repeated for A, namely, the vertices of A are connected to the barycenter
of B and the line segments are checked for intersection with the edges of B.
Again, if at least one of these line segments does not intersect an edge of B,
then the vertex of A associated with this line segment lies inside triangle
B. In this case, triangle A is inside (Le., intersects) triangle B.

FIGURE 2.23. Case where the triangles A and B are coplanar. As shown, the
vertices of B lie outside A, and the triangles do not intersect.

Case 4:
None of the three equations defined in (2.17) evaluates to zero. In this case,
we shall have two vertices of B on one side of plane Pa , and the third vertex
on the other side of Pa. This is illustrated by Figure 2.24.
Let b2 be the vertex that lies on the opposite side of plane Pa • Triangle B
will then intersect plane Pa in two points tit and P2 defining a line segment
on theyl~e of A. These points can be computed as follows. Consider edge
el = (bt, b2 ) given by its parameterized equation

(2.18)
where 0 ~ t ~ 1 and Pis a point on the edge. The plane equation of Pa is
given by

(2.19)
2.4 Collision Detection Between Different Hierarchical Representations 49

FIGURE 2.24. Triangle-triangle intersection test for the case where no vertices of
triangle B are coplanar with triangle A. One vertex of B will lie on the opposite
side of the other two vertices, with respect to the plane defined by triangle A.

where Pis any point on the plane and d is the plane constant given by

Edge el intersects plane Pa at a point PI that satisfies both equations


(2.18) and (2.19). Substituting equation (2.18) into (2.19), we can compute
the value of t corresponding to the intersection point PI, that is

tp = d- fi a _
_ • 1 6 (2.20)
fia . (b 2 - bl )
Substituting equation (2.20) back into (2.18), we can immediately find
the intersection point fft. A similar computation can be done to find the
intersection point P2 between edge e2 = (62 , 63 ) and plane Pa •
The line segment (PI, P2) can then be checked for intersection with tri-
angle A. We can apply the point-in-triangle intersection test for both PI
and P2. If both points lie outside triangle A, then triangle B does not in-
tersect triangle A. Otherwise, if one of the vertices lies inside and the other
outside, or if both lie inside, then triangle B intersects triangle A.

2.4.4 Point-in- Triangle Test


All point-in-triangle tests described in each of the above cases use the
segment-segment intersection test, whpre the line segments are coplanar.
This test can be efficiently implemented as follows. Let 81 = (PI, P2) and
82 = ( qi , ti2) be the line segments being tested for intersection, and let
50 2. Hierarchical Representation of 3D Polyhedra

ii be the normal vector of the plane that contains both segments. The
parameterized equations of the segments are then

P PI + t (P2 - PI)
ij iji + m (if2 - ijt) ,

with 0 ::; t ::; 1 and 0 ::; m ::; 1. The first step of the intersection test
consists of carrying out a quick rejection test. This test consists of checking
whether the line segments are parallel, that is, checking whether

If the line segments are not parallel, they will intersect if and only if
there exist t = tp and m = mq such that

(2.21)
with 0 ::; tp ::; 1 and 0 ::; mq ::; 1. Equation (2.21) can be solved for tp and
mq if we consider two auxiliary vectors kp and kq given by

(2.22)

that is, kp and kq are non-zero vectors perpendicular to (P2 - PI) and
(if2 - ijt), respectively. If we apply a dot product by kp on both sides of
equation (2.21), then the term multiplying tp evaluates to zero, and we can
therefore determine mq as

If mq < 0 or mq > 1, then the intersection point lies outside the line
segment 82, and the segments do not intersect. Otherwise, we apply a dot
product by kq on both sides of equation (2.21), and obtain tp as

Again, if tp < 0 or tp > 1, then the intersection lies outside the line
segment 81, and the segments do not intersect. Otherwise, the segments
intersect at the intersection point computed by substituting either tp or
mq into equation (2.21).
2.4 Collision Detection Between Different Hierarchical Representations 51

2.4-5 Computing Box-Sphere Intersections


The intersection between a box and a sphere is carried out by considering
the point in the boundary of the box that is closest to the sphere, and
checking whether its distance to the center of the sphere is greater than
the sphere's radius. If the distance is less than or equal to the sphere's
radius, then the box intersects the sphere.
Let jJ be a point in the box, and let c and r be the sphere's center and
radius, respectively. Let Xmin, X max , Ymin, Ymax, Zmin and Zmax define the
minimum and maximum values of the boundary of the box along each of
the coordinated axes, as shown in Figure 2.25.

FIGURE 2.25. The closest point to the sphere is on the boundary of the box and
minimizes the distance to the center given by equation 2.23.

The square of the distance from jJ to c is then given by


(2.23)
The point jJ that is closest to the sphere is that which minimizes equa-
tion (2.23), subject to the following constraints:

Xmin :S Px :S Xmax
Ymin :S Py :S Ymax
Zmin :S pz :S Zmax

Notice that each term of the equation (2.23) is non-negative and can be
independently minimized. For example, if Xmin :S ex :S X max , then Px = ex
minimizes the term (ex - Px)2. However, if ex < Xmin or ex > X max ,
then Px = Xmin or Px = Xmax minimizes the term, respectively. We do
a similar analysis for finding the value of Py and pz that minimizes their
corresponding quadratic terms.
Having determined the coordinates of the closest point to the sphere,
we just need to compare its distance to the center of the sphere with the
sphere's radius by substituting the coordinates of jJ into equation (2.23),
and checking whether
52 2. Hierarchical Representation of 3D Polyhedra

(2.24)
The box will intersect the sphere if and only if equation (2.24) is satisfied.

2.4.6 Computing Box-Triangle Intersections


The box-triangle intersection test can be quickly carried out in at most
three steps. In the first step, we check whether the vertices of the triangle
are inside the box. If at least one of the vertices is inside the box, then the
triangle intersects the box.

(a) (b)

FIGURE 2.26. (a) The triangle intersects the box whenever one of its vertices lies
inside the box; (b) The plane containing the triangle intersects the box. Edges of
the box that have vertices at opposite sides of the plane, in this case edges b5 bs,
b4bs and b7 bs , need to be checked for intersection with the triangle.

Let the box be defined by its minimum and maximum vertices, and let
ih, ih and V3 be the vertices of the triangle (see Figure 2.26(a)). Vertex Vi
is inside the box if and only if

Xmin ::; (Vi)x ::; Xmax

Ymin ::; (Vi)y ::; Ymax (2.25)


Zmin ::; (Vi)z ::; Zmax

If at least one of the vertices VI, V2 or V3 satisfies equation (2.25), then


the triangle intersects the box. Otherwise, we proceed to the second step.
In the second step, we check whether the plane containing the triangle
intersects the box. This can be done by checking whether the eight vertices
of the box lie on the same side of the plane (see Figure 2.26(b)). Let ii be
the normal of the triangle and d the plane constant determined from
2.4 Collision Detection Between Different Hierarchical Representations 53

d = ii· Vi, for i E {I, 2, 3} .

A point p is classified with respect to the plane containing the triangle


as follows:

If ii· p- d > 0 =} pis on positive half-plane


If ii· p- d = 0 =} plies on the plane (2.26)
If ii . p - d < 0 =} Pis on negative half-plane.
Using equation (2.26), we classify each vertex of the box according to
its relative position with respect to the plane. If all vertices lie on the
same half-space, then we can immediately conclude that the box does not
intersect the triangle. Otherwise, we need to consider the edges of the box
that intersect the plane, that is, the edges that have vertices at opposite
sides of the plane, or one vertex on the plane and another on either side.
These edges define line segments and a line segment-triangle intersection
test is done for each of them, as explained in detail in Section 2.4.9.

2.4.7 Computing Sphere- Triangle Intersections


The sphere-triangle test is more complex than the box-triangle test, in the
sense that it has more steps to be carried out before we can determine
whether the sphere is intersecting the triangle.

FIGURE 2.27. The triangle intersects the sphere whenever one of its vertices lies
inside the sphere, that is, the distance from one of its vertices to the center of
the sphere is less than or equal to the sphere's radius.

The first step is to check whether the plane that contains the triangle
intersects the sphere. This can be done by comparing the distance of the
54 2. Hierarchical Representation of 3D Polyhedra

plane to the center of the sphere with the radius of the sphere. Let r A and
CA be the sphere's radius and center. Let fit, ih and V3 be the vertices of
the triangle defining plane P (see Figure 2.27). Let nand d n be the plane
normal and plane constant. The distance between the plane P and the
sphere's center is then

The plane containing the triangle intersects the sphere whenever

If this is the case, then we proceed with the sphere-triangle intersection


test by checking whether the vertices of the triangle are inside the sphere. If
at least one of the vertices is inside the sphere, then the triangle intersects
the sphere. Let di be the distance between vertex Vi and the sphere's center,
that is

The sphere will intersect the triangle if

(2.27)
for at least one vertex Vi (see Figure 2.27). If this is not the case, then we
proceed to the third step of the sphere-triangle intersection test. In this
step, we project the sphere onto the plane containing the triangle, and
check whether the projected center lies inside the triangle. The projected
center Cproj is determined from

We can use the point-in-triangle test already explained in Section 2.4.4


to see whether the projected center lies inside the triangle. If the projected
center cproj lies inside the triangle, then the sphere intersects the triangle
(see Figure 2.27). Otherwise, we need to do one more test to check whether
the triangle edges intersect the sphere, as explained in the next section.

2.4.8 Computing Line Segment-Sphere Intersections


Let Pl and iJ2 define a line segment S, and CA and r A be the sphere's
center and radius, respectively. Consider the line L passing through CA and
perpendicular to the line segment S (see Figure 2.28).
Line L will intersect the line segment S at a point cproj such that
2.4 Collision Detection Between Different Hierarchical Representations 55

FIGURE 2.28. Intersection test between a sphere and a line segment. We only
need consider the intersection of the line segment with the circle resulting from
the intersection of the sphere and the plane defined by the center of the sphere,
and the end points of the line segment.

for t, given by
(iJ2 - pt) . CA - (P2 - PI) . PI
t = (_ _) (_ _) ,
P2 - PI . P2 - PI
that is, Cproj is the projection of the center of the sphere onto the line
segment's supporting line. The distance between the projection point Cp.,oj
and the center of the sphere is directly obtained from

d~ = (cproj - CA) . (cproj - CA) .

Having determined the projection point Cp.,Oj and its (squared) distance
d~ to the center of the sphere, one of the of the following three cases occurs.
1. If d~ > r~, then the sphere does not intersect the triangle.
2. If d~ = r~, then the supporting line is tangential to the sphere. If the
projection point Cp.,oj is inside the segment, that is, if 0 :::; t :::; 1, then
the line segment intersects the sphere.
3. If d~ < r~, then the supporting line intersects the sphere. The seg-
ment intersects the sphere if the projection point Cp.,oj is inside the
segment. Otherwise, an intersection occurs if the closest end point to
cproj is inside the sphere. The closest end point is PI if t :::; 0, or P2 if
t 2': 1.

2.4.9 Computing Line Segment- Triangle Intersections


The intersection of a line segment S with a triangle A can be viewed as a
subset of the intersection test between two triangles. Let the line segment
56 2. Hierarchical Representation of 3D Polyhedra

be defined by vertices 81 and 82, and the triangle be defined by vertices a1,
a2 and a3.
First, we check whether the vertices defining the line segment lie on the
same side of the plane containing the triangle (see Figure 2.29). If this is
so, then we can quickly conclude that the segment does not intersect the
triangle. Otherwise, we can have one of the following three cases.

FIGURE 2.29. Case where the vertices defining the line segment lie on the same
side of the plane containing triangle A. As shown, the line segment does not
intersect the triangle.

Case 1:
One vertex of the line segment, say vertex 82, lies on the plane that contains
the triangle, and the other lies on either side (see Figure 2.30). In this case,
we use the point-in-triangle test for checking whether 82 lies inside A. The
line segment intersects the triangle only if 82 lies inside A.

FIGURE 2.30. Case where one vertex of the line segment is coplanar with triangle
A. As shown, vertex 82 lies outside A, and the line segment does not intersect
the triangle.

Case 2:
Both vertices of the line segment lie on the plane containing A (see Fig-
ure 2.31). Again, we use the point-in-triangle test for checking the relative
2.5 Notes and Comments 57

location of the vertices with respect to the triangle. The line segment in-
tersects the triangle only if one of its vertices lies inside the triangle and
the other outside, or if both vertices lie inside the triangle.

FIGURE 2.31. Case where the line segment is coplanar with triangle A. In the
situation shown, vertices 81 and 82 lie inside and outside A, respectively, and the
line segment does intersect the triangle.

Case 3:
The vertices of the line segment lie on opposite sides of the plane containing
the triangle (see Figure 2.32). Let fft be the intersection between the line
segment and the plane containing the triangle. Using the point-in-triangle
test, we can check whether PI lies inside the triangle.

FIGURE 2.32. Case where the vertices defining the line segment lie on opposite
sides of the plane containing triangle A. As shown, the intersection point P1
between the line segment and the plane lies outside A, and the line segment does
not intersect the triangle.

2.5 Notes and Comments


The literature on hierarchical decompositions is extensive, with related pub-
lications on several research areas such as computational geometry, com-
puter graphics, robotics and molecular simulations. There are several other
58 2. Hierarchical Representation of 3D Polyhedra

representations and variants of the techniques presented in this chapter,


specially with respect to implementation.
The OBB tree representation became an option since Gottschalk et
at. [GLM96, Got96] introduced the separating-axis theorem for carrying
out fast interference detection between arbitrarily oriented boxes. Bergen
[vdB97] presented a modified interference-detection test using AABB tree
representations in which the search for a separating axis considered only
the normals of the faces of the boxes. The pair-wise edge-direction tests
were ignored, thus reducing the complexity of the test, but consequently
being about 6% less accurate.
The use of bounding spheres, instead of bounding boxes, is also popular,
owing to the simplicity of its implementation. The efficiency of bounding-
sphere representations can be further improved if we use quad-trees or
oct-trees instead of binary trees. Samet [Sam89] gives a good introduc-
tion to both quad-tree and oct-tree representations. The difficulty in us-
ing bounding-sphere representations is to come up with a partition that
best approximates the original polyhedra. Hubbard [Hub96] developed a
collision-detection algorithm that approximates 3D polyhedra with an oct-
tree representation of bounding spheres, using a sophisticated technique
based on 3D Voronoi diagrams to construct the spheres at each intermedi-
ate level of the decomposition.
The 3D convex-hull computation can be found in Preparata et al [PS85],
Edelsbrunner [Ede87], and in several other books on computational geom-
etry. In the OBB case, there is also the need to determine the eigenvectors
of the covariance matrix of the vertices of the convex hull. Eigenvectors
and their associated eigenvalues are covered in detail in Strang [Str91 J,
Golub [GL96] and Horn [HJ91].
The multi-level grid-structure analysis presented in Section 2.3.2 was
derived from Mirtich [Mir96b]. Some primitive-primitive tests presented in
Section 2.4 were obtained from Gottschalk [Got96] (box-box), Arvo [Arv90]
(box-sphere), Ritter [Rit90] (sphere-sphere) and Karabassi et at. [KPTB99]
(sphere-triangle). The triangle-triangle intersection test presented in Sec-
tion 2.4.3 is a combination of the three different intersection tests pre-
sented in Held [HeI97], Moller [MoI97] and Glaeser [Gla94]. Other interest-
ing primitive-primitive tests involving cones and cylinders can be found in
Held [HeI97].
2.5 Notes and Comments 59

Separating Simplified Overlap Test


Axis ii
(RA)x 1(TB)x 1 >
(ax + bx 1(RB)xx 1 + by 1(RB)xy 1 + bz 1(RB)xz I)
(RA)y 1(TB)y 1 >
(a y + bx 1(RB)yx 1 + by 1(RB)yy 1 + bz 1(RB)yz I)
(RA)z 1(TB)z 1 >
(a z + bx 1(RB)zx 1 + by 1(RB)zy 1+ bz 1(RB)zz I)
(RB)x 1(TB)x (RB)xx + (TB)y (RB)yx + (TB)z (RB)zx 1 >
(bx + ax 1(RB)xx 1+ ay 1(RB)yx 1 + az 1(RB)zx I)
(RB)y 1(TB)x (RB)xy + (TB)y (RB}Yy + (TB)z (RB)zy 1 >
(by + ax 1(RB)xy 1+ ay 1(RB)yy 1 + az 1(RB)zy I)
(RB)z 1(TB)x (RB)xz + (TB)y (RB)yz + (TB)z (RB)zz 1 >
(bz + ax 1(RB)xz 1+ ay 1(RB)yz 1+ az 1(RB)zz I)
(RA)x x (RB)x 1(TB)z (RB)yx - (TB)y (RB)zx 1 > (a y 1(RB)zx 1+
az 1(RB)yx 1+ by 1(RB)xz 1+ bz 1(RB)xy I)
(RA)x x (RB}y 1(TB)z (RB}Yy - (TB)y (RB)zy I> (a y 1(RB)zy 1+
az 1(RB)yy 1+ bx 1(RB)xz 1+ bz 1(RB)xx I)
(RA)x x (RB)z 1(TB)z (RB)yz - (TB)y (RB)zz I> (a y 1(RB)zz 1+
az 1(RB)yz 1 + bx 1(RB)xy 1+ by 1(RB)xx I)
(RA)y x (RB)x 1(TB)x (RB)zx - (TB)z (RB)xx I> (ax 1(RB)zx 1+
az 1(RB)xx 1+ by 1(RB)yz 1+ bz 1(RB)yy I)
(RA)y x (RB)y 1(TB)x (RB)zy - (TB)z (RB)xy I> (ax 1(RB)zy 1+
az 1(RB)xy 1+ bx 1(RB)yz 1+ bz 1(RB)Yx I)
(RA)y x (RB)z 1(TB)x (RB)zz - (TB)z (RB)xz I> (ax 1(RB)zz 1+
az 1(RB)xz 1+ bx 1(RB)yy 1+ by 1(RB)Yx I)
(RA)z x (RB)x 1(TB)y (RB)xx - (TB)x (RB)Yx 1 > (ax 1(RB)yx 1+
ay 1(RB)xx 1+ by 1(RB)zz 1+ bz 1(RB)zy I)
(RA)z x (RB)y 1(TB)y (RB)xy - (TB)x (RB)yy I> (ax 1(RB)yy 1+
ay 1(RB)xy 1+ bx 1(RB)zz 1+ bz 1(RB)zx I)
(RA)z x (RB)z 1(TB)y (RB)xz - (TB)x (RB)yz I> (ax 1(RB)yz 1+
ay 1(RB)xz 1+ bx 1(RB)zy 1 + by 1(RB)zx I)

TABLE 2.1. The 15 candidate separating axes and their associated tests with
respect to A's local-coordinate system. The boxes are overlapping if and only if
all tests fail.
3
Particle Systems

3.1 Introduction
Particles are among the simplest and most versatile objects used in dynamic
simulations. The fact that their mass is concentrated on a point (Le., cen-
ter of mass) considerably simplifies the dynamic equations governing their
motion. All interaction forces among themselves and with other objects
in the simulation are applied to the points representing each particle, and
the rotational motion of a point is undefined, and therefore ignored. The
reduced complexity in the dynamic equations allows for an increased num-
ber of particles being simulated without significantly imparing operation
of the simulation engine. These simplifications make particle systems an
extremely attractive option to simulate systems requiring a large number
of objects that can be approximated as a collection of point-mass objects.
Examples of such systems range from molecules, to smoke, fire, clouds,
liquids, and even cloth.
The main difference between the diverse set of particle systems in use
nowadays resides in the types of interaction forces considered and the
numerical-integration methods used to solve their equations of motion.
Since particle systems usually need a large number of particles to achieve
their desired effects, the complexity of the computation of the interac-
tion forces between particles, other objects and the simulated environment
plays a key role in overall simulation efficiency. Expensive interaction forces
such as those that are spatially dependent, that is, their intensity varies
with respect to the distance between the particles, can severely impair

M. G. Coutinho, Dynamic Simulations of Multibody Systems


© Springer Science+Business Media New York 2001
62 3. Particle Systems

the efficiency, specially in naive implementations. For example, consider


a molecular-dynamics simulation where the spatially dependent Lennard-
Jones potential force acts between pairs of particles representing atoms.
The computational cost of determining the potential forces between all
pairs of particles is therefore O(n 2 ) for a particle system containing n par-
ticles. Clearly, a naive implementation of the potential-force computation
becomes prohibitively expensive, even for a moderate number of particles
such as n = 1000.
The numerical-integration methods also play an important role in the
overall simulation accuracy and robustness. Recall that the actual motion
of the particles is determined from the numerical results obtained from the
numerical-integration module. A fast but inaccurate method can produce
unsatisfactory results that do not reflect the desired behavior of the par-
ticles in the system. On the other hand, an accurate numerical method
can generate an unsatisfactory performance hit that deems useless any at-
tempts to deliver interactive simulation speeds. In most cases, there is a
trade-off between the computational accuracy of the models used to nu-
merically integrate the evolution of particle systems over time, and the
simulation's efficiency. Attaining interactive speeds using precise models of
the particles' motion often requires computational power that is available
only in high-performance computers, such as supercomputers, or a network
of parallel computers.
In this book, we focus primarily on particle systems that can be ana-
lyzed as classical multibody systems, meaning, the motion of the center
of mass of each particle follows the laws of classical mechanics. Such par-
ticle systems provide a reasonably good approximation of a wide variety
of point-mass systems, such as dust, snow and rain. However, there are
yet other types of point-mass systems that are widely used in dynamic
simulations and animations that require specialized forms of equations of
motion and force interactions to capture the precise physical behavior of
the system. Examples of such particle systems include the simulation of
turbulent gases (requires solving the volumetric differential Navier-Stokes
equations), the simulation of light atoms or molecules (may need to take the
quantum effects into account if the translational, vibrational and rotational
motions are considered), and the detonation of explosives (requires using
the Chapman-Jouget theory, possibly with the equations of the state for
the detonated particles derived from laboratory experiments). The detailed
explanation of the theoretical framework needed to capture the precise be-
havior of such specialized systems is beyond the scope of this book. The
interested reader is referred to Section 3.10 for pointers to the literature
wherein in-depth explanations of such techniques can be found.
Our approach to such particle systems as these, is the same as that com-
monly used in most animation environments. These software packages usu-
ally implement specialized particle systems having a set of user-adjustable
parameters used to capture phenomena not otherwise considered in the
3.2 Particle Dynamics 63

standard particle-system model derived from classical mechanics. The idea


is then to mimic the behavior of the system without having to solve the
sophisticated (and computationally demanding) equations of motion asso-
ciated with it. Section 3.9 presents some specialized particle systems com-
monly found in animation packages. It is important to notice that this is
the only section in this book that does not consider the mathematically ac-
curate modeling of the dynamics. It was included here to demonstrate the
versatility and modeling power that particle systems can have on dynamic
simulations and animations.
From the users' perspective, a particle system is defined by both a parti-
cle emitter and the particles themselves. The particle emitter, as its name
implies, is the source from which particles are created and released in the
simulation environment. It can be either attached to other objects in the
simulation, or be seem as an object in itself, in which case, the emitter
is displayed with its default cubic shape (see Section 3.8). The particle
emitter settings are used to control the dynamic behavior of the particles
being emitted. These settings define the particle's size, mass, initial veloc-
ity and direction of movement, and many other user-adjustable parameters
as explained in Section 3.9.1. As soon as the particles are released, their
motion is governed by the dynamic equations derived from classical mech-
anical theory. The particle's parameters give an extra degree of flexibility
in governing their motion, providing the added functionality needed to im-
plement the specialized systems covered in this book. Examples of such
parameters include the particle's split age, lifespan, color attributes and
collision-detection options.

3.2 Particle Dynamics


The dynamic equations that govern the motion of a particle in our standard
implementation of a particle system are the same as those governing the
motion of a point-mass object in classical mechanics. Let the point-mass
be represented by its mass m located at position p(t), which varies as a
function of time. The velocity of the point is obtained by computing the
derivative of its position with respect to time, namely

iJ(t) = djJ(t) .
dt
Its acceleration is then given by

a(t) = diJ(t) . (3.1)


dt
Let F(t) be the net external force acting on the particle at the time
instant t. Using Newton's law, we have
64 3. Particle Systems

F(t) = d~;t) , (3.2)

where L(t) is the linear momentum of the particle computed as

L(t) = miJ(t) . (3.3)


Substituting equation (3.3) into (3.2) and using equation (3.1) we obtain

F(t) = d(miJ(t)) = m diJ(t) = ma(t). (3.4)


dt dt
Let y(t) denote the dynamic state of the particle at time t, that is,
the vector comprising all variables necessary to define the dynamics of
the particle at any instant during the simulation. Here, we shall pick the
position and linear momentum of the particle to define its dynamic state,
namely

_ ( jJ(t) )
y(t) = L(t) .

The dynamic state of the particle at time t = to is defined by the parti-


cle's position p(to) and its linear momentum L(to) computed as miJ(to).
The time derivative of the dynamic state defines how the dynamic state
of the particle changes over time, and is given by

dy(t) = ( di!J.t)/ dt ) = ( i!.(t) )


dt d L(t)/ dt F(t)·
So, the time derivative of the dynamic state at time t = to is defined by
the particle's velocity iJ(to) computed as (L(to)/m) and the net force F(to)
acting on it.
For a system with N particles, we can combine their individual dynamic
states into a single system-wide dynamic-state vector

with its corresponding time derivative

aY(t)
= (3.5)
dt
3.2 Particle Dynamics 65

The dynamic simulation of a particle system works as follows. At the


beginning of the simulation, we have the dynamic state of every parti-
cle, namely their positions and linear momenta defined with respect to the
world reference frame. Each simulation time step will then consist of numer-
ically integrating equation (3.5), using the dynamic state of the particles
at the beginning of the time step as the initial condition for the numeri-
cal integration. There are several numerical methods that can be used to
integrate equation (3.5). For example, the Euler method computes a quick
(and less accurate) approximation of the time derivative by using only the
information about the dynamic state at the beginning of the time step to
predict the dynamic state of the system at the end of that time step. Oth-
ers, such as the several variations of the Runge-Kutta method, use a more
sophisticated approach in which the dynamic state at the end of the time
step is computed as a weighted sum of the dynamic state of the system at
several intermediate positions within it. These and other popular methods
are discussed in Appendix B.
The computation of the net external force acting on each particle at each
intermediate step of the numerical integrator is determined by summing
all external forces acting on the particles. The types of external forces
considered in this book range from simple global forces (such as gravity), to
point-to-point forces (such as springs), to more computationally demanding
spatially dependent forces (such as windy regions). The detailed discussion
on how to determine the contribution of each of these forces to the net
external force of each particle is presented in Section 3.3.
Initially, the determination of the dynamic state of each particle at the
end of the current time step is done without taking into account any pos-
sible collisions between particles and other objects in the simulation envi-
ronment. The information about the initial and final dynamic state of each
particle is then used to check for collisions between the particles themselves
and with other rigid bodies in the simulation (see Section 3.4). Whenever
a collision is detected, the colliding particles have their trajectories traced
back in time to the moment just before the collision. The collision point
and collision normal are then computed from the relative displacement of
the colliding particles. Only then the collision-response module is activated
to compute the appropriate impulsive or contact forces that will be applied
to change the direction of motion of the colliding particles. This is done
slightly differently if we have a particle-particle collision or a particle-rigid
body collision (see Sections 3.6 and 3.7 for more details).
The dynamic equations of all particles involved in a collision are then
numerically integrated for the remaining period of time, that is, from the
collision time to the end of the current time step. This new numerical
integration will update the current particles' trajectories to account for all
collision forces. Notice that this also requires the numerical integration of
the dynamic state of all other particles connected to one or more particles
involved in a collision, since the connection usually implies the existence of
66 3. Particle Systems

a force component between the particles. For example, consider a simple


particle system consisting offour particles 0 1 ,02,03 and 0 4 , and suppose
particles 0 1 and O 2 are connected by a spring.

FIGURE 3.1. A simple particle system containing four particles. The dynamic
state of the system is numerically integrated from ti to t f. A collision between
particles 02 and 03 is detected at time te.

\
\
\
\
\
\
\
\ f
\ f
\ f

ot;;;---~/
O (1,)
2

0 . (/,)

FIGURE 3.2. Particles 02 and 03 are traced back in time to the moment just
before their collision.

Initially, the dynamic state of the system is numerically integrated from


ti (the beginning of the current time step) to t f (the end of the current
time step). Now, assume the collision-detection module detected a collision
between particles O 2 and 03 at time tc such that ti < tc < t f (see Fig-
ure 3.1). The colliding particles are then traced back in time to the moment
before their collision (Le., traced back to t c ) and the collision impulses are
computed so as to prevent their interpenetration. Having applied the colli-
sion impulses to both particles, their trajectories are numerically integrated
for the remaining period of time, that is, from tc to t f. Notice that, if we
just trace back in time the trajectories of O 2 and 0 3 , the spring-force com-
putation between particles 0 1 and O 2 will be incorrect in the numerical
integration for the remaining period of time. The problem is that, since
3.2 Particle Dynamics 67

FIGURE 3.3. Particle 0 1 is also traced back in time to tc before the numerical
integrator is used to recompute the trajectories of particles 01, 02 and 03. No-
tice that particle 0 4 was not affected by the collision, and therefore remained
unchanged throughout the collision-detection and response phases.

particle 0 1 was not involved in any collision, its dynamic state corresponds
to time t f' whereas the dynamic state of particle O 2 corresponds to time tc·
So, if we do not trace back in time 0 1 too, the spring-force computation will
use 0 1 's position at time t f when it should use it at the same simulation
time of O2 , namely time tc (see Figure 3.2). In other words, the numerical
integration of the dynamic state of all interconnected particles should be
synchronized to provide the correct system behavior (see Figure 3.3). On
the other hand, particles that are not connected can be asynchronously
moved within the same simulation time step. This is the case of particle
0 4 as shown in Figure (3.3), since the numerical integration of O 2 and 0 3
for the remaining period of time does not affect its dynamic state, already
computed.
As far as implementation is concerned, this approach requires some book-
keeping mechanism to efficiently determine which particles are connected
to other particles and rigid bodies. The payoff is the significant efficiency
gain over the alternative approach of tracing back in time all particles, even
those not involved in any collision, to the moment before the most recent
collision.
The information about the initial and final dynamic state of each particle
along the updated part of its trajectory is used to check again for collisions
between all other particles and rigid bodies in the simulation. This process
repeats until all particle-particle and particle-rigid body collisions detected
within the current time interval have been resolved.
Clearly, the collision check is an intense process that can consume much
computational time, especially in a naive implementation. We suggest us-
ing the cell decomposition of the simulated world already discussed in Sec-
tion 2.3 to speed the collision-detection checks. By so doing, as the system
evolves, the position of each particle relative to the cell decomposition of
the simulated world is tracked by assigning the particle to the cell in which
68 3. Particle Systems

it is included. This dynamic assignment is efficiently implemented by ob-


serving that the cell decomposition defines a uniform subdivision of the
simulated world into cubic cells (see Section 2.3 for more details). A parti-
cle (Le., point-mass) with coordinates P = (Px,Py,Pz) will be included in
the cell C = (c x , cy, cz ) with

Ci = l~: J for i E {x, y, z} ,

where Be is the dimension of the cells in the decomposition. Notice that


this cell assignment can also be used to speed the computation of spatially
dependent forces as explained in Section 3.3.4.

3.3 Interaction Forces


The interaction forces used in most particle-system simulations can be cat-
egorized into three different types of forces. The first type considers global
interaction forces, that is, forces that are independently applied to all parti-
cles in the system. Examples of such forces include gravity and viscous drag
(used to simulate air resistance). They are the least expensive interaction
forces available in the simulation environment, since their required com-
putational cost is negligible compared with the other types of interaction
forces presented in this book.
The second type considers interaction forces between a specific number
of particles. Damped springs are a good example of such interaction forces
between two given particles. Notice, however, that particles can be attached
to more than one particle, and each attachment may use a different interac-
tion force. For example, multiple attachments of springs to pairs of particles
can be used to create a mesh of particles (Le., a spring-mass system) that
models cloth, as discussed in Section 3.9.2.
Interactive-user manipulation is also modeled as a point-to-point force
between the current mouse position and the selected particle. The goal
of using a fictitious interaction force between the mouse and the selected
particle is to prevent the introduction of unstable configurations resulting
from abrupt mouse movements, as explained in Section 3.3.5.
Finally, the third type of interaction forces considered in this book for
particle-system simulations is the spatially dependent force. This comprises
forces that depend on the position of the particles, either relative to each
other or to the simulated environment. For instance, a gravitational force
field depends on the relative positioning of the particles, in the sense that
it will have a stronger influence on the motion of nearby particles than on
the motion of those farther away. Another example is the interaction force
created by defining a windy region on the simulated environment. Particles
located on the windy region or passing through it will have to take the
3.3 Interaction Forces 69

wind force into account when computing their net external force, whereas
particles that are not in the windy region can ignore that force.
The spatially dependent forces are the most expensive interaction forces
considered in particle-system simulations. Approximation methods are gen-
erally used to truncate the influence of the force field on particles that are
more than one threshold value distant. This truncation technique is dis-
cussed in detail in Section 3.3.4.

3.3.1 Gravity
The force contribution of the gravitational force acting on each particle
owing to its attraction to the ground (Le., Earth) is directly obtained as

F=mg,
where g is the gravity acceleration and m is the mass of the particle (see
Figure 3.4). The gravity acceleration is in most cases assumed to have
constant magnitude and direction pointing downwards (Le., towards the
ground).

___ p.
~
~- -""'"
m,.g

FIGURE 3.4. Gravity pulling particle H with mass ml towards the ground plane.

3.3.2 Viscous Drag


The most common use of viscous drag in dynamic simulations of particle
systems is to model the air resistance to the particle's movement. The goal
is to ensure that particles will eventually come to a rest if there are no
other external forces acting on them. Figure 3.5 illustrates this. The force
component of the viscous drag is computed as

where v is the velocity vector of the particle and kd is the coefficient of


drag.
70 3. Particle Systems

)i?f
l
__

...... --~
_
-
Vt

F; =-kA

~ --
--_..... F: -
_
V3
3 -kd v3

FIGURE 3.5. A set of particles Pi moving in random directions and experiencing


air resitance modeled as viscous drag F;,.

Besides preventing particles from gaining excessive speeds that may in-
troduce instabilities into the numerical-integration method being used, vis-
cous drag can also be used to control the rate at which particles accelerate.
For example, a particle system simulating smoke may use a coefficient of
drag much greater than that used in a particle system simulating rain. This
in turn has the effect of making the smoke particles slowly rise and spread
over nearby regions, whereas the rain drops will be allowed to fall at a
reasonable speed.

3.3.3 Damped Springs


Springs are mostly used to keep the distance between pairs of particles at a
known value. Whenever the particles are pushed apart or pulled together,
a spring force is applied to both particles with the same magnitude but
opposing direction.
Let PI and P 2 be two particles connected by a spring of resting length
roo Let rl, ih, r2 and V2 be the linear position and velocity of particles PI
and P2 , respectively. The spring-force component acting on both particles
is then obtained from

(r2 - rl)
Ir2 - rll
(3.6)
PI -P2 ,
with Pi being the spring force acting on particle Pi for i E {1,2}, ks being
the spring constant and kd being the damping constant (see Figure 3.6).
The damping term of equation (3.6) is used to prevent oscillation, and does
not affect the motion of the center of mass of the connected particles.
3.3 Interaction Forces 71

The spring system can be under, over or critically damped, depending


on the value of kd being used. Oscillations occur only when the system is
under damped. The interested reader is referred to Section 3.10 for pointers
to the literature wherein techniques to compute the value of kd for under,
over and critically damped spring systems can be found.

(a)

(b)

FIGURE 3.6. Particles PI and P2 are connected by a damped spring. (a) Particles
at resting position; (b) Spring forces exerted on the particles when they are pulled
away from each other.

3.3.4 Spatially Dependent Forces


There are two types of spatially dependent forces considered in this book.
The first type, referred to as constrained force field, deals with force fields
defined over a region of the simulated environment. Such forces interact
only with particles located within their region of influence. The second
type, referred to as unconstrained force field, deals with interaction forces
between all particles, which depend on the particles' relative positioning.

Constrained Force Fields


Constrained force fields are defined by their region of influence, force field
strength and the drop rate. The region of influence, as its name implies,
defines a region of the simulated world to which the force field is con-
strained. The boundary of the region of influence can be described by a
polyhedron in the simulated environment (see Figure 3.7). Particles that
are located inside the polyhedron have their trajectories affected by the
72 3. Particle Systems

force-field strength. For efficiency reasons, the region of influence should


be represented as a simple polyhedron such as a box or sphere, so that
particle-inclusion tests can be efficiently implemented using the algorithms
presented in Section 2.4.

FIGURE 3.7. A windy region defined as a box in the simulated environment.


Particles that lie outside the box are not affected by the wind, whereas those
inside the box have their net-force vector Fn adjusted to Fr, as the result of
taking into account the wind force Fi given by equation (3.7).

The force-field strength is defined at the center of the region of influence.


As we move away from the center, the strength of the force field is reduced
according to its distance to the center. Therefore, particles closer to the
center of the region of influence are more affected by the force field than
those near the boundary of the region of influence. This is used to provide a
smooth transition (i.e., avoid discontinuities) on the dynamics for particles
entering and leaving the region of influence.
The drop rate is computed as follows. If the region of influence is a sphere,
then the force-field strength at a point Pi inside the sphere is

where R is the radius of the sphere, fi is the distance vector from point
Pi to the center of the sphere c, and Fe is the force-field strength at c (see
Figure 3.8(a)). When the region of influence is a box centered at c with
dimensions B = (b x , by, bz ), the field strength at a point Pi inside the box
is given by

(1- 1(~~x I) (Fe)x


(1- 1(~i~y I) (Fe)y (3.7)
3.3 Interaction Forces 73

with fi being the distance vector from point Pi to the center of the box.
This situation is illustrated in Figure 3.8{b).

~l --~~~- - -
Y12.~~
z
FIGURE 3.8. Taking the drop rate into account when computing the force-field
strength at a point Pi inside the region of influence defined by: (a) a sphere; (b)
a box.

At a preprocessing stage, the region of influence of each constrained force


field is intersected with the cell decomposition of the simulated world. By
so doing, the simulation engine will know which cells are completely inside,
partially covered, or outside the region of influence. This greatly speeds
run-time particle-inclusion tests, since such tests are only necessary for
particles associated with cells that are partially covered by the region of
influence.

Unconstrained Force Fields


Unconstrained force fields are used to specify long-range force interactions
between all particles in the system. Each particle influences all others in
the system, which in most cases depend on their relative displacement. The
farther the particles are apart, the weaker the force interaction affecting
their motion. Examples of such force fields include:
• The gravitational potential between two particles P 1 and P2 , com-
puted as

G ml m2 (f'l - 1'2)
1Tl - T212 1Tl - 1'21
-Fl'
where ml, Tl, m2 and f2 are the mass and position of particles P1 and
P2 , respectively, and G = 6.672 X 10- 11 Nm 2 kg- 2 is the universal
gravitational constant.
74 3. Particle Systems

• The Lennard-Jones potential, commonly used for computing non-


bounding potentials in molecular-dynamics simulators, and given by

• The Coulomb potential, which is the equivalent of the gravitational


potential when the particles have electrical charges

K ql q2 WI - f2)
ITI - r21 2 1rl - r21
-fA,

with ql and q2 being the electrical charges of the particles, and K the
Coulomb constant equal to 8.9875 x 109 Nm 2 C- 2 . In this case, the
particles can either repel or attract each other, depending on whether
their electrical charges are of the same or opposite signs.

Clearly, the computation of unconstrained forces for a particle system


containing n particles has a O(n 2 ) computation time complexity, which
makes it impractical for interactive simulations, even for a moderate num-
ber of particles (Le., n;:::: 1000.) Fortunately, there is a workaround to this
limitation that reduces the computational complexity to O(n). It is based
on truncating the computation of the interaction forces to particles that
are within a cut-off distance from the particle being considered. This can
be efficiently implemented if we use the underlying cell subdivision of the
simulated world.
As explained in Section 3.2, the simulation engine dynamically assigns
particles to the cells in which they are included. Each particle will then
interact with other particles in that same cell, and those in neighboring cells
that are within a cut-off distance from the cell that contains the particle.
Figure 3.9 shows how the neighboring cells are determined for a 2D cell
decomposition.
The actual number of neighboring cells to be used depends on the size of
each cell and the cut-off distance. Let s be the dimension of each cell along
each axis of the world-coordinate frame 1 , and let Se be the desired cut-
off distance. Assume we are computing the force interactions for particles
contained in cell C = (c x , cy, cz ). Now, imagine a cut-off box with its center
coincident with the center of cell C, and with sides of length equal to the
cut-off distance. This situation is illustrated in Figure 3.10.
3.3 Interaction Forces 75

0 o C
0
0 L °
r---..,0

[7 0
"'\ °
I
Sc
°0 :\
0 0
o 0
0 C
°
\ 0
0
:;
0 ~ ~ 0

............. .-/

° 0

FIGURE 3.9. Particles in cell C will only interact with other particles in C and
in neighboring cells that are within the cut-off distance Be from C.

Cy

-l f J
x
Cy

FIGURE 3.10. The computation of the force interactions for particles in cell
C = (cx,cy,c z ) is limited to the cells with indexes within l~J from it.
76 3. Particle Systems

The cut-off box will therefore intersect

p = rs; 1with p E 1N

cells of the subdivision. The particles in C = (ex, cY ' cz ) will then interact
with the particles assigned to cells C = (i,j, k) satisfying

o <
o <

o <

where Cn is the maximum cell-index value, as discussed in Section 2.3.

3.3.5 User Interaction


The user-interaction force is modeled as a damped spring connecting the
current mouse position to the position of the particle being dragged. The
goal of using this fictitious spring is to avoid the introduction of unre-
alistically large external forces acting on the selected particle because of
abrupt mouse movements. These large external forces can make the dy-
namic equations describing the motion of the particle stiff. Stiff systems
are more sensible to round-off errors and usually require the use of more
elaborated and time-consuming numerical-integration methods, such as the
implicit Euler method described in Appendix B.
The main difference between the damped spring described in Section
3.3.3 and the fictitious spring used here is that the resting length of the
fictitious spring should be zero. A zero resting length means that the se-
lected particle will only stabilize its motion when its position is coincident
with the mouse position. Therefore, as the user drags the particle around,
the current mouse position is used to update the actual distance between
the particle and the mouse. This distance is then used in equation (3.6) to
compute the appropriate spring force to be applied.

3.4 Collision Detection: Overview


Even though particles are modeled as point-mass objects, they are usually
represented by simple geometric shapes such as cubes or spheres that can

1 Recall from Section 2.3 that the cell decomposition defines a uniform subdivision of
the simulated world.
3.4 Collision Detection: Overview 77

be rendered in large numbers without affecting too much the overall per-
formance of the rendering engine. The particle's shape can then be used
to detect collisions between particles and other objects in the simulated
environment.
We say the particle system has internal collisions whenever the collisions
between its particles are taken into account. The particle system will have
external collisions if the collisions between its particles and other particles
defined by other particle systems are also taken into account. Collisions
between rigid bodies and particles will be referred to as complex collisions.
In this book, we focus on particle systems that can have internal, ex-
ternal and complex collisions. Also, we assume all particles in the system
have a spherical shape, possibly -with different radii. The main reason for
this assumption is efficiency. Since particles are point-mass objects, their
trajectories between two consecutive time steps define a straight line seg-
ment. When their shape is taken into account, their trajectories will span
a volume in 3D space. If we limit our system to one having only spherical
particles, the volume spanned by the motion of each particle can be de-
scribed as a cylinder with a spherical cap (see Figure 3.11). In this context,
collision detection between particles and other objects in the simulated
environment can be determined using quick and efficient intersection tests.

Direction
~--------~
I \ I \ of motion

~--------~
Initial position Final position

--
+ r:)\
~------------7'"
I \ I \
I • ~ I • ~
\ -..L.I ____________\ JJ..II \])
Cylinder Spherical Cap

FIGURE 3.11. The trajectory of spherical particles can be described by concate-


nating simple geometric structures such as a cylinder and a sphere.

The relative displacement of the colliding particles or rigid bodies is


used to determine the collision normal and tangent plane at the collision
point. The actual computation of the collision normal is slightly different
depending on whether we are considering particle-particle or particle-rigid
body collisions. This is explained in detail in the following sections. The
computation of the tangent plane, on the other hand, is done after the
collision normal is determined, and depends strictly on it. Section A.6 of
Appendix A presents a thorough derivation of how the tangent plane is
78 3. Particle Systems

obtained given the collision-normal vector ii. Henceforth, we shall take for
granted the computation of vectors Fand k that, together with vector ii,
form the local frame used to compute the collision and contact forces.

3.4,1 Particle-Particle Collision


The collision detection between particles is usually undertaken by checking
whether the particles' trajectories intersect. Because the trajectory of each
particle is represented by a cylinder with a spherical cap, the collision-
detection check consists of checking for cylinder-cylinder, cylinder-sphere
and sphere-sphere intersections. The cylinder-cylinder and cylinder-sphere
intersection tests are presented in Sections 3.5.1 and 3.5.3, respectively.
The sphere-sphere intersection test was already presented in Chapter 2, in
the context of interference detection between hierarchical representations
of rigid-body systems.
Unfortunately, transforming the collision-detection problem into an in-
tersection problem does not always give us the correct result. Consider the
situation illustrated in Figure 3.12. Clearly, the trajectories of particles PI
and P2 do intersect at position I. However, if we take time into account, we
quickly conclude that the particles do not collide because the time instant
associated with each particle when their trajectories overlap is different. In
other words, when particle P2 is at position I, particle PI is still at posi-
tion A. By the time particle PI reaches position I, particle P2 is already
at position B. Therefore, even though their trajectories intersect, they do
not really collide.
One way to overcome this problem is to use the geometrical intersection
of the trajectories as a reference point to check whether the particles really
collide. This is best illustrated using the example shown in Figure 3.12. In
this example, we already know that the trajectories of particles PI and P2
intersect at position I. We want to determine the time instant before the
intersection happened, that is, just before the particles collide. The idea is
then to trace back in time until either both particles are positioned at the
moment just before their collision, or their time instants associated with
the intersection point I are different and collision is no longer an issue.
The trace back in time can be efficiently implemented using a root-finding
algorithm such as the bisection method. The bisection method works by
moving each particle half way through the current time interval. A sphere-
sphere intersection test is then carried out to determine whether the par-
ticles intersect at the middle point. If the particles intersect at the middle
point, then the current time interval is substituted for its first half (Le.,
from the start to middle points) or its second half (Le., from the middle
to end points), depending on the intersection point I being located in the
first or second halves, respectively.
If the particles do not intersect at the middle point, then their position
at the middle point is compared with the position of the intersection point
3.4 Collision Detection: Overview 79

FIGURE 3.12. The geometric intersection of the particle's trajectories may be


associated with different simulation times for each particle.

I to help figure out which half should be used to replace the current time
interval. Figures 3.13 and 3.14 show the two possible outcomes of this
comparison.
In Figure 3.13, the intersection point I is located in the first half of the
time interval for particle P2 , but on the second half for particle Pl. In
this case, the location of the intersection point I in the trajectory of each
particle is associated with different halves of the time interval, that is, the
time instant associated with each particle when their trajectories overlap
is different. Therefore, they do not collide. In Figure 3.14, the intersection
point I is located on the same half of the time interval for both particles.
In this case, the current time interval is substituted for the half in which
the intersection point I is located.
The current time interval is then recursively subdivided into half parts
using the bisection method until either the collision is dismissed as an
intersection at different time instants, or the current time interval is shrunk
to less than a threshold value. In the latter case, the particles will be
intersecting at one end of the time interval, and will not be intersecting
at the other end. The collision time (Le., the instant before the collision)
is approximated by the end of the time interval in which the particles are
not colliding.
The particles' geometric displacement at the collision time is used to
compute the collision normal as the unit vector connecting the center of
the spheres representing the particles. The direction of the collision normal
is chosen such that the relative velocity of the particles along the collision
80 3. Particle Systems

FIGURE 3.13. Applying the bisection method to determine the collision between
particles that have their trajectories intersecting. Case in which the intersection
point I is assigned to different time intervals of the bisection. The particles do
not collide.

t = to +h

FIGURE 3.14. Case in which the intersection point I is assigned to the same
time interval of the bisection. Additional time subdivision is required.
3.4 Collision Detection: Overview 81

normal is negative, indicating that the particles are moving towards each
other.

3.4.2 Particle-Rigid Body Collision


The collision detection between particles and rigid bodies is more compli-
cated than that involving only particles, owing to the use of hierarchical
representations for rigid bodies, as discussed in Chapter 2. Here, we have to
check first for particle-hierarchical tree collisions, and if we end up reaching
some leaves of the hierarchical tree during the collision test, we still need
to carry out particle-primitive collision checks for the primitives associated
with each leaf.
Since in this book we are only considering hierarchical representations
using either boxes or spheres, the particle-hierarchical tree collision checks
are transformed into a series of intersection tests between the particle's
trajectory and the elements of the hierarchical tree. If the hierarchical tree
representation uses boxes (i.e., AABB or OBB tree), then the intersection
tests are limited to a sequence of cylinder-box and sphere-box tests. How-
ever, if the hierarchical tree representation uses spheres (Le., BS tree), then
the intersection tests involve cylinder-sphere and sphere-sphere tests only.
Also, since the primitives considered in this book are only triangles, the
particle-primitive collision checks are transformed to a series of cylinder-
triangle and sphere-triangle intersection tests.
Some of the above intersection tests have already been presented in Chap-
ter 2, when checking for collisions between different hierarchical tree rep-
resentations of rigid bodies. More specifically, we have covered sphere-box
in Section 2.4.5, sphere-sphere in Section 2.4.2 and sphere-triangle in Sec-
tion 2.4.7. The remaining intersection tests involving cylinders are discussed
in Sections 3.5.1 to 3.5.4 of this chapter.
The collision detection between a particle and a rigid body is simplified
by ignoring the rigid body's trajectory during the current simulation time
step, and carrying out the collision checks only with the rigid body already
positioned at the end of the current time step (see Section 4.4 of Chap-
ter 4 for more on rigid body collisions). By so doing, the problem we had
when checking for particle-particle collisions with particles that had their
trajectories overlapping at different time instants is no longer relevant.
As is the case with most simplifications, there are situations in which
the collision detection misses some particle-rigid body collisions using this
scheme. However, let's focus first on the cases when the simplification
works, and later discuss its drawbacks.
A particle is assumed to collide with a rigid body whenever its trajec-
tory intersects one or more triangle primitives of the rigid body. When an
intersection is first detected, the collision-detection module keeps a pointer
to the triangle primitive of the rigid body corresponding to the intersection
point closest to the particle's initial position (see Figure 3.15).
82 3. Particle Systems

Final
position

FIGURE 3.15. The particle's trajectory intersects several triangle primitives of a


rigid body. The triangle with the closest intersection point to the initial position
of the particle is selected as the intersecting triangle. As shown, the intersection
point h is closer to HI than h and 13. Therefore, triangle TI is selected as the
intersecting triangle.

The particle is then traced back in time to the moment just before the
collision, using the bisection method to recursively subdivide the time in-
terval into halves. Notice that for the particle-rigid body collision detection
there is no need to keep intersecting the particle's trajectory with the rigid
body's hierarchical representation at each intermediate step of the bisec-
tion method because the rigid body is considered to be "fixed" at the end
of the current simulation time step (its trajectory is ignored). Moreover,
we already know the triangle primitive that will first come in contact with
the particle. Therefore, at each intermediate step of the bisection method,
we need only check for intersection between the closest triangle and the
particle's trajectory. This process continues until the current time interval
is shrunk to less than a threshold value. At this point, the particle will
be intersecting the triangle at one end of the time interval, and will not
be intersecting the triangle at the other end. The collision time (Le., time
just before the collision) is approximated by the end of the time interval
in which the particle does not intersect the triangle. The collision point is
assumed to be the center of the sphere representing the particle, and the
collision normal can be either a vertex normal, an edge normal or a face
normal depending on the particle being closer to a vertex, an edge or a
point in the interior of the triangle.
The reaction on the rigid body's motion owing to the impulsive or contact
forces of the particles colliding with it will only be applied to the rigid body
on the subsequent simulation time step. In other words, even though the
rigid body is modeled as a "fixed" object for the current time step, the
forces and impulses exerted by particles colliding with it are accumulated
as an external force and impulse that will affect the rigid body's motion the
next time its dynamic equations are integrated. For instance, consider the
3.4 Collision Detection: Overview 83

situation shown in Figure 3.16, where several particles are moving toward
a box at rest.

Time step tk Time step tk

(a) (b)
Position at
time step
Time step tk
tk +h

(c) (d)
FIGURE 3.16. (a) Several particles hitting a box at rest at time t = tk; (b)
The particles' trajectories are updated according to the impulsive forces owing
to the collision; (c) The reaction forces owing to the particles' collisions are sub-
stituted for a net force-torque pair acting on the box's center of mass; (d) The net
force-torque pair is then used in the subsequent simulation time step t = (tk + h)
to update the position and orientation of the box.

The collision-detection module will check for geometric intersections be-


tween the particles' trajectories and the box (see Figure 3.16(a)). The
collision-response module is then activated to resolve any detected colli-
sions (more details in Section 3.7). The colliding particles have their trajec-
tories updated according to the impulsive forces computed by the collisioIl-
response module, so as to prevent interpenetration with the box, as well as
other particles during their movement (see Figure 3.16(b)). The reaction
impulsive force to the collision of each particle is summed and saved as an
external impulsive force-torque pair acting on the box (see Figure 3.16(c)).
This external impulsive force-torque pair will then be used to update the
box's motion during the next simulation time step (see Figure 3.16(d)).
As mentioned before, there are a couple of drawbacks to ignoring the rigid
body's trajectory when checking for particle-rigid body collisions. First of
all, collisions that occur at the beginning of the current simulation time
step have a higher probability of being missed than collisions that occur
near the end of the time step. This owes to the fact that the rigid body
is positioned at the end of the current time step before any particle-rigid
body collisions are checked. Of course, we could reduce the simulation time
step to catch these collision misses, but this would considerably slow the
84 3. Particle Systems

simulation, defeating the purpose of using the simplification in the first


place.
Secondly, it is possible to have situations in which, even though the par-
ticle's trajectory does not intersect the rigid body's triangular faces, it is
completely inside the rigid body (see Figure 3.17). This is a difficult prob-
lem to deal with because using standard point-in-polygon tests for checking
whether the extreme points of the line defining the particle's trajectory are
included in the rigid body's shape can be very time consuming, especially
if we don't have a convex decomposition of the rigid body at hand.

t = tt tt <1«lt +h) I - It +h

r:'=::l11J f~---:::'-:;11illJ
L1J (a)
0 f----{'
I
I
I I
,...
... J
I I
L. ___ J./

(b)
I
I
I I
I I
L. ___ J./

(c)
...

FIGURE 3.17. (a) Rigid body and particle positioned at the beginning of the
current simulation time step; (b) Rigid body collides with particle somewhere
before the end of the current time step; (c) Rigid body and particle positioned
at the end of the current time step. Since the rigid body's trajectory is ignored,
no intersections with the rigid body's triangle primitives are detected. The rigid
body and particle are assumed to be not colliding, even though the particle's
trajectory is completely contained inside the rigid body.

Another way to deal with this problem is to carry out an additional test
using the partial intersection information obtained after the rigid body's
hierarchical representation is checked for intersection against the particle's
trajectory. The fact that the particle's trajectory does not intersect the
rigid body means that the intersection between the trajectory and its hier-
archical representation is empty at some intermediate level of the hierarchy.
This level can be the top-most level containing the parent node, in which
case the intersection test is quickly dismissed, or any other intermediate
level including the leaf nodes. The extra test then consists of checking for
sidedness of the extreme points of the particle's trajectory with respect to
the triangle primitives associated with the intermediate node at which the
intersection was dismissed. If both extreme points are on the negative side
(Le., inside) of all planes defined by the triangular faces, then the trajec-
tory is completely inside the rigid body. If both extreme points are on the
positive side (Le., outside) of all planes defined by the triangular faces, then
the trajectory is completely outside the rigid body. The case in which one
point is inside and the other is outside cannot occur at this stage because
the trajectory is known not to be intersecting the rigid body.
3.4 Collision Detection: Overview 85

Even though this extra test would detect the cases in which the particle's
trajectory is completely inside the rigid body, it can significantly affect the
overall program efficiency. For example, when the intersection is dismissed
at the parent node, the extreme points of the trajectory would have to
be tested for sidedness against all triangle faces defining the rigid body.
Clearly, this is impractical in simulations involving several hundred or more
particles.
In this book, we suggest the following approach to efficiently carry out
this additional test. Our approach consists of enhancing the AABB and
OBB hierarchical representations with some extra information about the
relative location of the vertices of their intermediate nodes (Le., boxes)
with respect to the interior and exterior of the rigid body2. This is done
by testing the relative location of each vertex of the intermediate box B j
with respect to the triangle primitives T! associated with it. Recall that
the triangle normals fiTj are always pointing outwards, that is, towards the
v
exterior of the rigid body. So, vertex E B j lies outside the rigid body if
and only if

v· fiT! > 0, \:IT! associated with B j .

Conversely, vertex v E Bj lies inside the rigid body if and only if

v· fiT; < 0, \:IT! associated with B j .

We also keep track of the closest triangle face to each vertex of the
intermediate boxes. The idea is then to use this inside-outside information
of each vertex to classify the six faces of box B j as pointing to the interior
(if all of its vertices are in the interior), exterior (if all of its vertices are in
the exterior) or undefined (if some vertices are in the interior and others in
the exterior). On a first pass, the extreme points of the particle's trajectory
are initially assigned the same label of the faces of the box closest to them.
If both extreme points are labeled exterior, then the particle's trajectory
lies outside the rigid body and no collisions are reported. However, if one
or both are labeled undefined, then we use the closest triangle face to each
vertex of the box (adding up to four triangle faces) to improve the sidedness
test. If both extreme points are labeled exterior on this second pass, then
no collisions are reported. Otherwise, the particle's trajectory is assumed
to be inside the rigid body.
Ideally, once the additional test indicates that the particle's trajectory
is included in the rigid body, we have to trace back in time both particle
and rigid body to the moment before their collision. Unfortunately, this
would have the cascade effect of requiring recomputation of all collisions
between the rigid body and other particles, since those computed to that

2This technique does not apply for Bounding Sphere representations.


86 3. Particle Systems

time considered the rigid body positioned (Le., "fixed") at the end of the
current simulation time step, and not at some intermediate position. In
our view, the best way to cope with this tracing problem is to remove the
particle from the simulation. This has no side effects with respect to all
other collisions already processed, it is easy and fast to implement, it does
not affect the efficacy of the simulation, and may even pass unnoticed if
there is a large number of particles nearby the one being removed.
Lastly, the third drawback to using the above-mentioned simplification
is that all rigid body-rigid body collisions must be processed before any
particle-particle and particle-rigid body collisions. This is necessary because
rigid body-rigid body collisions require that the colliding rigid bodies be
traced back in time to the moment just before their collision. Moreover, the
impulses and contact forces are immediately applied and· their trajectories
are updated through the remaining period of time. So, if we compute all
particle-particle and particle-rigid body collisions before the rigid body-
rigid body collisions are dealt with, there is a chance that some rigid bodies
will have their positions at the end of the current time step modified because
of some collisions with other rigid bodies. This would require recomputation
of all particle-rigid body collisions and particle-particle collisions involving
the particles that collided with those rigid bodies that had their trajectories
modified by the rigid body-rigid body collisions.

3.5 Collision-Detection Implementation


In this section we shall address all intersection tests necessary to implement
the collision detection between particles and rigid-bodies, as explained in
Section 3.4. We use the following notation to describe these intersection
tests.
The particle's trajectory will be represented by a cylinder H and a sphere
S. The sphere S is given by its center cand radius T e , whereas the cylinder
H is given by its radius rh and two points hI and h2 defining the direction
ih of its axis. The vector Uh can be directly obtained from hI and h2 as

The top and bottom limiting planes of the cylinder are perpendicular to
Uh, passing through points h2 and hb respectively. Their equations are

ji. Uh 1'2 (top plane)


(3.8)
ji. Uh 1'1 (bottom plane)
3.5 Collision-Detection Implementation 87

for any point p in the planes, with

"Y2 h2 . ih
"Yl hI . i1h
being the top and bottom plane constants, respectively.
The rigid-body primitive is represented by a triangle T defined by its
vertices ih, 712 and 713 , The triangle normal is computed as 3

Let Pt be the plane containing the triangle. Any point p E Pt satisfies

where fit is the plane normal (i.e., the triangle normal.) and "Yt is the plane
constant given by

"Yt = VI . fit .

A box representing an intermediate node of an AABB or OBB hierar-


chical tree representation of rigid bodies is defined by its two diagonally
opposing extreme points bmin and bmax .

3.5.1 Computing Cylinder- Cylinder Intersections


The cylinder-cylinder intersection test is primarily used when checking for
collisions between the trajectories of two particles. Here, we shall present
an intersection test that is custom-tailored for cylinders representing parti-
cles' trajectories. Recall that the trajectory is defined by a cylinder with a
spherical-cap. Therefore, the most complicated cases that need to be con-
sidered in a general cylinder-cylinder intersection test can be avoided. More
specifically, the intersection tests between one cylinder and the top or bot-
tom regions of the other cylinder are left unresolved until the cylinder is
checked for intersection with the spherical-cap of the other cylinder. The
existence of any intersection with the top or bottom regions of the cylinder
will necessarily imply the existence of an intersection between their asso-
ciated spherical-cap and the cylinder (see Figure 3.18), meaning all such
intersections will be detected by the cylinder-sphere intersection test dis-
cussed in Section 3.5.3. Here, we shall focus on checking for intersections
between the cylinders' cap.

3The simulation engine presented in this book uses the right-hand coordinate system
for its internal representation. Therefore, outward normals are computed from the vertex
list given in a counterclockwise order.
88 3. Particle Systems

Let Hand M represent the two cylinders being checked for intersection.
The first step is to carry out some quick rejection tests for M.lfthe extreme
points of cylinder M's axis lie above or below the top or bottom limiting
planes of cylinder H, that is, if

(rrh . Uh - 1'2) > 0


(m2 . Uh - 1'2) > 0
or

(m1' Uh -1'1) < 0


(m2 . Uh - 1'1) < 0
then any cylinder-cylinder intersection will be detected by the cylinder-
sphere intersection test, and the cylinders are reported as non-intersecting.
Also, if the cylinder M's axis intersects the top limiting plane of cylinder
H, that is, if

(m1 . Uh - 1'2) > 0


(m2 . Uh - 1'2) < 0
or

(mI' Uh - 1'2) <0


(m2 . Uh - 1'2) > 0
then any cylinder-cylinder intersection will contain a region on the top
limiting plane, thus it can be detected by the cylinder-sphere intersection
test. Again, the cylinder-cylinder intersection test returns false, indicating
the cylinders do not intersect. If the above tests fail, then we conduct them
again, but for H instead of M. If all rejection tests failed, then the axis of
each cylinder is positioned between the limiting planes of the other. The
intersection test for this situation can be efficiently carried out as follows.
Consider the line segment defined by cylinder M's axis. Let cm be the
closest point of this line segment to the line supporting cylinder H's axis, as
shown in Figure 3.19. The determination of the closest point between a line
segment and an infinite line is explained in detail in Section A.5. Notice,
however, that according to Section A.5 2m can be either a point inside
the line segment, or one of its extreme points (i.e., m1 or m2), depending
whether the actual closest point lies inside or outside the line segment.
Therefore, cm is guaranteed to lie inside the line segment defining cylinder
M's axis.
3.5 Collision-Detection Implementation 89

I
H I
I
I
I Intersection
I region

. . -_--1--_
I
~ t -,

FIGURE 3.18. Cylinder H represents a particle's trajectory from hI to h2 • Any


intersection with the top region of the cylinder (associated with the final trajec-
tory point h2) will be detected by the time we check for intersections with the
spherical cap.

FIGURE 3.19. The cylinder-cylinder intersection test is conducted by comparing


the distance d between the closest points em and c" of their axes with the sum
(rm + rh) of the their radii.
90 3. Particle Systems

Let Ch be the corresponding point to cm, located on the supporting line


of cylinder H's axis (see Figure 3.19). The distance d between Cm and Ch
is then

(3.9)
Clearly, the cylinders will not intersect if

(3.10)
that is, if the distance between the closest points of the cylinders' axes is
greater than the sum of their radii. If equation (3.10) is not satisfied, then
the cylinders will intersect only if Ch lies within the line segment defined
by cylinder H's axis. However, if c,. lies outside cylinder H's axis, then
we need to test whether the distance between cm and the extreme point
of cylinder H's axis that is closest to Ch is still less than the sum of the
cylinders' radii. In other words, we need to compute

d1 = Ch - h11
1

d2 = 1 c,. - h2 1

and select Ch = h1 if d 1 < d2, or Ch = h2 otherwise. Then, we need


to substitute the new value of Ch into equation (3.9), and check whether
equation (3.10) is still satisfied. If this is the case, then the cylinders do not
intersect. Otherwise, the cylinders do intersect and the intersection point
is approximated by their closest points, that is, Cm for cylinder M and Ch
for cylinder H.

3.5.2 Computing Cylinder-Box Intersections


The cylinder-box intersection test is used to detect collisions between par-
ticles' trajectories and AABB or OBB hierarchical tree representations.
Initially, we conduct a quick rejection test to check whether the box lies
completely above or below the top and bottom limiting planes of the cylin-
der, respectively. The box will lie above the top limiting plane if

(bmin . Uh - 1'2) >0 (3.11)


and below the bottom limiting plane if

(3.12)
If either equation (3.11) or (3.12) is satisfied, then the box does not
intersect the cylinder. Otherwise, we need to conduct the following test for
each face of the box.
3.5 Collision-Detection Implementation 91

Let Ii be a face of the box defined by vertices ih, V2, V3 and V4' Also, let
Vmin and vmax define the extreme points of face Ii, given by

(Vmin)x min«Vl)x, (V2)x, (V3)x, (V4)x)


(Vmin)y min«Vl)y, (V2)y, (V3)y, (V4)y)
(Vmin)z = min«vdz, (V2)z, (V3)z, (V4)z)
(Vmax)x max«Vl)x, (V2)x, (V3)x, (V4)x)
(Vmax)y max«Vl)y, (V2)y, (V3)y, (V4)Y)
(Vmax)z max«vdz, (V2)z, (V3)z, (V4)z) .

We have two possible cases to consider depending on whether the cylin-


der's axis is perpendicular to the plane containing Ii- Let ni be the outward
normal of Ii (Le., normal pointing from the inside to the outside of the box).
The cylinder's axis will be perpendicular to Ii if

(3.13)
is satisfied.

Case 1:
If the axis is perpendicular to the plane, we proceed by checking whether
the cylinder's axis intersects the plane containing Ii- This line-segment-
with-plane intersection test is discussed in Section A.4 of Appendix A.
Let g be the intersection point between the infinite line supporting the
cylinder's axis and the plane. If g lies outside the end points defining the
cylinder's axis (see Figure 3.20), then the cylinder does not intersect the
box. However, if 9 lies inside the axis, then a point-in-rectangle test is
conducted to see whether g is actually inside Fi (see Figure 3.21), that is,
whether the cylinder and the box do intersect. Otherwise, the cylinder-box
intersection test returns false, meaning the cylinder does not intersect the
box.
The intersection point g will lie inside the rectangular face Ii whenever

(Vmin)x ~ gx ~ (vmax)x
(Vmin)y ~ gy ~ (vmax)y
(Vmin)z ~ gz ~ (vmax)z

Case 2:
If equation (3.13) is not satisfied, then the cylinder's axis is not perpen-
dicular to the plane containing face Ii. In this case, we need to construct
an auxiliary plane Pt to help us determine the closest and farthest points
92 3. Particle Systems

FIGURE 3.20. The intersection point g lies outside the cylinder's axis. Therefore,
the cylinder does not intersect face k

FIGURE 3.21. The intersection point g lies inside the cylinder's axis and a
point-in-rectangle test is carried out to determine whether g lies inside or outside
facek
3.5 Collision-Detection Implementation 93

of the cylinder to the plane that contains face Ii- Consider the situation
illustrated in Figure 3.22.

FIGURE 3.22. The auxiliary plane Pi is used to determine the closest and farthest
points of the cylinder to the plane containing Fi.

The auxiliary plane Pi is defined as the plane perpendicular to Ii which


also contains the cylinder's axis. Its normal vector fia is obtained from

Clearly, since the plane P;, contains the cylinder's axis, its intersection
with the cylinder defines a rectangular region R i . We need to determine
the vertices defining R i . In order to do so, consider the auxiliary vector
fib E Pi given by

where kb E IR is a scalar variable that defines the length of vector fib.


Notice that, by construction, fib is a vector parallel to the top and bottom
limiting planes of the cylinder. The vertices of Ri can then be obtained by
adding and subtracting fib from the cylinder's axis, with kb chosen as

Thus, the rectangular region Ri is defined by vertices (hI -fib), (h2 -fib),
(h2 + fib) and (hI + fib) (see Figure 3.22). The cylinder intersects face Ii
if and only if Ii intersects R i . Notice that the closest and farthest points
of Ri to the plane containing Ii are Pc = (hI - fib) and PI = (h2 + fib),
respectively. So, face Ii intersects Ri if and only if it intersects the line
94 3. Particle Systems

segment defined by (Pc, 'PI)' This test is analogous to the intersection test
between the cylinder's axis and face Fi when they are perpendicular.
In summary, we decompose the cylinder-box intersection test into six
cylinder-rectangle tests. Each of them is implemented as a plane-line seg-
ment intersection test, thoroughly explained in Section A.4.

3.5.3 Computing Cylinder-Sphere Intersections


The cylinder-sphere intersection test is used to detect particle-particle col-
lisions, as well as intersections between particles' trajectories and Bounding
Sphere hierarchical tree representations. This test can be efficiently imple-
mented if we consider the relative displacement of the center of the sphere
with respect to the top and bottom planes limiting the cylinder. One of
the following cases occurs:

1. The sphere is completely above the top plane;

2. The sphere intersects the top plane, but its center is above it;
3. The sphere intersects the top plane, but its center is on or below it;
4. The sphere is completely between the top and bottom planes;
5. The sphere intersects the bottom plane, but its center is on or above
it;
6. The sphere intersects the bottom plane, but its center is below it;
7. The sphere is completely below the top plane.

Let's start by examining the cases in which the sphere intersects either
the top or bottom limiting planes of the cylinder. Figures 3.23 and 3.24
show the situation for cases 2 and 3 of the above list. The analysis of this
situation is also applicable to cases 5 and 6.
Let Cl and C2 be the projection of the center of the sphere on the top
plane and on the cylinder axis, respectively4. Clearly, the cylinder intersects
the sphere if and only if

(3.14)
where x and L are variables to be determined from the relative displacement
of the cylinder and the sphere. Consider the triangle defined by vertices C,
C2 and h1 • Applying the Pythagorean theorem, we immediately obtain L
as

(3.15)

4See Appendix A for details on how to compute these projections.


3.5 Collision-Detection Implementation 95

I
I
I
I
I
I
I
I

_---1---_
I

- ~t '

FIGURE 3.23. The sphere intersects the top plane, with the center of the sphere
being above the plane. A similar figure can be drawn to depict the sphere's
intersecting the bottom plane.

I
I
,.... .,,-/
,----

FIGURE 3.24. The sphere intersects the top plane, with the center of the sphere
being below the plane. A similar figure can be drawn to depict the sphere's
intersecting the bottom plane.
96 3. Particle Systems

where the vector (C2 - hI) can be efficiently computed by projecting the
vector (c - hI) onto the cylinder axis, that is

(3.16)
If the center of the sphere is on or below the top plane, then we imme-
diately have (see Figure 3.24)

x = rc. (3.17)
Otherwise, the variable x = Iii - CI I can be obtained by applying the
Pythagorean theorem to triangle C, CI and ii, that is

(3.18)
Notice from Figure 3.23 that

Using equation (3.16), we have

(3.19)
The variable x is then determined by substituting equation (3.19) into
(3.18). We can immediately verify whether the cylinder intersects the sphere
by plugging x and L into equation (3.14).
Notice that this intersection test is used only for cases 2, 3, 5 and 6.
The other three possible cases, namely cases 1, 4 and 7, are addressed in a
different way, as shown in Figure 3.25.
In cases 1 and 7, the distances of the center of the sphere to its projection
on both the top and bottom planes are greater than the radius of the sphere,
that is

d> rc. (3.20)


Substituting equation (3.20) into (3.18), we obtain

which has no real solution. Therefore, the cylinder does not intersect the
sphere in cases 1 and 7.
Finally, if the relative displacement corresponds to case 4, we have

x = rc
and the intersection test to be used is the same as that in Figure 3.24.
3.5 Collision-Detection Implementation 97

FIGURE 3.25. Relative displacement of the cylinder and the sphere for cases 1, 4
and 7.

At this point, we have covered the intersection tests for all seven possible
cases of relative displacement between the cylinder and the sphere. How-
ever, we still need to address how to determine in which of the seven cases
we are given the initial cylinder and sphere positions.
In order to do so, we start by computing the value of d, using equa-
tion (3.19). If Id I > T e , then we are either at case 1 or 7, and the cylinder
does not intersect the sphere. Else, if d > 0, then we are at case 2 and the
variable x is computed using equation (3.18). If our case does not fit in any
of the above situations, then we need to check whether

(3.21)
If equation (3.21) evaluates to true, then we are at case 6 and the variable
x is also computed using equation (3.18). Otherwise, we are at case 3, 4
or 5, and the variable x is obtained from equation (3.17).

3.5.4 Computing Cylinder- Triangle Intersections


The cylinder-triangle intersection test presented in this section is the first
of a two-part collision-detection test between particles' trajectories and
triangle primitives forming a rigid body. For efficiency reasons, the algo-
rithm described here is not a general cylinder-triangle intersection test be-
cause the check for intersections between triangles and the limiting planes
defining the cylinder is left partly unresolved until the second part of the
collision-detection test is performed. The second part of the detection test,
already explained in Section 2.4.7, consists of checking for sphere-triangle
98 3. Particle Systems

intersections, with the sphere representing the final position of the parti-
cle. Notice that there is no need to carry out a sphere-triangle intersection
test at the initial position of the particle because that was the particle's
final position at the previous simulation time step, and therefore has been
checked already.
As mentioned in Section 3.4, the cylinder represents the particle's tra-
jectory for the current time step. In this context, the point h! is associated
with the initial position of the particle and the point h2 to its final position.
The cylinder's axis represents the actual trajectory of the point-mass parti-
cle. Therefore, collision points between the cylinder and the triangle should
be located on the cylinder axis, representing the position of the particle at
the moment of collision.
The first step in the cylinder-triangle intersection test consist of carrying
out a quick rejection test. This test is used to check whether all vertices
of T lie either above the top or below the bottom limiting planes of the
cylinder. If so, then we can immediately conclude that the cylinder does
not intersect the triangle (see Figures 3.26 and 3.27).

I
I
I
I
H I
I
I
I

_---1---_
I

- h:. "

FIGURE 3.26. The triangle does not intersect the cylinder whenever its vertices
lie above the top limiting plane of the cylinder.

The vertices of triangle T will lie above the top limiting plane of the
cylinder if

(Vi· Uh -')'2) > 0, Vi E {1,2,3} (3.22)

and they will lie below the bottom limiting plane of the cylinder if

(Vi· Uh -')'d < 0, Vi E {1,2,3}. (3.23)


3.5 Collision-Detection Implementation 99

FIGURE 3.27. The triangle does not intersect the cylinder whenever its vertices
lie below the bottom limiting plane of the cylinder.

The cylinder does not intersect the triangle if either equations (3.22)
or (3.23) is satisfied for all vertices. Otherwise, more tests are needed to
determine whether triangle T is in fact intersecting cylinder H.
The next step consists of checking whether the cylinder axis is parallel to
Pt , the plane that contains the triangle. That is, we need to check whether

ih . fit = 0 , (3.24)
where fit is the plane normal. For the sake of clarity, let's subdivide our
analysis at this point into two main cases, namely: the cylinder axis does
not intersect Pt (i.e., the axis is parallel to the plane); the cylinder axis
does intersect H.

Case 1: Axis is parallel to plane.


This is the case in which equation (3.24) is satisfied. Since the axis is
parallel to the plane, we need to compute ther distance and compare it
with the cylinder's radius. The distance between an axis parallel to a plane
and the plane itself is the same as the distance from any point in the axis,
say hb to the plane, and is given by

Clearly, if

Idl > r c ,
then the cylinder does not intersect the triangle (see Figure 3.28).
However, if this is not the case, then the plane Pt is not only parallel
to the cylinder's axis, but also intersects the cylinder. This is illustrated in
Figure 3.29.
100 3. Particle Systems

iihl d

~ P,
I
I
I
I
I
I
H I
I
I
I
I
~--:-I---
V2
~

FIGURE 3.28. The cylinder axis is parallel to the plane containing the triangle.
In this case, there will be no intersections if the distance d between the cylinder
axis (hl' h2) and the plane is greater than the radius rc of the cylinder.

: II I_-.,.vl
I -

I [- ~r--t I',
H " I::;" I
',I I \
f', I ,
I , I ,
_---I--.:::,L ___ ~
/"..... ---- j2r1',
l
_ r- ,
--"'--J't
~T "
I

FIGURE 3.29. Plane Pt containing the triangle is parallel to, and intersects, the
cylinder. We project onto the cylinder's axis the triangle vertices that are inside
the cylinder, and set as intersection point / the projection closer to the initial
point h1 • In the situation shown, /2 is selected as the intersection point between
the particle and the triangle.
3.5 Collision-Detection Implementation 101

At this point, we need to conduct several inclusion tests to see whether


the intersection region between Pt and the cylinder contains the triangle.
First, we need to check whether one or more vertices of the triangle lie
inside the cylinder. Vertex Vi E T, for i E {l, 2, 3}, lies inside the cylinder if
it is positioned between the top and bottom limiting planes and its distance
to the cylinder is less than the radius Te. Putting into equations, we need
to verify that

(Vi' Uh - 1'2) < 0


(Vi . Uh - 1'1) > 0
Idi I < Te
is satisfied for at least one vertex of T. If this is so, then the cylinder
intersects the triangle (see Figure 3.29). The intersection point is chosen
by projecting the triangle vertices inside the cylinder onto its axis, and
selecting the projected vertex closest to hI, that is, closest to the initial
point in the trajectory.
In the event all vertices of T lie outside the cylinder, then we need to
check whether the intersection region between the cylinder and the plane
containing the triangle is completely or partly inside the triangle. This
can be efficiently done if we project the cylinder axis onto the plane that
contains the triangle, as shown in Figure 3.30.

FIGURE 3.30. The projected cylinder axis (a,6) is checked for intersections with
the triangle edges. Edges (ift, V2) and (V3, VI) intersect the projected axis at points
th and iiI, respectively. The point ih is selected as the intersection point because
it is closer to the initial position hI.
102 3. Particle Systems

Let a and b be, respectively, the projection points of hI and h2 on the


plane Pt. The projected axis is then checked for intersection with the tri-
angle edges. This segment-triangle intersection test is explained in detail in
Section 2.4.9. If intersections are found, then we choose as the intersection
point the intersection closest to hI (see Figure 3.30). If the projected axis
does not intersect the edges of the triangle, then the triangle does not inter-
sect the cylinder. However, it can still intersect the top or bottom limiting
planes of the cylinder. The intersection with the top plane is left unresolved
at this point because it will be carried out later during the sphere-triangle
intersection test (the top plane is inside the sphere representing the particle
at the end point of its trajectory.) On the other hand, the intersection test
with the bottom plane (Le., the plane associated with the starting point of
the trajectory) is completely ignored, since it was already carried out dur-
ing the previous simulation time step (the starting point of the trajectory
was the ending point of the previous time step.) Therefore, in both cases,
the cylinder-triangle intersection test returns false, meaning the cylinder
does not intersect the triangle.
There is, however, a special case to be considered before we compute
the intersection between the projected axis (a,b) and the triangle edges. If
the particle is in contact with the rigid body, then the intersection point
between the particle and the triangular faces representing the object can be
its initial point hI. This happens whenever the particle is at rest or rolling
on top of a triangular face, with an external force (such as gravity) pulling
along the triangle normal, as shown in Figure 3.31.

FIGURE 3.31. The particle is rolling on top of a triangular face. At the start of
the current time step, gravity pulls the particle down and a collision is detected
at the beginning of the movement. The collision-response module then computes
the contact force Fc that will prevent the particle from moving downwards. The
particle's trajectory is then recomputed taking the reaction force into account,
and the particle moves parallel to the triangular face, from its initial position hI
to its final position h2 •

In order to deal with this special case, we need first to test whether a
lies inside the triangle. If so, then the cylinder intersects the triangle, and
the intersection point is set to hI (this point-in-triangle test is covered in
3.5 Collision-Detection Implementation 103

Section 2.4.4). Otherwise, the projected axis is checked for intersections


with the triangle edges, as explained above.

Case 2: Axis intersects the plane.


Here, equation (3.24) is not satisfied. We first need to compute the in-
tersection point 9 between the plane and the line supporting the axis.
The intersection point 9 will be given by

(3.25)
for some kg E ill (see Section A.4 of Appendix A for details on how to
determine kg). If kg < 0 or kg > 1, then the cylinder does not intersect
the triangle. However, if 0 ::; kg ::; 1, then we need to check whether the
intersection point 9 lies inside or outside the triangle (see Figure 3.32.) This
test can be efficiently implemented using the point-in-triangle test already
discussed in Section 2.4.4. If 9 lies inside the triangle, then the cylinder
intersects the triangle and we set 9 as their intersection point.

FIGURE 3.32. The intersection point § between the cylinder axis and the plane
that contains the triangle lies inside or outside the triangle. In the situation
shown, point § lies inside the triangle.

Otherwise, if 9 lies outside the triangle, then one of the following cases
can occur:

1. One or more edges of the triangle intersect the cylinder cap;

2. The triangle is intersecting the top limiting plane of the cylinder;

3. The triangle is intersecting the bottom limiting plane of the cylinder;

4. And, of course, the triangle is not intersecting the cylinder at all.


104 3. Particle Systems

Case 2 is left unresolved for the moment because the top limiting plane
is also part of the spherical cap, and therefore its intersection with the
triangle is left to the sphere-triangle test. Also, case 3 is ignored because
the bottom limiting plane at the current time step was the top limiting
plane at the previous time step and was already checked at that time. In
both cases, the cylinder-triangle intersection test returns false, meaning the
cylinder does not intersect the triangle.
Case 1 requires some extra steps, as illustrated in Figure 3.33. For each
edge of the triangle, we determine its closest point and distance to the cylin-
der's axis. The closest point of an edge to a line is computed as indicated
in Section A.5 of Appendix A.

FIGURE 3.33. The distance d 1 2 is less than r c , meaning 912 is approximated as


the intersection point between the cylinder and the triangle.

Let d ij be the distance from edge Cr, J) to the cylinder's axis. If the
distance from all edges is such that

dij > r c , for i,j E {I, 2, 3}, i i= j ,

then, at first, none of the edges intersects the cylinder cap. The triangle
may still intersect the top limiting plane, possibly passing through the
cylinder cap (see Figure 3.34). However, as mentioned, checking whether
the triangle intersects the top limiting plane is left to the sphere-triangle
intersection test, and no further tests are required at this stage.
However, if one or more distances dij are less than or equal to r c , then
we check whether their associated closest point gij is inside the cylinder. If
this is the case, then the cylinder intersects the triangle and the intersection
point is set to the gij closest to hi (the initial position of the particle). The
point-in-cylinder test is covered in Section 3.5.5.
Finally, if all closest points gij are outside the cylinder, then the triangle
may still be intersecting the top limiting plane of the cylinder (see Fig-
3.5 Collision-Detection Implementation 105

FIGURE 3.34. The distances between the triangle edges and the cylinder axis are
greater than r e , but the triangle still intersects the cylinder's top limiting plane.
The point § is the intersection between the cylinder's axis and the triangle plane.

ure 3.35). Again, this case is dealt with in the sphere-triangle intersection
test.

3.5.5 Point-in-Cylinder Test


The point-in-cylinder test can be carried out in three easy steps. First, we
determine the relative position of the point p with respect to the top and
bottom limiting planes of the cylinder. If plies above or below the top and
bottom limiting planes, respectively, then it is not included in the cylinder.
Otherwise, if p lies on either of the planes, then we need to compute its
distance to hI or h2 as appropriate, and compare it with the radius of the
cylinder. For instance, if p lies on the top limiting plane, then we need to
check whether

(3.26)

If equation (3.26) is satisfied, then the p lies inside the cylinder.


Finally, if p lies between the top and bottom limiting planes of the cylin-
der, then we need to compute its distance to the cylinder's axis and compare
it with the cylinder's radius. Let d be the distance between p and the cylin-
der's axis (see Section A.2 of Appendix A for details on how to compute
the distance between a point and a line segment). The point is inside the
cylinder if and only if
106 3. Particle Systems

I
I
I
I

_---1---_
I

--- ~+ --

FIGURE 3.35. Distance d12 is less than T e , but the closest point 912 lies outside
the cylinder axis. Nonetheless, the triangle still intersects the cylinder at its top
limiting plane.

3.6 Particle-Particle Collision Response


Whenever a particle-particle collision is detected, the collision-response
module is invoked to compute the appropriate collision impulses or contact
forces that will prevent interpenetration between the colliding particles. As
explained in Section 3.4, the trajectories of the colliding particles are traced
back in time to the moment before their collision. The collision point and
normal are then determined from their geometric displacement.
In the case of particle-particle collisions, the collision point is the actual
particles' position, since the particles are treated as point-mass objects and
all collision forces are directly applied to the center of the sphere represent-
ing each particle. The particles' shape is only used to compute the normal
direction of the collision. As indicated in Figure 3.36, the collision normal
is determined by connecting the center of the particles' spheres.
The colliding particles are arbitrarily assigned indexes 1 and 2, and the
normal direction is selected such that the relative velocity (ih - V2) of the
particles along the normal is negative just before the collision, that is, we
choose ii such that

(3.27)
is satisfied just before the collision. This assignment is critical, since from
Newton's principle of action and reaction the collision impulses and contact
forces between the particles have the same magnitude, but opposite direc-
tions. Following our convention, a positive impulse should be applied to
3.6 Particle-Particle Collision Response 107

FIGURE 3.36. Particles 01 and 02 are traced back in time to the moment before
their collision. The collision normal fi is defined by the line connecting the center
of the spheres. Its direction should be the opposite of the relative velocity (ih -V2)
of the particles along the normal.

the particle with index 1, whereas a negative impulse should be applied to


the particle of index 2. Therefore, it is very important to keep track of the
index assigned to each particle so as to later apply the collision impulses
and contact forces on the correct direction (Le., with the correct sign) to
each particle. Also, notice that in the case of multiple particle-particle col-
lisions, a particle might be assigned different indexes for each collision it is
involved.
The difference between a collision and a contact is determined from the
module of the relative velocity along the collision normal, at the collision
point. If the relative velocity of the particles along the normal, at the
moment before the collision, is less than a threshold value, then the particles
are said to be in contact and a contact force is computed to prevent their
interpenetration. Otherwise, the particles are said to be in collision and an
impulsive force is applied to instantaneously change the direction of motion
of the particles to avoid the imminent interpenetration.
It may happen that several particles are involved in multiple collisions
and contacts. If so, the collision-response module should first resolve all
collisions by simultaneously computing all impulsive forces. Having deter-
mined all impulsive forces, the collision-response module proceeds by ap-
plying the impulses to the appropriate particles. By the time the impulses
are applied, some of the contacts may break, depending on whether the rel-
ative acceleration of the particles at their contact point, along the contact
normal, is positive, zero or negative. A contact force is then simultaneously
computed for all contacts that have a negative relative acceleration along
their contact normal.

3.6.1 Computing Impulsive Forces for a Single Collision


Let's start by examining the case where we have one or more simultaneous
collisions, each involving two different particles. Here, each collision can be
108 3. Particle Systems

dealt with independently of the others, since they do not have particles in
common.
Let collision C, involving particles 0 1 and O 2 , be defined by its col-
lision normal ii and tangent axes f and k, as indicated in Figure 3.37.
Let ih = ((Vl)n, (Vl)t, (Vl)k) and V2 = ((V2)n, (V2)t, (V2)k) be the parti-
cles' velocities just before the collision, and VI = ((Vdn' (Vdt, (V1h) and
V2 = ((V2)n, (V2)t, (V2)k) be their velocities just after the collision. We need
to compute their velocities just after the collision, along with the impulsive
force P = (Pn , Pt , Pk ). This yields a total of nine unknowns (P, VI and
V2 ), thus requiring the solution of a system with nine equations.

-P,
ii

..

FIGURE 3.37. Particles 0 1 and O 2 just before their collision. The impulsive force
is applied to each particle, with same magnitude, but opposite direction.

Applying the principle of impulse and momentum for each particle along
the three collision axes, we obtain six out of the nine equations needed:

~l (V1)n -~l (Vl)n Pn (3.28)


~l (vdt - ~l (Vl)t Pt (3.29)
~l (vdk - ~l (Vdk Pk (3.30)
~2(V2)n -~2(V2)n -Pn (3.31 )
~2 (V2)t - ~2 (V2)t -Pt (3.32)
~2 (V2)k - ~2 (V2)k -Pk· (3.33)

The next equation is obtained by the empirical relation involving the


coefficient of restitution and the relative velocity of the particles along the
normal direction of collision. Let e denote the coefficient of restitution along
the normal direction. We have

(3.34)
3.6 Particle-Particle Collision Response 109

The remaining two equations are obtained from the Coulomb friction
relations at the collision point. If the relative motion of the particles along
f and k is zero just before the collision, that is, if

(Vl)t - (V2)t 0
(Vdk - (V2)k 0,
then their relative motion will remain zero after the collision. More specif-
ically, we use

(3.35)
(3.36)
as the two remaining equations to solve the system. However, if the rel-
ative motion is not zero, then the particles are sliding along f and k at
the collision point. The collision impulse will then act on the opposite
direction of motion, trying to prevent the sliding. If it succeeds, then equa-
tions (3.35) and (3.36) should be used. Otherwise, the particles continue
sliding throughout the collision, and we use

(3.37)
(3.38)

as the two remaining equations to solve the system. Notice that (J-td)t and
(J-td)k are the dynamic Coulomb friction coefficients along the f and k axes,
respectively. Since Pt and Pk are always opposing the sliding motion, the
coefficients of friction can be either positive or negative to reflect that
condition. The actual signs of the coefficients depend on the relative velocity
of the particles along their associated axes, just before the collision. The
signs are directly computed from

(V2)t - (Vl)t
(3.39)
(V2)n - (Vl)n
(V2)k - (Vl)k
(3.40)
(V2)n - (Vl)n .
This directional-friction model is a generalization of the widely used
model of relating the tangential and normal impulses using just one omni-
directional coefficient of friction J-td, as in

Ptk = J-tdPn, (3.41)


where Ptk is the impulse on the tangent plane given by
110 3. Particle Systems

For example, if friction is isotropic, that is, independent of direction,


then we can write

J-Ld COS¢
J-Ld sin ¢

for some angle ¢, so

Ptk jP? +Pl


-J"(J-L-d-c)""'"2-=P:C;;;:-c-o-s--:¢""'"2-+-("-J-L-d""'"')2""""P-==n"""2-si:-n-¢=2
J-LdPn,

which is the same result obtained using the omnidirectional-friction model


of equation (3.41). The main advantage of using the directional-friction
model is that the non-linear equation

which needs to be enforced when the particles are not sliding at the collision
point, can be substituted for two linear equations

I Pt I < J-LtPn
I Pk I < J-Lk Pn

which are equivalent to the non-linear equation if friction is isotropic, and,


most important, are easier to handle in matrix form, as we shall see shOItly.
So, as far as friction is concerned, we have to consider two possible
cases. In the first case, we assume the particles continue sliding on the
tangent plane after collision, and we use equations (3.28) to (3.34) with
equations (3.37) and (3.38) to compute the collision impulse and velocities
after the collision. In the second case, the particles are not sliding on the
tangent plane after the collision, and we use equations (3.28) to (3.34) with
equations (3.35) and (3.36) instead. For now, let's focus on the solution cor-
responding to the first case. Later, we consider the required modifications
needed to address the second case.
Summing equations (3.28) and (3.31), (3.29) and (3.32), (3.30) and (3.33),
we get
3.6 Particle-Particle Collision Response III

mi (vdn + m2 (V2)n ml (vdn + m2 (V2)n (3.42)


mi (Vdt + m2 (V2)t mi (vdt + m2 (V2)t (3.43)
mi (VI)k + m2 (V2)k ml (VI)k +m2(V2)k . (3.44)

Subtracting the same equations pair-wise, we obtain

(mi (vdn - m2 (V2)n) - (mi (vdn - m2 (V2)n)


(3.45)
2
(mi (VI)t - m2 (V2)t) - (mi (VI)t - m2 (V2)t)
(3.46)
2
(ml (VI)k - m2 (V2)k) - (mi (VI)k - m2 (v2h)
(3.47)
2
Substituting equations (3.45) to (3.47) into (3.37) and (3.38) gives

(/ld}t mi (VI)n - mi (VI)t - (/ld)t m2 (V2)n + m2 (V2)t =


(/ld)t mi (vdn - mi (VI)t - (/ld)t m2 (V2)n + m2 (V2)t (3.48)
(/ld)k ml (vdn - mi (VI)k - (/ld)k m2 (V2)n + m2 (V2h =
(/ld)k mi (vdn - mi (VI)k - (/ld)k m2 (V2)n + m2 (V2)k . (3.49)

Making a change of variables such that

(Ui)j = mi ((Vi)j - (Vi)j), fori = {1,2}, j = {n,t,k} ,


the system defined by equations (3.42) to (3.44), (3.34), (3.48) and (3.49)
can then be written as

(udn + (U2)n 0
(UI)t + (U2)t 0
(Udk + (U2)k 0
(U1)n (U2)n
-----
mi m2
-(1 + e) ((VI)n - (V2)n)
(/ld)t (UI)n - (Udt - (/ld)t (U2)n + (U2)t 0
(/ldh (UI)n - (Ul)k - (/ld)k (U2)n + (U2)k 0.

Solving for the (Ui)j we obtain


112 3. Particle Systems

ml2 (1 + e) ((V2)n - (VI)n) (3.50)


(UI)t ml ((VI)t - (vdt)

(J-Ld)t ml2 (1 + e) ((V2)n - (VI)n) (3.51)


(UI)k ml ((VI)k - (Vdk)

(J-Ldh m12 (1 + e) ((V2)n - (VI)n) (3.52)


(U2)n m2 ((V2)n - (V2)n)

-m12 (1 + e) ((V2)n - (VI)n) (3.53)


(U2)t m2 ((V2)t - (V2)t)

-(J-Ld)t ml2 (1 + e) ((V2)n - (VI)n) (3.54)


(U2)k m2 ((V2)k - (V2)k)

-(J-Ld)k m I2(1 +e)((V2)n - (VI)n)' (3.55)

where
mlm2
ml2 =
(ml + m2)
The particle velocities VI and V2 just after the collision are directly ob-
tained from equations (3.50) to (3.55). Substituting their values into equa-
tions (3.45) to (3.47), we immediately get the impulse P.
All derivations up till now considered the case wherein the colliding par-
ticles continue sliding throughout the collision. If the particles are not slid-
ing after collision, either because they were not sliding before the collision
or the sliding motion stopped during the collision, then equations (3.35)
and (3.36) should be used instead of equations (3.37) and (3.38), which are
repeated here for convenience:

(vdt (V2)t
(VI)k (V2)k.

Notice that the sliding motion on the tangent plane is directly affected by
the coefficients of restitution and friction, as well as by the relative velocities
of the particles just before the collision. Intuitively, for a given coefficient
of restitution and relative velocities, the sliding motion will continue if
the coefficient of friction is small, or will stop if the coefficient of friction
is sufficiently large. Therefore, there exists a critical coefficient of friction
value associated with a given coefficient of restitution and relative velocity
of the particles. If the actual coefficient of friction is less than the critical
coefficient of friction, then slide continues throughout the collision and
the system equations associated with the first case should be considered.
However, if the actual coefficient of friction is greater than or equal to
the critical coefficient of friction, then slide stops somewhere during the
3.6 Particle-Particle Collision Response 113

collision and the system equations associated with the second case should
be considered instead.
Let's derive an expression for computing the critical coefficient of friction.
If we substitute back (Vt}t, (Vt}k , (V2)t and (V2)k obtained from equa-
tions (3.51), (3.52), (3.54) and (3.55), respectively, into equations (3.37)
and (3.38), we get

(Vl)t) + (J.Ld)t m12 (1 + e) ((V2)n - (vI}n)


ml
(V2)t) - (J.Ld)t m12 (1 + e) ((V2)n - (Vl)n)
m2
(Vl)k) + (J.Ld)k m12 (1 + e) ((V2)n - (vI}n)
ml
(V2)k) - (J.Ld)k m 12 (1 + e) ((V2)n - (Vl)n)

1 ((V2)t - (vt}t)
(3.56)
(1 + e) ((V2)n - (Vl)n)
1 ((V2)k - (Vl)k)
(3.57)
(1 + e) ((V2)n - (Vl)n) ,

where (J.Ld)f and (J.Ld)k are the critical values of the coefficient of friction
such that the sliding motion stops exactly at the end of the collision.
We do the following in practice. First, compute the critical coefficient
of friction using equations (3.56) and (3.57). Then, compare the actual
coefficient of friction (J.Ld)t and (J.Ld)k to their associated critical values. If
(J.Ldh < (J.Ld)f, then sliding continues along f and we use equation (3.37).
Else, if (J.Ld)t 2: (J.Ld)f, then sliding along f stops during the collision and we
use equation (3.35). The same analysis is used for comparing (J.Ld)k with
(J.Ld)k and selecting the appropriate system equation.
Also, notice that there is no need to derive a new set of solutions to the
system equations for the case in which sliding stops during the collision; we
just need to use the critical value of the coefficient of friction instead of the
actual friction value in the solution equations already obtained. Recall that,
if we set (J.Ld)t = (J.Ld)f, then we immediately obtain the desired condition
(Vt}t = (V2)t. By analogy, if we set (J.Ld)k = (J.Ld)k, we get (Vt)k = (V2)k.
An alternate representation of the system equations for computing the
collision impulses commonly found in the literature is the partitioned-
matrix representation. Even though this representation is not particularly
useful for the singe-collision case because we were able to compute the im-
pulse and final velocities, it proves to be extremely useful when dealing with
114 3. Particle Systems

multiple simultaneous collisions. Here, we shall focus on the partitioned-


matrix representation of a single collision. In Section 3.6.2, we extend it to
the multiple-collision case.
As previously explained, we use equations (3.28) to (3.34) with equa-
tions (3.37) and (3.38) whenever the particles continue sliding on the tan-
gent plane after collision. In this case, the system equations can be put into
the following matrix format:

0 0 0 1 0 0 -1 0 0 (P1,2)n
-(/-ld)t 1 0 0 0 0 0 0 0 (P1,2)t
-(/-ldh 1 0 0 0 0 0 0 0 (P1,2)k
-1 0 0 m1 0 0 0 0 0 (vdn
0 -1 0 0 m1 0 0 0 0 (vdt
0 0 -1 0 0 ml 0 0 0 (vdk
1 0 0 m2 0 0 0 0 0 (V2)n
0 1 0 0 m2 0 0 0 0 (V2)t
0 0 1 0 0 m2 0 0 0 (V2h
-e ((V1)n - (V2)n)
0
0
m1 (vdn
m1 (vI}t (3.58)
m1 (V1)k
m2 (V2)n
m2 (V2)t
m2 (v2h

where Pl,2 = ((P1,2)n, (P1,2)t, (P1,2)k) is the collision impulse between par-
ticles 0 1 and O 2 .
If sliding along the f direction stops by the end of the collision, then we
need to use equation (3.35) instead of equation (3.37). This in turn has the
effect of substituting the second row of the system matrix for

(0 0 0 0 1 0 0 -1 0).

Conversely, if sliding along the k directions stops by the end of the col-
lision, then we need to substitute the third row of the system matrix for

(0 0 0 0 0 1 0 0 -1).
The partitioned-matrix representation of the system can be directly ob-
tained from equation (3.58), and is given by

Al,2
( -I (3.59)
1
3.6 Particle-Particle Collision Response 115

where I is the 3 x 3 identity matrix, 0 is the 3 x 3 zero matrix, and

The matrices A 1 ,2 and B 1 ,2 are chosen depending on whether sliding


continues along the tangent plane after the collision ends. We have four
possible cases to consider.

~1 0~) and B 1 ,2 = (~0 0~ 0~)

~ 0~)
o
and B 1 ,2 = (~0 0~ ~)
1

Notice that the first row of the partitioned matrix shown in (3.59) con-
tains the coefficient of restitution and friction equations, and it is associ-
ated with the state variable PI,2. The second and third rows contain the
conservation-of-linear-momentum equations associated with the final veloc-
ities VI and V2 , respectively. This ordering is extremely important because
it can significantly simplify the updates required for the multiple-collision
case.

3.6.2 Computing Impulsive Forces for Multiple Simultaneous


Collisions
During a simulation, there might be situations in which three or more par-
ticles are simultaneously colliding with each other. In these cases, instead of
resolving one collision at a time not taking into account the presence of the
others, the simulation engine needs to group the particles into clusters that
116 3. Particle Systems

Cluster G2 Cluster G)

FIGURE 3.38. Multiple particle collisions separated into three clusters. Particle
Oi is added to cluster G j if it is colliding with at least one particle already in G j •
The collision-response module resolves each cluster in parallel, since they have
no collisions in common and therefore can be viewed as independent groups of
collisions.

share at least one collision. The collisions within each cluster can then be
simultaneously resolved independent of all other clusters (see Figure 3.38).
Consider the computation of the collision impulses associated with clus-
ter G 1 , as shown in Figure 3.38. Let collisions C 1 and C 2 be the collisions
(0 1 - O 2 ) and (0 2 - 0 3 ), respectively. As far as particle O 2 is concerned,
the linear momentum equation owing to both collisions becomes

(3.60)

where P2H1,3H2 is the impulse P2,3 of collision C 2 expressed in the local


coordinate frame 5 associated with collision C 1 . The minus sign on P1 ,2
shows that particle O 2 has index 2 with respect to collision C 1 .
Clearly, the impulse owing to collision C 2 will also affect the computation
of the impulse owing to collision C 1 , and vice-versa. Therefore, the correct
way to compute the collision impulses is to take both collisions into account
when solving the system of equations. Recall from Section 3.6.1 that we
adopted the convention that a positive impulse is applied to the particle
with index 1, and a negative impulse is applied to the particle with index
2. The choice of indexes is related to the relative velocities of the particles
along the collision normal, such that equation (3.27) is satisfied at the
moment just before the collision.

5The local-coordinate frame is defined by the collision normal and tangent plane.
3.6 Particle-Particle Collision Response 117

If a particle is involved in multiple collisions, it is possible to have it


assigned to different indexes for each collision. For the particular situation
of cluster G 1 , particle O2 has index 2 with respect to its collision with
particle 0 1 , and index 1 with respect to its collision with particle 0 3 , This
in turn affects the choice of sign when combining the multiple-collision
impulses in the system equations (Le., the minus sign of Pl,2 and the plus
sign of P2>-+l,3>-+2 in equation (3.60)). Moreover, the collision normal and
tangent plane are different for each collision. So, we also need to implement
a change of base between the collision impulses before combining them (Le.,
the vector P 2>-+l,3>-+2 used in equation (3.60)).
The best way to deal with multiple collisions is to represent the system
equations associated with each cluster in its partitioned matrix form

where if is the state vector containing the variables that need to be de-
termined. In the case of a single collision, the state vector is defined by
the collision impulse and final velocities of the colliding particles. However,
when dealing with multiple collisions, the state vector can be viewed as
the concatenation of several single-collision state vectors, with the added
complexity that no variables should be accounted for more than once. For
instance, Figure 3.39(a) shows the result of a naive concatenation of state
vectors for the multiple collisions associated with cluster G 1 of Figure 3.38.

State vector State vector


q - O2 Collision: ~.2 _ ~.2 q - 02 Collision: ~.2 _ ~.2
v.- V. v.- v.
f ; - f;
02 - 0 3 Collision: P:z.3 _
P:z.3
f ; - f; ~
T
f ; - f;
O2 - 0 3 Collision: P':'3 P:z.3
t:;
iJ.-
3 t:; -/
f;
(a) (b)

FIGURE 3.39. (a) A naive concatenation creates multiple entries for the fi-
nal velocities of particles that are involved in more than one collision; (b) The
state-vector variables should have a link back to their collisions. More than one
link is used for multiple collisions, as in the case of V2.

Since particle O 2 is involved in both collisions, its final velocity V2 is


counted twice. The correct way to create the state vector is then to keep
track of the variables already added, and mark as "common" those added
more than once. This is illustrated in Figure 3.39(b).
Having determined the state vector associated with a cluster, the next
step is to fill in the rows of matrix A and vector b. This can be done by
118 3. Particle Systems

considering the equation associated with the first link of each variable in
the state vector. For example, for the cluster G l of Figure 3.38, the first
variable of the state vector is Pl,2. This variable is linked to the (0 1 -
O 2 ) collision. Its associated equations are the coefficient of restitution and
friction equations. Therefore, the first row of matrix A and vector b is

(T
B 1 ,2 -B 1 ,2
x X
X X
X X
X X

The second variable of the state vector is VI. This variable is also linked
to the (0 1 - O 2 ) collision. Its associated equations are the conservation
of linear momentum for particle 0 1 . So, the second row of matrix A and
vector b is

B 1 ,2 -B 1 ,2 0 Pl ,2 Ch,2

D ( 1
( A."
-I mIl 0 0 VI ml ih
x x x X V2 X
X X X X P23, X
X X X X
V3 x

Doing the same for all other state variables, we obtain

B 1 ,2 -B 1 ,2 0 0 P12, d-;',2

( 1
( A."
-I mIl 0 0 0 VI ml iit

1
I 0 m21 0 0 V2 m2ih
0 0 B 2 ,3 A 2 ,3 -B 2 ,3 P23, d-;,3
0 0 0 I m3 1 V3 m3 ih
(3.61 )
Notice the difference between rows 1 and 4 of the system matrix shown
in equation (3.61). Since V2 is common to both (0 1 - O 2) and (02 - 0 3 )
collisions, the matrices A 2 ,3 and B 2 ,3 were rearranged to correctly multiply
their associated state-vector variables. The correct order is B 2 ,3 multiplying
the linear velocity of the particle with index 1, A 2 ,3 multiplying the impulse
associated with collision (0 2 - 0 3 ) and (-B 2 ,3) multiplying the linear
velocity of the particle with index 2. Because for collision O 2 - 0 3 particle
O 2 is associated with index 1 and particle 0 3 with index 2, the arrangement
of these block matrices in row 4 of equation (3.61) is different from the one
obtained for row l.
Also, notice that equation (3.61) was bllilt following only the first link of
each state-vector variable. Now, we need to update equation (3.61) with the
multiple-collision terms. This can be done by considering the state variables
3.6 Particle-Particle Collision Response 119

that have more than one associated link. The first link was used to define
the row. The following links are used to update some elements of the row
with the multiple-collision terms.
In general, if particle Oi is involved in more than one collision, then the
row associated with ~, that is, the row associated with its final velocity,
needs to be updated. Say for example that particle Oi has a second link to
particle OJ. Let A,j designate the state-vector variable corresponding to
the impulse associated with this collision. So, the index of ~ in the state
vector defines the row of the system matrix to be updated, and the index
of Pi,j in the state vector defines the column of the system matrix that
needs to be updated. Therefore, we need to update the element

[index of ~][index of A,j]

of the system matrix given in equation (3.61).


The actual update consists of accounting for Pi,j in the linear momentum
equations associated with particle Oi' This can be done by expressing Pi,j
with respect to the local-coordinate frame of the collision corresponding to
the first link of the state variable ~.
Say for example that the first link of the state variable ~ is associated
with collision C m involving particles Oi and Om. Let the local-coordinate
frame Fm,i of collision (Om - Oi) be defined by vectors nm,i, t'm,i and km,i'
The second link of the state variable ~ is associated with collision C j
involving particles Oi and OJ. Let the local-coordinate frame Fi,j of colli-
sion (Oi -OJ) be defined by vectors ni,j, 4,j and ki,j. The collision impulse
Pi,j defined in the local frame Fi,j is expressed in the local frame Fm,i as

with

n ··f .
'I.,) ffi,Z ni,) . km,i )
t't,)· fm,z. t't,J.. k·
m,'l .
k't,J··fm,l. k·km,z.
'I.,)

The variable A can be either 1 or -1, depending whether particle Oi is


assigned to index 2 or 1 in collision OJ. The necessary multiple-collision
term update is then

[index of ~] [index of Pi,j] = A-tj,i>-tm .

As an example, let's apply this multiple-collision term update to the


cluster G 1 of Figure 3.39. In this example, the second link of V2 points to
the collision of particle O 2 with particle 0 3 . Therefore, we need to update
the element at
120 3. Particle Systems

[index of V2] [index of P2,3] = [3,4]

in the system matrix of equation (3.61). The actual update will be to


substitute the current 0 element at position [3,4] for

ih,3· t;.,2
£;,3· t;.,2 (3.62)
k2 ,3 • [1,2
where frame :F1 ,2 is defined by vectors nl,2, t;.,2 and k1 ,2, and frame :F2,3
is defined by vectors n2,3, £;,3 and k2,3. Also, since particle O 2 is assigned
to index 1 in its collision with particle 0 3 (see Figure 3.38), we should use
A = +1 in equation (3.62). That is, we need to set

element [3,4] = M 2 H-l,3H-2 .

The final system matrix for this particular example is then:

[
B 1 ,2 -B 1 ,2 0 P1 ,2 d-;',2

J".)
i't
)-
-I
[ At" mIl 0 0 ml ift
I 0 m21 M 2 H-l,3H-2 V2 m2ih
0 0 B 2 ,3 A 2 ,3 P2 ,3 d-;,3
0 0 0 I m3 1 V.1 m3 v3

In summary, for each state-vector variable with more than one link, we
need to update the elements of the system matrix corresponding to each
of these collisions. When all elements are updated, we solve the result-
ing linear system using, for example, the Gaussian elimination method.
Another option would be to use specialized methods to solve sparse lin-
ear systems, since the system matrix is often sparse. The solution would
then give the correct values of the state-vector variables to be used by the
collision-response module.

3.6.3 Computing Contact Forces jor a Single Contact


Two particles are said to be in contact whenever their relative velocities
along the collision normal are either zero, or less than a threshold value.
In these cases, a contact force should be applied, instead of the impulsive
force described in Section 3.6.l.
The contact-force computation is considerably different from the impul-
sive-force computation. In the latter case, we have the equations of conser-
vation of linear momentum and the coefficients of friction and restitution
3.6 Particle-Particle Collision Response 121

defining the system equations. Here, we need to derive other conditions to


compute the contact forces, based on the contact geometry6 and dynamic
state of each particle.
The first condition states that the relative acceleration of the particles
at the contact point, along the contact normal, should be greater than or
equal to zero, assuming that a negative value indicates that the particles
are accelerating towards each other. In this case, if the computed contact
force is such that the relative acceleration at the contact point along the
contact normal is zero, then the particles remain in contact. However, if
their relative acceleration is greater than zero, then contact is about to
break.
The second condition implies that the contact-force component along the
contact normal should be greater than or equal to zero, indicating that the
particles are being pushed away from each other. The contact force is not
allowed to have a negative value, that is, is not allowed to keep the particles
connected to each other, preventing their separation.
The third and final condition states that the contact force should be set
to zero if the contact between the particles is about to break. In other
words, if the relative acceleration at the contact point, along the contact
normal, is greater than zero, then contact is about to break and the contact
force should be set to zero.
Let's translate these three conditions into meaningful equations that can
be used to compute the contact force. Figure 3.40 illustrates a typical situa-
tion in which particles 0 1 and 02 are shown at the moment before contact,
in contact, and interpenetrating each other in case the contact force is not
applied.

(a) (b) (c)

FIGURE 3.40. (a) Particles 01 and 02 are about to make contact with other at
points P1 and P2i (b) Contact is established whenever P1 = P2i (c) Interpenetra-
tion occurs if (P1 - P2) . n < 0, where n is the contact normal.

6When collision becomes a contact, the collision normal will also be referred to as
the contact normal.
122 3. Particle Systems

Let PI (t) and P2 (t) be the position of particles 0 1 and O 2 that are about
to be in contact. Consider the vector iJ(t) defined as

(3.63)

where net) is the contact normal, pointing from particle O 2 to particle 0 1 ,


and itt) and k(t) are vectors defining the tangent plane at the contact.
Clearly, qn(t) defines a distance measure between points P1(t) and P2(t),
along the contact normal, as a function of time. We have qn (t) > 0 if
the particles are separated, qn(t) = 0 if the particles are in contact, and
qn(t) < 0 if the particles are interpenetrating (see Figure 3.40). Let tc be
the instant at which contact is established, that is

The first condition states that the relative acceleration at the contact
point, along the contact normal, should be greater than or equal to zero.
This is equivalent to enforce that

(3.64)

If we let 0:( t) = (an (t), at (t), ak (t)) be the relative acceleration at the
contact point, we can rewrite equation (3.64) as

(3.65)
The components at (t) and ak (t) define the relative acceleration at the
contact point on the tangent plane of the contact. They are only used if
static or dynamic friction is considered at the contact point, as will be
explained later in this section.
The second condition states that the contact-force component along the
contact normal should be non-negative, that is

(3.66)

where F = (Fn' Ft, Fk) is the contact force to be determined. If friction is


taken into account, then the tangent components Ft and Fk of the contact
force are computed following the Coulomb friction model. To elaborate, if
r
the relative velocity of the points PI and P2 along is zero or less than a
threshold value, then there is no sliding at the contact point. In this case,
the component F t will assume values in the range of
3.6 Particle-Particle Collision Response 123

depending on the relative-acceleration component at (t) being positive or


negative. In other words, Ft will do its best to prevent the particles from
sliding at the contact point by always opposing the relative acceleration
at(t? On the other hand, if the relative velocity along is greater thanr
the threshold value, then the particles are sliding at the contact point and

depending on the relative acceleration at (t) being negative or positive. Here,


(J.Ldh is the dynamic coefficient of friction along the i'direction. A similar
analysis holds for k.
The third and last condition states that the contact force is zero if the
contact is breaking away, that is, if the relative acceleration along the con-
tact normal is positive. Equivalently, we have

(3.67)
meaning that, if Fn is greater than zero, then the particles are in contact
and the relative acceleration is zero. Otherwise, if an is greater than zero,
then the contact is about to break and the contact force should be zero.
Putting it all together, we see that the computation of the contact force
involves solving the following system of equations:

an(t c ) > 0
Fn > 0 (3.68)
Fn an(tc) O.

Here, we adopt the convention that a positive contact force +F is applied


to particle 0 1 (Le., the particle with index 1) and a negative contact force
-F is applied to particle O 2 (Le., the particle with index 2).
According to equation (3.64), the relative acceleration an(t), along the
contact normal, can be obtained by differentiating equation (3.63) twice
with respect to time. By so doing, we see that the first time derivative of
equation (3.63) gives

( d P1 (t) _ d P2 (t») . ii(t) +


dt dt
( _ _) dii(t)
PI-P2 .~' (3.69)

or equivalently

7Notice that Ft is zero if at(t) is zero.


124 3. Particle Systems

(ih(t) - V2(t)) . n(t) +


(_ _) dn(t)
(3.70)
P1-P2 '~'

where V1 (t) and V2(t) are the velocity vectors of points P1 (t) and P2(t). This
gives us an expression for the relative velocity vn(t) = dq(t)j dt of points
P1 (t) and P2 (t) along the contact normal, as a function of their velocities
and collision normal. The time derivative of the collision normal indicates
its rate of change in direction as a function of time.
Differentiating equation (3.69) once again with respect to time

(3.71)

or equivalently

(3.72)

where a1(t) and a2(t) are the acceleration vectors of points P1(t) and
P2 (t), respectively. This gives us an expression for the relative accelera-
tion an(t) = d2 q(t)j dt 2 of points Pl(t) and P2(t) along the contact normal,
as a function of their accelerations, velocities, contact normal and rate of
change in direction of the contact normal.
At the instant of contact t = t e , points P1 (t) and P2 (t) are coincident,
that is

(3.73)
Substituting equation (3.73) into (3.72), we obtain an expression of the
relative acceleration along the contact normal at the instant of contact:

According to equation (3.74), the relative acceleration at the instant of


contact has two terms. The first term depends on the accelerations of the
3.6 Particle-Particle Collision Response 125

contact points, which in turn are related to the contact force using Newton's
law. The second term depends on the velocities of the contact points and
the rate of change in direction of the collision normal.
For now, let's assume the contact to be frictionless 8 , that is

If we separate the terms that depend on the contact force from those
that do not, we can rewrite equation (3.74) as

an(tc) = (al1)n Fn + b1 . (3.75)


Substituting equation (3.75) in (3.68), we obtain:

((al1)n Fn + b1 ) > 0
Fn > 0 (3.76)
Fn ((au)n Fn + b1 ) o.
Thus, the computation of the contact force for the frictionless case in-
volves solving the system of equations defined in (3.76), which is quadratic
on Fn. One way of solving this system is to use quadratic programming.
However, such techniques are difficult to implement, often requiring the use
of sophisticated numerical software packages.
Fortunately, the system of equations defined in (3.76) is also of the same
form of a renowned numerical programming technique called linear comple-
mentarity. The implementation using linear-complementarity techniques is
significantly easier than the implementation of a quadratic program, and
is discussed in detail in Appendix G. There, we start presenting solution
methods for the frictionless case, and show how to modify them to deal with
static and dynamic friction at the contacts. These modifications on the so-
lution method require that equation (3.75) be extended to also consider the
relation between the relative-acceleration and contact-force components on
the tangent plane of the contact.
Where friction is taken into account, the system of equations become

(a12 )t
(a22)t
(a32)t 1;m: ) ( :: ) + ( )::1: )
(3.77)

where

SLater in this section, we shall relax this assumption to show how the system of
equations used in the frictionless case can be expanded to handle friction.
126 3. Particle Systems

(a1(tC) - a2(t c))· t(tc) + 2 (1h(t c) - V2(tc))· d~:c) (3.78)

(a1 (t c) - a2(t c)) . k(t c) + 2 (VI (t c) - V2(tc)) . d ~~c) (3.79)

The solution method presented in Appendix G assumes both matrix A


and vector bto be known constants computed from the geometric displace-
ment and dynamic state of the particles at the instant ofcontact. Therefore,
we need to determine the coefficients of matrix A and vector b before we
can safely apply the linear-complementari~ techniques of Appendix G.
The first row of matrix A and vector b is obtained by expressing the
normal relative acceleration an(t c) at the instant of contact as a function
of the contact-force components Fn , Ft and Fk. This can be done using
equation (3.74).
Let's start by examining its first term of equation (3.74), namely the
term
(a1(tC) - a2(tc))· ii(t c) .
The acceleration a1 of point PI is obtained directly from equation (3.4)
as

a1 = F + (Ft}ext , (3.80)
m1
where (F1 )ext is the net external force (such as gravity, spring forces, spa-
tially dependent forces, etc.) acting on particle 0 1 and F is the contact
force to be determined. Similarly, the acceleration a2 of point P2 is given
by

a2 = -F + (F2)ext . (3.81)
m2
Substituting equations (3.80) and (3.81) into the first term of equa-
tion (3.74) gives

+
3.6 Particle-Particle Collision Response 127

So, the total contribution to the coefficients of the first row of matrix A
and vector b from the first term of equation (3.74) is

(aU)n (-1+ -1)


ml m2
(aI2)t 0
(3.82)
(a13)k 0

(bl)n (Ft}ext + (F2)ext) . n(t c) .


ml m2

Notice that (aI2)t and (aI3)k are zero because the first term does not
depend on Ft and Fk, respectively. Now, let's examine the second term of
equation (3.74), namely

_ () _ ( )) d n( t c )
2 (VI tc - V2 tc .~ .

The velocities of points PI and P2 are known quantities independent of


the contact force. So, the contribution to the first row of matrix A from the
velocity components is zero. However, we still need to compute the rate of
change in direction of the contact normal as a function of time and check
whether it depends on the contact force.
Section E.3.1 presents a detailed description of how the time derivative
of the contact normal for the particle-particle case can be computed. For
convenience, the result is reproduced here:
dn(t)
dt
which is independent of the contact force as well. So, the contribution of the
second term of equation (3.74) to the coefficients of matrix A and vector b
is

(a11)n 0
(al2)t = 0
(3.83)
(aI3)k 0

(bl)n = 2CVI -) . 1(VI- - V2)


- V2
VI -V2
- 1= 21-VI - V2- 1.
Combining equations (3.82) and (3.83), we obtain the coefficients asso-
ciated with the first row of matrix A and vector b as
128 3. Particle Systems

(al1)n (-1+ -1)


ml m2
(a12)t 0
(a13)k = 0

(bdn = ( (F1)ext + (F2)ext) . ii


ml m2

+ 21 VI - v21·
The computation of the coefficients associated with the second and third
rows 9 of matrix A and vector bis similar to the derivations already obtained
for the coefficients of the first row. The main difference is that, instead of
computing the dot product with ii, we compute it with f for the second
row, and with k for the third row, as shown in equations (3.78). After some
manipulation, we obtain

(a2dn o
(a22)t = (2..+2..)
ml m2
(a23)k = 0
and

(3.84)
(3.85)

for the second row, and

(a3dn = 0
(a32)t 0

(a33)k = (-
1+-
1 )
mi m2

and

9These coefficients need only be computed if friction is taken into account. In the
frictionless case, both Ft and Fk are zero.
3.6 Particle-Particle Collision Response 129

(3.86)

for the third row of matrix A and vector b.


The actual determination of the coefficients (bt}t and (b1)k as shown in
equations (3.84) and (3.86) is more involved than that for (b 1 )n because
they require computing the rate of change in direction of the vectors itt)
and k(t) on the tangent plane of the contact. The computation of the time
derivative of the tangent-plane vectors is discussed in detail in Section E.4
of Appendix E.
Lastly, having determined the elements of matrix A and vector b, we
can apply the LCP techniques of Appendix G to compute the contact-
force components. We then update the dynamic state of each particle by
applying +F on particle 0 1 and -F on particle O2 •

3.6.4 Computing Contact Forces for Multiple Contacts


The principle behind the computation of multiple particle-particle contact
forces is the same as the computation of multiple particle-particle collision
impulses. Again, the simulation engine needs to group the particles into
clusters that share at least one contact. The contacts within each cluster
can then be simultaneously resolved independent of all other clusters (see
Figure 3.41).
When a particle is involved in multiple contacts, it is possible to have it
assigned to different indexes for each contact. For the particular situation of
cluster G 2 in Figure 3.41, particle O 2 has index 2 with respect to its contact
with particle Ob and index 1 with respect to its contact with particle 0 3 .
This in turn affects the choice of sign when combining the multiple-contact
forces in the system equations. Moreover, the contact normal and tangent
plane are different for each contact. So, we also need to carry out a change
of base between the contact forces before combining them.
In the single particle-particle contact, the contact-force computation tak-
ing friction into account was done using linear-complementarity techniques
to solve a system of equations of the form

an(t c) > 0
Fn > 0
Ft(AF+b) 0,
130 3. Particle Systems

Cluster Gt

Cluster Gz Cluster G3

FIGURE 3.41. A multiple particle-particle contact-force computation. In this


case, the particles are grouped into three clusters that can be solved in parallel.

where 10

F (Fn' Fb Fd
b ((bdn' (b1)t, (b1)k)t

This solution method can be extended to the case of multiple-contact-


force computations. The main difference between multiple- and single-
contact-force computations involving a given particle is that the contact
force at contact C i can affect the computation of the contact force at con-
tact Cj . So, instead of solving one contact at a time, we need to simultane-
ously solve all contacts having a particle in common. This in turn has the
same effect of merging the several individual system of equations for each
contact into one larger system, and applying the linear-complementarity
techniques to merged system.
For example, suppose we have a cluster with m simultaneous contacts.
Each contact C i is defined by its contact-normal (fi)i and tangent-plane
vectors (i)i and (kk The contact force at contact C i is then expressed as

lOHere, we are already using the result of Section 3.6.3 that the matrix A is all zero,
save for its diagonal elements.
3.6 Particle-Particle Collision Response 131

The contact-force vector for the multiple-collision system is obtained by


concatenating the contact-force vectors of each of the m contacts, that is

The vector b becomes

and the matrix A is enlarged to accommodate all contact forces. Its parti-
tioned representation is given by

where each sub-matrix is given by

(ai(j+l»)ti
(a(i+l)(j+l»)ti
(a(i+2)(j+l»)ti
If contacts Ci and Cj have no particles in common, then the sub-matrix
Aij is set to zero, indicating that their contact forces do not affect each
other. However, if contacts Ci and Cj do have a particle in common, then
the coefficients aij are the contribution of the contact force of contact Cj
to the relative acceleration at contact C i . More specifically, the coefficient
(aij)ni is the contribution of the contact-force component (Fj)nj to the
relative normal acceleration at the contact C i . Analogously, the coefficients
(aij)ti and (aijhi are the contribution of the contact-force components
(Fj)tj and (Fj)k j to the relative normal acceleration at the contact Ci .
Also, notice that the contact force Fj is given with respect to the contact
frame of C j , whereas the relative acceleration iii is given with respect to the
contact frame of C i . Therefore, a change of base is required when computing
the coefficients of matrix Aij and vector bi .
Suppose contact Ci involves particles 0 1 and O 2 , and contact Cj involves
particles O 2 and 0 3 , that is, they have particle O 2 in common. We want to
determine the contribution of the contact force Fj acting on particle O 2 of
contact Cj to the relative acceleration of contact C i . This in turn involves
determining the coefficients of the sub-matrix Aij and the components
(bi)ni' (bik and (bi)k i of vector b. The relative acceleration at contact Ci
between particles 0 1 and O 2 is given by
132 3. Particle Systems

(3.87)

As explained in the single-contact case, only the first term of equa-


tions (3.87) depends on the forces exerted at contact Ci . The second term
depends on the velocities and is added to (bi)ni' (bi)ti and (bihi' as appro-
priate. Thus, the contribution of the contact force Pj acting on particle O 2
of contact Cj does not affect the components of vector b. In other words,
the expressions used to compute the vector b for the single-contact case
are still valid for the multiple-contact case, that is, the components (bi)nil
(bik and (bi)k i of vector b are given by

where (Pdext and (P2 )ext are the net external forces (such as gravity, spring
forces, spatially dependent forces, etc.) acting on particles 0 1 and '02 , re-
spectively.
Using equation (3.4), the contribution of the contact force Pj acting on
particle O 2 of contact Cj to the acceleration a1 of particle 0 1 involved in
collision Ci is 11

Conversely, the contribution of Pj to a2 is


11 Notice that the contact force acting on particle 02 because of contact Cj can be
+Fj or -F~, depending on particle 02 having index 1 or 2 with respect to contact Cj.
The following derivations assume the contact force is +Fj.
3.6 Particle-Particle Collision Response 133

_ Fj
m2
The net contribution of Fj to the relative acceleration at the contact Ci
is then
1
(- 1 ) ~
ml
+m2
- Fj •

Substituting this into the first terms of equations (3.87), we obtain the
contributions of Fj to each relative-acceleration component at contact Ci :

contribution to (ai)ni

contribution to (ai)ti

contribution to (ai)k i

Using the fact that

Fj = (Fj)nj nj + (Fj)tj ij + (Fjh j kj ,


we immediately obtain the coefficients of the sub-matrix Aij as

(aij)ni (1- + -1)~


ml m2
~
nj·ni (3.88)

(ai(j+1»)ni (1- + -1)~


ml m2
~
tj ·ni (3.89)

(ai(H2) )ni (-
1+- ~
1 ) kj·ni (3.90)
ml m2

(a(i+l)j)ti (1-ml
1)~nj ·ti~
+ -m2 (3.91)

(aCi+l)(H1)k
( -1 + -1 ~ ·t~i
) tj (3.92)
ml m2

(aCi+l)(H2»)ti
(1- + -1)~
ml m2
~
kj ·ti (3.93)

(aCi+2)j)k i (-
1+- ~
1) nj·ki (3.94)
ml m2

(a(i+2)(j+l»)k i (1- + -1)~


ml m2
~
tj·ki (3.95)

(aCi+2)(j+2»)k i (1- + -1)~


ml m2
~ ·
kj·ki (3.96)
134 3. Particle Systems

Notice that, if i = j, then the sub-matrix Aii is reduced to

o
(a(i+l)(i+l)k
o
which is the same expression obtained in equation (3.77) for the single-
contact case.
When friction is not taken into account, the sub-matrix Aij is reduced
to

since the contact-force components (Fj)tj and (Fj)kj are zero in the fric-
tionless case. This result is also compatible with that obtained for the
frictionless single-contact-force computation explained in Section 3.6.3.
Having computed the contact force Pi for each contact Gi , 1 ~ i ~ m,
we update the dynamic state of each particle involved on contact Gi by
applying +Pi to the particle 0 1 (Le., the particle with index 1) and -P to
the particle O 2 (i.e., the particle with index 2).
When a particle is involved in multiple contacts, it is possible to have it
assigned to different indexes for each contact. For the particular situation
of cluster G 2 in Figure 3.41, particle O 2 has index 2 with respect to its
contact G1 with particle 01, and index 1 with respect to its contact G2
with particle 0 3 . So, the net contact force actually applied to particle O 2
after all contact forces have been computed is

where PI and P2 are the contact forces associated with contacts G1 and
G2 ·

3.7 Particle-Rigid Body Collision Response


Whenever a particle-rigid body collision is detected, the collision-response
module is invoked to compute the appropriate collision impulses and con-
tact forces that will prevent interpenetration. As explained in Section 3.4,
the trajectories of the colliding particles are traced back in time to the
moment before the collision. The rigid body is not moved from its current
position, which happens to be its position at the end of the current time
step after any and all rigid body-rigid body collisions were resolved.
In this book, we model the particle-rigid body collision as the particle
colliding with another particle on the rigid body's surface. The advantage
of doing so is that we can reuse most of the results obtained for the particle-
particle single or multiple collisions or contacts developed in Section 3.6.
3.7 Particle-Rigid Body Collision Response 135

More specifically, there are only three main modifications that we need to
make before we can reuse the equations already derived for the particle-
particle collision and contact cases.
The first modification consists of making the mass of the particle on the
rigid body's surface be the same as the rigid body's mass. For example, if
particle 0 1 is colliding, or comes in contact with, particle O 2 on the rigid
body's surface, then we make m2 be the rigid body's mass. Clearly, this
modification induces no changes on the equations already derived for the
particle-particle cases.
The second modification requires that both velocity and acceleration of
the particle on the rigid body's surface be computed using the rigid body's
dynamic equations covered in Section 4.2 of Chapter 4. Unlike the parti-
cle's dynamics, the rigid-body motion has to take into account rotational
motion, making its dynamic equations much more complex than those de-
rived for particles in Section 3.2. Therefore, this modification will cause
some changes on the particle-particle collision and contact equations, as
will be explained in Sections 3.7.1 and 3.7.2.
The third and last modification involves the way the collision or contact
normal is computed. Even though the particle is colliding with another
particle on the rigid body's surface, the normal is defined by the rigid
body's geometry, as opposed to being the line connecting both particles.
This is done as follows.
Let 0 1 be the particle colliding or in contact with rigid body B 1 • The
particle O 2 on the rigid body's surface can be an interior point, a point on
an edge, or a vertex of the rigid body's triangle primitive being intersected
by 0 1 's trajectory. So, if 02 is in the interior of the triangle, then the
triangle's normal is taken as the collision or contact normal. If O2 lies on
an edge of the triangle, then the edge's normal is taken as the collision
normal. Notice that the edge normal is computed as the average of the
normals of the triangle faces that share the edge. Lastly, if O 2 lies on a
vertex of the triangle, then the vertex's normal is selected as the collision
or contact normal. The vertex's normal is computed as the average of the
normals of all triangles that contain the vertex.
If the particles are colliding, then the normal direction is selected such
that
('ih - V2) . n < 0 ,
that is, the particles are moving towards each other before the collision.
Notice that this may require changing the direction of the normal computed
from the triangle normal, edge normal or vertex normal if V2 > VI, that is,
if the rigid body is moving faster towards the particle, as opposed to the
particle moving faster towards the rigid body. On the other hand, if the
particles are in contact, we have
136 3. Particle Systems

and the normal direction remains unchanged (Le., pointing outwards the
rigid body's surface).

3.7.1 Computing Impulsive Forces


The computation of impulsive forces for the particle-rigid body collision is
very nearly the same as that described for the single or multiple particle-
particle collision. As mentioned, the main modifications are on the com-
putation of the velocity of particle O2 located on the rigid body's surface,
and the collision normal.
Consider the situation illustrated in Figure 3.42. Particle 0 1 is about to
collide with particle O 2 on the rigid body's surface.

FIGURE 3.42. Particle 0 1 is colliding with rigid body Bl at 02. The velocity
V2 and acceleration a2 of point P2 are computed using the rigid body's dynamic
equations.

Let Mb be the mass of the rigid body, and Vb and Wb be the linear and
angular velocities of the rigid body just before the collision. The mass m2
of the particle O 2 is then set to

(3.97)
Its velocity before the collision is computed as the velocity of a point on
the rigid body (see Section 4.2 for more details), that is

(3.98)
where 1'2 is the distance between particle O2 and the rigid body's center of
mass given by
3.7 Particle-Rigid Body Collision Response 137

So, using equations (3.97) and (3.98) as the mass and velocity of particle
O 2 just before the collision, we can directly apply the single- or multiple-
collision equations and compute the collision impulse P1,2 associated with
the collision of particles 0 1 and O2 .
The dynamic state of particle 0 1 is then updated with the application of
the collision impulse P1,2. However, recall that the update on the dynamic
state of the rigid body owing to the impulse P1 ,2 is postponed to the next
simulation time step. Therefore, for each simulation time step, we need
to sum all collision impulses acting on rigid body Blowing to one or
more particle-rigid body collisions, and apply the resultant impulse at the
beginning of the next simulation time step, as if all collisions happened at
that time. As explained in Section 3.4, this is an approximation used to
improve the overall simulation efficacy.

3.1.2 Computing Contact Forces


The computation of the contact force between a particle and a rigid body
follows the same principles explained in the computation of a particle-
particle contact. More specifically, the particles should not interpenetrate,
the contact force should not prevent contact from breaking apart, and the
contact force should be set to zero if contact is about to break. Translating
these conditions into equations, we have that the relative acceleration of
the particles at the contact point should be greater than or equal to zero,
the contact force should be greater than or equal to zero, and the contact
force should be zero if the relative acceleration is positive, or it should be
positive if the relative acceleration is zero.
Again, we use the vector ij(t) = (ih - ih) . ii to compute the relative
acceleration of the particles at the contact point, given by

where tc is the instant when contact was established. Equation (3.99) is


the same as equation (3.74) rewritten here for convenience.
Clearly, the velocity ih and acceleration ih of particle O 2 should be
computed using the rigid-body dynamics equations covered in Section 4.2.
Moreover, since the contact normal is either a triangle normal, an edge
normal or a vertex normal, the time derivative of the normal vector should
also take into account the dynamics of the rigid-body motion. In other
words, the rate of change in direction of the normal vector is a function of
the linear and angular velocities of the rigid body.
Unfortunately, the derivation of these relations requires a significant
knowledge of rigid-body dynamics, which is only covered in Chapter 4.
Therefore, for the sake of clarity, we shall postpone the computation of the
contact forces between a particle and a rigid body until Section 4.9. By so
138 3. Particle Systems

doing, the reader will have a chance to assimilate the concepts of rigid-body
dynamics necessary to understand the contact-force computations.

3.8 Particle Emitter


The particle emitter is used to create and release particles in the simulated
environment. Usually, particle emitters are implemented as an invisible
planar quadrangular surface that can be attached to other objects in the
simulation, or be used as a stand-alone object, in which case it can be
displayed attached to a default cube (see Figure 3.43).

(a) (b)

FIGURE 3.43. (a) In most cases, particle emitters are represented by a planar
quandrangular face. The grid is created from the size of each particle and the
total number of particles to be released at a time; (b) In the stand-alone version,
a default cubic object can be created, and the particle emitter is attached to its
top face.

The actual emission of particles in the simulated environment is not as


straightforward as it may seem. Some precautionary measures should be
taken to avoid unnecessary implementation problems. For example, the
particle-particle collision-detection module checks for geometric intersec-
tions of the particles' trajectories as the system evolves. It relies heavily
on the fact that the particles are not intersecting at the beginning of the
current time step, that is, at the starting point of their trajectories, so that
the trace back in time can always detect a state wherein the particles are
not intersecting. So, if the particles are created in such a manner that they
overlap each other right from the start, then any particle-particle collisions
detected immediately after they are released cannot be resolved using the
collision-detection techniques presented in this book. The approach fails
because the trace back in time is unable to reach a state wherein the par-
ticles are not intersecting. Therefore, we do need to assure that particles
not be overlapping each other at the time they are released.
Also, it is a good idea to establish a clearance region around the emitter
surface to prevent situations in which an object is placed on top of the
3.8 Particle Emitter 139

emitter and the particles either jam immediately after they are released,
or simply cannot be released at all. This is illustrated in Figure 3.44.

Particles not added to


simulation

o 0 0
0 00
0000
00 0

FIGURE 3.44. Object B is partially obstructing the emitter surface E . Particles


created on the obstructed area are not added to the simulation.

Our approach to these practical problems is as follows. Every time a


new round of particles is released, the particles just created are checked for
intersections with other particles already released, as well as rigid bodies
that are in the same world-cell decomposition as the emitter. Whenever an
intersection is detected, the particles just created are immediately removed
from the simulation. In other words, the emitter will only add new particles
to the system if there is enough room for them.
Clearly, this approach requires that we know the position on the emitter
surface at which each particle is released. In order to do so, we consider
a grid decomposition of the emitter surface such that a single particle is
released at the center of each cell of the decomposition.
Let d be the desired diameter of the spheres representing the particles
being emitted, and let nt be the number of particles simultaneously released
at a time. The dimension of each cell in the decomposition is then

fs = 2d v'ni (3.100)

for a square emitter surface, where the factor of 2 is used to allow for some
extra space between each particle positioned at the center of its associated
cell.
Another practical problem that should be considered when emitting par-
ticles is that in most cases the particles should not behave exactly like each
other. For instance, the introduction of some variations on size, speed and
direction of movement of each particle often makes the particle system look
and feel more real. In our approach, we define a set of user-adjustable para-
meters to control the dynamic behavior of the particles being emitted. For
each parameter, we define its mean value and deviation. So, for example,
a particle system with particles of size four and deviation two will have
140 3. Particle Systems

particles with size ranging from two to six, and average size of four. The
actual size of each particle can be dynamically computed assuming a nor-
mal probability distribution for each parameter. Equation (3.100) should
then be modified to accommodate this deviation on size.
Each time new particles are released, we need to compute their maximum
diameter dmax . Notice that the value of dmax will probably vary from con-
secutive releases, that is, the emitter grid dynamically grows and shrinks
to the appropriate size before each release. The dimensions of each cell in
the decomposition is then dynamically obtained from

is = 2 dmax ,,;n; . (3.101)


This in turn minimizes the risk of having particles just released inter-
secting each other.

3.B.1 User-Definable Parameters


The desired dynamic behavior of the particle system can usually be ad-
justed through a set of particle parameters. Each parameter is defined by
its nominal (Le., mean) value and an optional deviation value. Here, we pro-
vide a list of default parameters commonly found in animation packages
to set up particle-emitter properties. Other parameters used to implement
specialized particle systems we cover in Section 3.9.1.
1. Particle size
Defines the diameter of the spheres representing the emitted particles.
2. Particle mass
Defines the mass of each particle.
3. Particle age
Defines the age of a particle. This parameter is used to determine the
maximum time interval the particle will exist in the simulation, in
case the particle resilience parameter is set to true.
4. Particle resilience
Regulates whether particles that exist for a time span longer than
their age should be removed from the simulation.
5. Emitter size
Limits the maximum size of the emitter surface. If the size computed
using equation (3.101) turns out to be greater than this value, then
the number of particles simultaneously released is reduced to
3.8 Particle Emitter 141

where (fs)max is the maximum size of the emitter surface and nr is


the actual number of particles being released.
6. Emission velocity
Defines each particle's velocity at time of emission.
7. Emission direction
Defines the direction in which the particles will move as soon as they
are released.
8. Emission delay
Controls the time interval between two consecutive emissions, as a
multiple of the simulation time step being used. For example, if the
delay is set to three, then the emitter will skip two simulation time
steps, and will emit particles ·again only on the third time step after
the last emission.
9. Emission rate
Defines the number of particles emitted at each emission. Notice that
the maximum possible emission rate is constrained by the emitter
size.
10. Maximum emission
Defines the maximum number of particles emitted by this source. This
is required not only to limit the overall number of particles being used
in the simulation, but also to simulate effects such as smoke resulting
from a fire being dissipated after the fire is out.
11. Particle spawn
Regulates whether particles that were removed from the simulation
should be reused by the emitter. If set to true, then the interpretation
of the maximum emission parameter will be slightly different than
its default interpenetration. In this case, the maximum emission pa-
rameter will regulate the total number of particles emitted by this
source that are active in the simulation. (Active here means that the
particle's lifespan has not yet reached its age.)
12. Collision detection
This flag is used to indicate whether particle collisions should be
taken into account during the simulation. The flag can turn on and
off internal, external and complex collisions. Recall from Section 3.4
that internal collisions refer to collisions between particles emitted
by the same particle system. External collisions indicate that colli-
sions between particles emitted by different particle systems should
be taken into account, whereas complex collisions refers to collisions
142 3. Particle Systems

between particles and rigid bodies. Notice that there is no deviation


value associated with this parameter.
13. Particle static friction
Defines the static-friction coefficient of the particle when in contact
with other particles and rigid bodies. The actual static-friction co-
efficient used in the computations is the average value of the static
friction assigned to each of the contacting particles and rigid bodies.
14. Particle dynamic friction
Defines the dynamic-friction coefficient of the particle when in contact
with other particles and rigid bodies. The actual dynamic-friction co-
efficient used in the computations is the average value of the dynamic
friction assigned to each of the contacting particles and rigid bodies.
15. External forces
Defines a list of external forces globally applied to all (and only) par-
ticles emitted from this source. For example, this listing can be used
to define a viscous drag force to simulate air resistance, add gravity
to pull the particles towards the ground, or to force all particles to
have a default movement along a specific direction, as happens when
modeling rain falling diagonally to the ground.

3.9 Specialized Particle Systems


In this Section, we shall discuss some specialized particle systems com-
monly found in animation packages. The idea behind such systems is to
swap accuracy of the physical modeling of the particles' interactions for
overall system efficiency without sacrificing the look of the simulation. For
example, instead of using the Navier-Stokes equations to simulate vapor
leaving a cup of hot water as a turbulent gas, we obtain the same effect
by using a set of user-definable parameters to adjust some properties of
the particle system representing the vapor. The result is a simulation that
has a behavior similar to the hot turbulent gas modeled by the actual
physics-based equations, but using a simpler mathematical framework.
There are two main reasons to include this and the previous sections
in this book, despite the methods used not being based on the accurate
physical modeling of the particles' interactions. First of all, these special-
ized systems are very popular among computer graphics practitioners and
animators, and we feel that this chapter would be incomplete without men-
tioning such systems. Besides, discussing in detail the mathematical frame-
work needed to precisely model these f;ystems, which require specialized
forms of equations of motion and force interactions, is beyond the scope of
this book.
3.9 Specialized Particle Systems 143

Secondly, we want to make the point that the physics-based particle-


dynamics and collision-detection and response modules developed here can
be used in these systems as a fast and reliable way to evolve the particles'
trajectories over time. The benefit of doing so from the object-oriented
point of view is that particles and rigid bodies can use the same under-
lying simulation engine. This includes using the same numerical meth-
ods, collision-detection algorithms and collision-response-force computa-
tions. Particles and rigid-body objects can then be derived from a common
parent class, and the shared functionality can be implemented as virtual
methods of the parent class. So, as far as the simulation engine is concerned,
virtual methods on the parent class are invoked and the appropriate particle
or rigid-body behavior is obtained. In other words, the simulation engine
makes no distinction between particles and rigid bodies when advancing
the system by one more time step because it only manipulates their parent
class's objects.

3.9.1 User-Adjustable Parameters


The set of particle system parameters presented here is intended to com-
plement the set already presented in Section 3.8.1 with new functionality
needed to create visual effects like smoke, rain, jet flows of water, and
explosions. Notice that these parameters are used to mimic the coarse be-
havior of such systems without having to solve the sophisticated equations
of motion associated with the simulation of gases, liquids and explosions 12 •
As mentioned in Section 3.1, the detailed explanation of the theoretical
framework needed to capture the precise behavior of such specialized sys-
tems is beyond the scope of this book. The interested reader is referred to
Section 3.10 for pointers to the literature wherein in-depth explanations of
such techniques can be found.

1. Particle split
Indicates whether particles can generate new child particles. This
parameter, combined with the age parameter, lets users create several
interesting effects, such as air being burned by a rocket launcher and
the smoke getting first more dense, then dispersed in air a few seconds
later.
2. Particle-split number
Defines the total number of child particles that will be created by
their parent after each split.
3. Particle-split age

120ur approach is the same as that commonly used in most animation environments
where parameters are fine tuned to achieve the desired visual effect.
144 3. Particle Systems

Defines the age of the particle at which it will start to create its
children. This age should be less than the particle age.

4. Particle-split delay
Defines the time interval between two consecutive splits, as a multiple
of the simulation time step. For example, a split delay of two indicates
that, after the particle-split age has been reached, the particle will
create new child particles every other simulation time step.

5. Particle-split depth
Defines the maximum number of splits a particle may have.

6. Particle-split velocity
Defines the percentage value of the parent's velocity inherited by its
children at the time of the split.

7. Particle-split direction
Defines a maximum deviation from the parent's direction inherited
by its children at the time of the split. The deviation is used to spread
the children round their parents, along the direction of movement.

8. Particle-split size
Defines the percentage value of the parent's size inherited by its chil-
dren at the time of the split.

9. Particle-split lifespan
Defines a maximum deviation from the parent's age inherited by its
children at the time of the split.

10. Motion trail


Regulates whether particles should leave a motion trail behind them.

11. Motion-trail age


Defines the amount of time the motion trail remains visible. The
"motion trail" particles are then removed from the simulation as soon
as this time expires.

12. Color evolution


Defines a sequence of RGB color intensities of the particle over its
lifetime. A time value is associated with each element of the color
sequence, such I.that the color changes as soon as its corresponding
time has been reached. For example, a color evolution of the form
(R, G, B, t) with the values
3.9 Specialized Particle Systems 145

{(1.0, 1.0, 1.0,0.0), (0.6,0.6,0.6,2.0),


(0.3,0.3,0.3,4.0), (0.0,0.0,0.0,7.0)}

assigns an initial white to the particle, then changes it to gray after


two seconds, changes it again to light gray at four seconds from the
previous change, and lastly sets it to black when seven seconds have
passed from the last change.

13. Particle electrical charge


Defines the electrical charge of the particle; useful when electrical
force fields are used as external forces acting on the particle system.

There are several ways to create the visual effect of smoke using the
particle system parameters described so far. We can define a large number
of particles with small mass and size, and set up an external force that
makes the particles flow from the emitter in the desired direction to form
the column of smoke. Notice that there is no need to define gravity in
these systems; only a viscous-drag force to compensate for the acceleration
increase owing to the external force being applied.
Particles should be assigned a large value for their age, such that the
column of smoke can rise slowly over time without disappearing too soon as
it rises. On the other hand, the split age should be set fairly soon compared
with the particle's age so that the smoke starts dense near the emitter. The
dissipation is regulated by the deviations in size, velocity and direction of
the split. These deviations should be set to small values such that the
column of smoke remains concentrated along the direction of movement
near the emitter and opens up like a cone as the particles move away from
it, that is, as their deviation values accumulate to significant values after a
certain number of splits.
When we are creating the visual effect of smoke from a fire, the particles
can be set to an initial RG B color intensity of yellow, then change to orange,
then to dark gray and finally to black. The time span used for each color
depends on the desired visual effect for the intensity of the fire and the
material being burned. The material generally determines how quickly the
smoke turns black or dark gray.
The type of visual effects involving liquids that can be created using the
specialized particle-system framework described in this book is limited to
liquids that can be effectively represented by their drops. This includes
rain, sprinklers and jet flows of water.
In the case of rain, the emitter surface should be set as large as necessary
to cover the area where the rain will fall. The size of the particles (i.e., rain
drops) should be kept small, unless you want to create the effect of a sum-
mer thunderstorm or hail-storm. The number of particles used combined
146 3. Particle Systems

with the particle's velocities defines the intensity of the rain. A small num-
ber falling slowly characterizes a light rain, whereas a large number falling
fast resembles a tropical rain. The direction of the rain can be set using an
appropriate external force to pull the particles down, as opposed to using
gravity. Again, viscous drag should be used to counter balance the acceler-
ation increase owing to the external force and give the impression the rain
is falling at constant speed. Also, there is no need to split the particles or
change their color.
In the case of sprinklers, the mass of the particles and their initial veloc-
ity defines the maximum height the particles will reach along their entire
trajectories. Notice that the trajectory will be parabolic if we consider only
gravity as the external force. The deviation is used to control the "aperture"
of the sprinkler. Small deviations force the particles to be concentrated near
the emitter, whereas large deviations make the particles disperse all around
the emitter. Particles mayor may not be split, depending on the desired
volume of liquid being simulated.
Jet flows are similar to sprinklers. The main difference is that the initial
velocity on jet flows is usually considerably higher than the velocity used
to model sprinklers. Also, the deviation is maintained as small as possible
to force the particles to stay close together during their motion. When we
use jet flows to push rigid bodies through the simulated environment, we
should use a moderate number of particles with increased mass values so
that the net reaction force to the impact of the particles on the rigid body
is large enough to move it.
The visual effect of explosions can use either a planar or spherical emit-
ter surface, depending on what is being exploded. For instance, if we are
simulating the explosion of a grenade, then we can safely use the planar
emitter with a large number of particles of small size, short lifespan and
large deviation. The splitting of particles is usually over used in these explo-
sions, since we want to form a dense cloud immediately after the explosion.
The particle's age is then used to control how fast the cloud will dissipate.
There is no need to use external forces in these effects.
The spherical emitter is useful if we are creating the visual effect of
fireworks, or the explosion of an artifact in a game environment. The idea
is the same as that presented for planar emitters. The sphere's surface
is decomposed into a grid where each cell releases one particle at a time
along its radial direction. The direction deviation is then used to vary the
emission direction with respect to the nominal radial direction. Also, the
initial velocity deviation can be used to obtain an uneven cloud of particles.

3.9.2 Overview of Cloth Simulation


One possible way of simulating objects made of cloth is to use a com-
bination of particles and springs to model the local deformations of the
cloth as it moves. In this context, the cloth surface is represented by a
3.9 Specialized Particle Systems 147

uniform rectangular grid with each vertex being assigned to a particle.


Neighboring particles are then strategically connected by springs to repre-
sent the stretch, shear and bend forces of the cloth. Figure 3.45(a) shows
a small cloth grid containing sixteen vertices. The stretch force is mod-
eled by springs connecting adjacent vertices of the grid, as illustrated in
Figure 3.45(b). The shear force is modeled by another set of springs con-
necting diagonally opposed vertices of the grid (see Figure 3.45( c)). Finally,
the bend force is modeled by a third set of springs connecting every other
adjacent vertex of the grid, as indicated in Figure 3.45(d). By changing
the stiffness of the three sets of springs, we can obtain the desired surface
property of the cloth being simulated.

9"---<;>---<?---9
I I I I
Q---4- -- ~--Q
I I I I
c!>---
I
-<>---Q.---Q
I I I
0 --.0.--.0..--0
(a) (b)

(c) (d )

FIGURE 3.45. (a) Rectangular grid representing a piece of cloth. The broken
lines connect adjacent vertices of the grid; (b) Stretch forces are represented by
springs connecting particle (i,j) to particles (i + 1,j) and (i,j + 1); (c) Shear
forces are represented by springs connecting particles (i,j) and (i + 1,j + 1),
and particles (i + 1, j) and (i,j + 1); (d) Bend forces are represented by springs
connecting particles (i,j) and (i + 2, j) , and particles (i,j) and (i,j + 2).

The collision detection between cloth objects and other particle or rigid-
body objects in the simulation follows the same principles already explained
in Section 3.4. The rectangular grid is internally decomposed into a trian-
gular mesh by simply connecting one of the diagonally opposing vertices of
each grid cell, say vertex (i,j) to (i+l,j+l). Particle-cloth and rigid body-
cloth collisions are detected by checking for geometric intersections between
the particle or rigid body with the triangular mesh. This intersection test
can be efficiently implemented if we consider a hierarchical tree represen-
148 3. Particle Systems

tation of the triangular mesh to prune out unnecessary primitive-primitive


intersection tests, as explained in detail in Chapter 2.
Self-intersections are also handled using the same technique. We first
check for intersections between the intermediate nodes at the first level of
the hierarchical tree, that is, between the two children of the root node (as-
suming a binary tree). If they do not intersect, then the cloth is guaranteed
to be not self-intersecting. Otherwise, we check for intersections between
the intermediate nodes at the second level of the three. We recursively
proceed checking for intersections between the intermediate nodes at the
ith level that have their parents intersecting at the (i - 1)-th level until
we reach the leaf nodes, or until no intermediate intersections are found.
Self-intersections exist only if there are primitive-primitive intersections
between the primitives associated with overlapping leaves of the tree. In
the case of rigid body-cloth intersections, the primitives are both trian-
gles, whereas in the case of particle-cloth intersections the primitives are
triangles and cylinders with a spherical cap, respectively.
Whenever a collision is detected, the appropriate impact or contact forces
are computed and applied to the cloth particles associated with the vertices
of each intersected triangle according to the following rules. If the contact
point is a vertex of the triangle, then the force is applied only to the particle
associated with that vertex. If the contact point is on an edge of the triangle,
then half the force is applied to each particle forming the edge. Otherwise,
if the contact point lies inside the triangle, then one third of the force is
applied to each of the three particles of the intersected triangle. Also, notice
that, since all particles in the cloth are interconnected with their neighbors,
we shall need to solve a linear system of the same order of magnitude as
the total number of particles defining the cloth surface for each simulation
time step. So, as we attempt to obtain more realistic simulation results
by increasing the number of particles used to represent the cloth object,
computational time per simulation time step increases considerably, thus
reducing the overall efficacy of the simulation.
Another common problem observed when modeling cloth with a spring-
particle system is that the system of equations of motion can become stiff,
especially when one of the spring constants used is orders of magnitude
different from the others. One way of minimizing this stiffness is to use a
numerical-integration method appropriate to such situations; see the im-
plicit Euler method discussed in Appendix B.
There is also one more problem worth mentioning when modeling cloth
as a spring-particle system. In some situations, one or more springs can end
up being elongated to extremely high values, sometimes as large as twice
their resting displacement. This might be acceptable if we were simulating
an actual spring-mass system, but such super elastic behavior is unrealistic
in the case of cloth. The problem is that the stretch and shear forces of
real woven fabrics vary non-linearly with the distance between their fibers,
such that the resistance increases very rapidly as a function of the relative
3.9 Specialized Particle Systems 149

displacement of the fibers until either the movement stops, or the fabric
fails to withstand the force, and ruptures.
One way of preventing this super-elastic behavior would be to dynami-
cally increase the stiffness of the springs being stretched or sheared above
a threshold limit, such that the spring resistance dramatically increases in
these cases to prevent further elongation. Unfortunately, this is not prac-
tical because the dynamic increase of the spring resistance can introduce
stiffness into the numerical integration, forcing it to reduce the size of the
simulation time steps being taken, and thus adversely affect the overall
simulation. As a matter of fact, there are situations in which the time step
can be reduced to such a small value that the simulation seems to be halted
forever.
Another way to deal with the super-elastic effect without having to
change the stiffness of the springs is to set up a maximum spring defor-
mation and dynamically enforce it during the simulation. The maximum
deformation should be set as a percentage of the resting size of the spring.
We can assign a maximum deformation for the stretch, shear and blend
strings, although the latter is usually not considered because real cloth
objects have no significant limits on how much they can be bended. Also,
because the particles are laid out as vertices of a uniform rectangular mesh,
we set the shear and stretch maximum deformations be the same. This last
assumption can considerably simplify the enforcement of the maximum-
deformation condition because we shall always be able to ignore the elon-
gation of the stretch springs, and only consider the elongation of the shear
springs diagonally placed on each rectangular cell of the grid, as shown in
Figure 3.45{c). In other words, the stretch deformation is automatically
enforced whenever we enforce the shear deformation.
This approach of enforcing maximum deformations can be implemented
as follows. On a first pass, the spring forces are computed as usual, that is,
from the initial displacement of their associated particles. The net force act-
ing on each particle is then computed by summing the spring forces acting
on the particle with any other external forces, as appropriate. The particles
are moved according to the results obtained from the numerical integration
of their equations of motion, and their associated springs are stretched and
compressed accordingly. Then, on a second pass, the displacement of each
shear spring is checked against the maximum allowable spring deformation.
If the shear spring is elongated more than the maximum allowable defor-
mation, then its associated particles are brought up close together to the
point where the spring displacement is equal to the maximum deformation
allowed. Figure 3.46 shows how the particles are moved together without
violating the direction of motion obtained from the numerical integration.
Consider a shear spring connecting particles P and Q located at positions
fit and ifl at time t = to. The current spring elongation is d l < d max , where
dmax is the maximum deformation allowed. The particles are then moved
to positions P2 and ih at time t = (to + h), and the spring is stretched to
150 3. Particle Systems

p
Q

~ r-----__~d~m________J

FIGURE 3.46. The shear spring connecting particles P and Q is elongated above
its maximum deformation value from time t = to to t = (to + h). We need to
determine positions Pm and ifm at which the elongation d m equals its maximum
value dmax •

a size d2 > dmax . The problem is then to find the intermediate particle
positions Pm and ifm along their direction of motion, at which the spring
elongation is dmax .
Since the particles' path is approximated by a straight line connecting
their initial and final positions, the intermediate point Pm belongs to the
line segment connecting Pl and P2, that is

(3.102)
where 0 ~ tp :S 1 is a scalar variable to be determined. Analogously we
have

(3.103)
with 0 ~ tq ~ 1. Notice that, since the particles are moved from their initial
to their final positions within the same simulation time step, we have

= tq .
tp (3.104)
The distance dm between Pm and ifm is computed as

2 = 1Pm
dm - -qm
- 12 . (3.105)
Substituting equations (3.102) and (3.103) into (3.105), and using equa-
tion (3.104), we have

d~ 1(Pl + tp (P2 - pt}) - (it + tq (ch - Qi)) 12 _


1(Pl - Q't} + tp ((P2 - ch) - (Pl - (ft)) 12
1kl
-
+ t k21
- 2
3.9 Specialized Particle Systems 151

((kl)x + t (k 2)x)2 + ((kd y + t (k2)y)2


+ ((kdz +t(k2)z)2,

where ki = (PI - qi) and k2 = ((P2 - 1]2) - (PI - qi)) are known vectors.
We want dm = dmax , that is, we need to salve the quadratic equation

(kd; + (kd~ + (kd; - d;'ax +


2 ((kdx (k2)x + (kl)y (k2)y + (kl)z (k2)z) tp +
((k2); + (k2)~ + (k2);) t; = 0 (3.106)

for tp. Let (tph and (tph be the two possible solutions for equation (3.106).
If both solutions arc less than zero, then the initial elongation d l is greater
than dmax , which contradicts the fact that the maximum deformation is en-
forced on every time step (Le., if d l > dmax , then the maximum deformation
enforcement would have been applied to the particles during the previous
simulation time step). Also, if both solutions arc greater than one, then the
final elongation d2 is less than dmax , which contradicts the fact that the
maximum-deformation condition has been violated. If just one of the solu-
tions, say (tph, is between zero and one, then we set tp = (tph. Otherwise,
if both solutions are between zero and one, say 0 :::; (tph :::; (tph :::; 1, then
we select the largest solution, that is, we set tp = (tph. Having determined
the parameter t p , we substitute its value on equations (3.102) and (3.103)
to obtain Pm and ifm, respectively.
The worst-case scenario for this procedure occurs when all shear springs
are already elongated at their limits at the beginning of the current time
step. In such situations, the particles are initially moved to their new posi-
tions at the end of the current time step, and some shear springs may have
been further elongated, and others compressed. The particles associated
with the springs that were elongated are then moved back to their ini-
tial positions. So, the computational time spent processing these particles
was wasted. However, in spite of this apparent inefficiency, the algorithm
is guaranteed to assure the maximum-deformation condition in just one
pass through all particles. Moreover, because we are moving the particles
backwards along their computed paths, any particle can be chosen as the
starting point.
One final remark: when we have multiple updates in the position of a
particle owing to several shear springs attached to it, the selected parameter
tp will be the minimum of all values obtained to enforce the maximum-
deformation condition at each shear spring. Again, this is possible because
we are moving the particles backwards along their computed paths, so that
each parameter tp obtained for different shear springs refers to the same
path. Therefore, they can be compared with each other, and selecting the
minimum value guarantees that all other conditions are satisfied.
152 3. Particle Systems

3.10 Notes and Comments


The idea of using particle systems as a modeling tool in computer graphics
was originally introduced by Reeves [Ree83]. Nowadays, particle systems
are so widely used to model diverse sets of systems that the large number
of different techniques, implementations and parameter settings available
makes it difficult to address this topic in depth.
From our experience, the selection of the particle system depends on
the application at hand. For instance, if you are working on molecular
dynamics, then you will probably be willing to trade efficiency for accuracy
in your models, and so you need to use a particle system that models the
details of particle interactions to a great extent. On the other hand, if your
concern is to get a visually appealing simulation of smoke coming out of a
fire, then you will probably need to use a flexible particle system that lets
you adjust the look of the simulation without worrying too much about the
underlying accuracy of the model.
Our approach in this chapter was to first provide the foundation needed
to implement accurate models of particle interactions based on classical
mechanics, then extend our model with some user-definable parameters
commonly found in animation packages to support a diverse set of spe-
cialized particle systems. Frenkel et al. [FS96] also used the mathematical
foundation of classical mechanics to model several molecular-dynamics sys-
tems. The types of force interactions described in Section 3.3 were inspired
from the work of Frenkel and Baraff et al [BW98a]. A detailed discussion
on under, over and critically damped spring systems can be found in Beer
et al. [BJ77b].
The particle-particle collision detection representing the particle's trajec-
tory as a cylinder with spherical cap was originally proposed by Karabassi
et al. [KPTB99]. The cylinder-cylinder, cylinder-sphere and cylinder-line
segment intersection tests were obtained from Held [HeI97]. The cylinder-
box intersection test presented in Section 3.5.2 was adapted from Held's
cylinder-triangle intersection test. However, the actual cylinder-triangle
test used in Section 3.5.4 was suggested by Karabassi.
The use of a critical-coefficient-of-friction value to determine whether the
particles are sliding at their collision point was obtained from Brach [Bra91].
This in turn allows us to express the multiple particle-particle collision
case in a concise block-partitioned matrix representation, which can be ef-
ficiently solved by Gaussian elimination, or by a specialized sparse-matrix
solver routine. The mathematical foundation used to derive the single and
multiple contact equations was adapted from Baraff et al [BW98a], which
dealt with rigid body-rigid body contact-force computation.
Several parameters used in Section 3.9 were inspired from commercial
software packages, such as Visviva's Animation Engine and SoftImage's
Particle System. The suggested parameter settings for simulating smoke,
liquids and explosions were obtained by trial and error.
3.10 Notes and Comments 153

The cloth model was by far the most demanding. The model presented
in Section 3.9.2 is very similar to that proposed by Provot [Pro95, Pro97].
The main differences are in the collision-detection and response techniques
used, and in the way the particles are moved back to enforce the spring's
maximum deformation condition. There are, however, other models that
could be used to simulate cloth. These derive from the work of Baraff et
al. [BW99], Breen et al. [BHW94], Demetri et al. [DJAK87] and Michel et
al. [CYND92], to name a few.
Lastly, the mathematical theory of the Navier-Stokes equations and the
physics of the conventional theory of turbulence can be found in Wilkins
[Wil99], Starn et al. [SF95, Sta99] and Foster et al. [FM96, FM97]. An
introduction to the Chapman-Jouget theory used to model detonation of
explosives can also be found in Wilkins [Wil99].
4
Rigid- Body Systems

4.1 Introduction
Rigid-body dynamic simulations are by far the most interesting ones, with
applications ranging from mechanical-systems design and prototyping, to
robotic motion, to physics-based computer-graphics animations. A rigid
body is modeled as a collection of particles that make up its geomet-
ric shape. During motion, the relative position of each particle forming
the rigid body must remain constant so that its shape remains unchanged
throughout the motion. This requires taking into account the rotational mo-
tion of the rigid body, which in turn considerably complicates the derivation
of the equations of motion, the collision-detection techniques to be used,
and the computation of all impulsive and contact forces that prevent their
interpenetration during a simulation.
Here, we shall focus on both unconstrained and constrained motion of
rigid bodies. The unconstrained motion deals with the dynamic equations
that govern the free motion of a rigid body as a function of the net force
and net torque acting on it. By free motion we mean that the motion is
determined without worrying about collision detection and response. The
constrained motion, on the other hand, deals with the computation of all
impulsive and contact forces resulting from single or multiple collisions, or
contacts between two or more rigid bodies during a simulation. Notice that
the constraints considered in this chapter are imposed solely to prevent
interpenetration of the rigid bodies. In the next chapter, we shall study
other types of constrained motion where two or more rigid bodies are inter-

M. G. Coutinho, Dynamic Simulations of Multibody Systems


© Springer Science+Business Media New York 2001
156 4. Rigid-Body Systems

connected through joints that limit their relative degree of freedom, forcing
them to stay "connected" throughout the entire simulation.
All algorithms presented in this book assume that a rigid body is given
by its boundary representation, that is, by the faces defining its geomet-
ric shape. From the boundary representation, we can compute the rigid
body's mass properties and convex decomposition, as explained in Appen-
dices D and F, respectively. The mass properties of a rigid body are used
in the dynamic-equations formulation presented in Section 4.2. The convex
decomposition can be used to speed the collision-detection phase using spe-
cialized algorithms tailored for convex objects, as discussed in Section 4.4.
Also, we assume that the faces describing the rigid body geometry are all
triangular. This is not a limitation, since the faces can be efficiently tri-
angulated during the convex-decomposition computation (see Appendix F
for details).

4.2 Rigid-Body Dynamics


The dynamic equations that govern the motion of a rigid body need to
capture both translational and rotational effects owing to external forces
acting on it. Moreover, the rigid body's motion is influenced not only by
the external forces, but also by its shape and mass distribution. The former
defines a set of variables known as the rigid body's mass properties.
The mass properties of a rigid body are its volume, total mass, center
of mass and inertia tensor. The inertia tensor is the equivalent of the total
mass for rotational motion. That is, in the same way that the mass is used to
relate the linear acceleration with the net external force, the inertia tensor
is used to relate the angular acceleration with the net external torque acting
on the rigid body. The mass properties can be directly computed from the
rigid body's boundary representation, as explained in detail in Appendix D.
The boundary representation of a rigid body is usually given with respect
to a local-reference frame known as the body frome. The mass properties
of the rigid body are therefore computed with respect to this local frame.
Scalar quantities, such as the rigid body's mass and volume, are indepen-
dent of the reference frame being used. However, the position of the center
of mass and the inertia tensor are affected by the choice of reference frame.
Let F1 be the body frame associated with the rigid body B 1 , and let
F be the world frame used in the simulation. Also, let the body frame be
rotated by R(t) with respect to the world frame at time t. This is illustrated
in Figure 4.1.
As mentioned in Appendix D, the inertia tensor is computed using a
body frame that is parallel to the world frame, but has its origin at the rigid
body's center of mass. The main advantage of using such body frame is that
4.2 Rigid-Body Dynamics 157

(a) (b)

FIGURE 4.1. (a) Rigid body positioned and oriented with respect to its body
frame; (b) Same rigid body described with respect to the world frame.

the transformation between the inertia tensor from body-frame coordinates


to world-frame coordinates is reduced to

I(t) = R(t) Ibody(t) Rt(t) . (4.1)


Given the position of a point ih on the rigid body expressed in body-
frame coordinates, its corresponding position p( t) with respect to the world
frame is then computed as:

p( t) = R( t ) PI + r( t ) (4.2)
where r(t) is the position of the center of mass of BI with respect to F at
time instant t. Notice that PI is computed with respect to the body frame
FI, which moves with the body. Thus PI is a constant vector over time.
The actual motion of the body with respect to F is encoded in the rotation
matrix R(t) and the translation vector r(t).
The velocity of p(t) is obtained by computing the time derivative of its
position vector, namely
dfi(t) _ dR(t) _ R(t) dPI dr(t)
dt - dt PI + dt + dt .
Since PI is a constant vector, we have
dp(t) dR(t) _ dr(t)
---;u- = ~ PI + ---;u- . (4.3)
Let v(t) be the linear velocity of the center of mass of body BI with
respect to F. Thus,

dr(t) __( )
dt -v t . (4.4)
Also, let w(t) be the angular velocity of body BI with respect to :F.
According to Section E.5 of Appendix E, the time derivative of the rotation
matrix is given by
158 4. Rigid-Body Systems

d~?) = w X R(t) = w(t) R(t) , (4.5)

where w(t) is the matrix-vector representation of a cross-product, described


in Section A.7 of Appendix A. Substituting equations (4.4) and (4.5) into
(4.3), we obtain
d ~(t)
~t = w(t) R(t) fli + v(t) .

Using equation (4.2) we get

dfl(t)
w(t) R(t) R(t)-I(fl(t) - r(t)) + v(t)
dt
w(t) (fl(t) - r(t)) + v(t)
w(t) x (fl(t) - r(t)) + v(t) . (4.6)

Equation (4.6) gives us a way of computing the velocity of any point


fl(t) in the rigid body. Finally, the acceleration of point fl(t) is obtained by
computing the time derivative of its velocity vector, namely

d2 fl(t)_dw(t)
- - - - - x (~() ~()) +wt
pt -rt ~() x (dfl(t)
---- dr(t))
- dv(t) .(47)
+-- .
dt 2 dt dt dt dt
Let a( t) be the linear acceleration of the rigid body's center of mass, that
is

a(t) = dv(t)
dt
and let a(t) be the angular acceleration of the rigid body defined as

~( ) _ dw(t)
at - dt .

Notice that both linear and angular accelerations are expressed in world-
frame coordinates. Substituting these into equation (4.7), we obtain

d2!t;t) = a(t) x (p(t) - r(t)) + w(t) x (w(t) x (fl(t) - r(t))) + a(t). (4.8)

Let F(t) be the net external force acting on the rigid body's center of
mass at time instant t. Using Newton's law, we have

F(t) = d~y) , (4.9)


4.2 Rigid-Body Dynamics 159

where L(t) is the linear momentum of the rigid body computed from

L(t) = mv(t) , (4.10)


with m and v(t) being the rigid body's mass and linear velocity of its center
of mass. Substituting equation (4.10) into (4.9), we have

F-( t ) -_ d (m v( t)) -m---mat.


_ d v( t) _ _() (4.11)
dt dt
A similar equation can be obtained relating the net torque f(t) acting
on the rigid body's center of mass, with the angular acceleration a( t). It is
known as the Euler equation and is given by

f(t) = d ii(t) , (4.12)


dt
where ii(t) is the rigid body's angular momentum computed as

ii(t) = I(t) w(t) , ( 4.13)


with I(t) being the inertia tensor expressed in world frame coordinates,
obtained from equation (4.1).
The angular acceleration a(t) is related to the angular momentum ii(t),
as follows. We already know that the angular acceleration is computed as
the time derivative of the angular velocity. Since equation (4.13) relates the
angular velocity and the angular momentum, we have

_( ) _ dw(t) _ d (I-l(t) ii(t)) _ dI- 1 (t) H-() I- 1 ( ) dii(t)


o:t- - - t+ t .
dt dt dt dt
Using equation (4.12),

a(t) = dI~;(t) ii(t) + rl(t) f(t) . (4.14)

From equation (4.1), the inverse of the inertia tensor is given by

( 4.15)
The time derivative of the inverse of the inertia tensor is then

dI- 1 (t)/ dt = d~?) (Ibody )-l(t) Rt(t) + R(t) (Ibody)-l(t) d~:(t)


= w(t) R(t) (Ibody )-l(t) Rt(t) + R(t) (Ibody )-l(t) (w(t) R(t))t
= w(t) R(t) (Ibody )-l(t) Rt(t) + R(t) (Ibody )-l(t) Rt(t) wt(t)
= w(t) R(t) (Ibody )-l(t) Rt(t) - R(t) (Ibody )-l(t) Rt(t) w(t)
160 4. Rigid-Body Systems

because (~;t(t) = -w(t). Using equation (4.1) again, we can simplify the
above expression to

rl(t) rl(t)
~ ____ ~A A

w(t) R(t) (I body )-l(t) Rt(t)' - R(t) (Ibody)-l(t) Rt(t)' w(t)


w(t) I-l(t) - I-l(t)w(t) . (4.16)
Substituting equation (4.16) into (4.14), we obtain

a(t) (w(t) rl(t) - I-1(t) w(t)) H(t) + rl(t) i(t)


w(t) rl(t) H(t) - I-1(t) w(t) H(t) + I-1(t) i(t)
wit)
~
w(t) rl(t) H(t) _I-l(t) w(t) H(t) + I-l(t) i(t)
wit) xw(t)=o
~ _I-l(t) w(t) H(t) + rl(t) i(t)
-rl(t) w(t) x H(t) + I-1(t) i(t)
rl(t) H(t) x w(t) + rl(t) i(t) . (4.17)
So, the relation between the angular acceleration and angular momentum
is expressed as

5(t) = I-1(t) (H(t) x w(t) + i(t)) , (4.18)


or alternatively

i(t) I(t) a(t) - H(t) x w(t)


I(t) 5(t) + w(t) x H(t) . (4.19)
Let y(t) denote the dynamic state of the .rigid body at time t, that is,
the vector comprising all variables necessary to define the dynamics of the
rigid body at any instant during the simulation. Since the rigid body's
motion can be sub-divided into translational and rotational components,
we shall pick the center of mass's position, the rigid body's orientation, and
its linear and angular momenta to define its dynamic state, namely

f'(t) )
_ R(t)
y(t) =
( ~(t) .
H(t)
So, the dynamic state of the rigid body at time t = to is defined by the
center of mass's position f'(to) , the rigid body's orientation R(to), its linear
4.2 Rigid-Body Dynamics 161

momentum L(to) computed as m iJ(to), and its angular momentum H(to)


computed as I(t) w(t).
The time derivative of the dynamic state defines how the dynamic state
of the rigid body changes over time, and is given by

df'(t)/ dt) ( iJ(t) )


dy(t) = ( d~(t)/ dt = w(t2 R(t)
dt dL(t)/ dt F(t)'
dH(t)/ dt "f(t)
So, the time derivative of the dynamic state at time t = to is defined
by the center of mass's velocity iJ(to) computed as (L(to)/ m), the updated
orientation w(to) R(to) with w(to) being computed as 1-1 (to) H(to), and
the net force F(to) and net torque "f(to) acting on the center of mass.
For a system with N rigid bodies, we can combine their individual dy-
namic states into a single system-wide dynamic-state vector

with its corresponding time derivative being

dY(t)
dt
(4.20)

The general description of how the dynamic simulation of rigid-body


systems work is very similar to the one already given in Chapter 3 for
particle systems. At the beginning of the simulation, we have the dynamic
state of each rigid body, namely its position, orientation and linear and
angular momenta defined with respect to the world-reference frame. Each
simulation time step consists of numerically integrating equation (4.20),
using the dynamic state of the rigid bodies at the beginning of the time
step as the initial condition for the numerical integration. There are several
numerical methods that can be used to integrate equation (4.20), and the
most popular ones are discussed in detail in Appendix B.
The computation of the net external force acting on each rigid body
at each intermediate step of the numerical integrator is determined by
summing all external forces acting on different points of the rigid body.
These forces are then substituted for a force-torque pair acting on the rigid
body's center of mass before they are used in the equations of motion. A
force Fi (t) acting at point Pi (t) is substituted for a force-torque pair

Fi(t)
(pi(t) - f'(t)) x Fi(t) ,
162 4. Rigid-Body Systems

where the (em) index stands for "center of mass." The types of external
forces considered in this book for rigid-body simulations range from simple
global forces (such as gravity) to point-to-point forces (such as springs),
and are discussed in detail in Section 4.3.
In a first pass, the determination of the dynamic state of each rigid body
at the end of the current time step is done without taking into account any
possible collisions between rigid bodies and other objects in the simulation
environment. The information about the final dynamic state of each rigid
body is then used on a second pass to check for collisions between them-
selves and other particles in the simulation. The collision detection consists
of checking for geometric intersections between the bodies positioned at the
end of the current simulation time step with all other bodies and particles
in the simulation. As explained in Section 3.4.2, the particular case of rigid
body-particle collision is handled only after all rigid body-rigid body colli-
sions have been detected and resolved. This is necessary because the rigid
body-particle collision model used in this book is such that, when a particle
collides with a rigid body, only the particle is traced back in time to the
moment before the collision.
Whenever a rigid body-rigid body collision is detected, the colliding rigid
bodies have their positions and orientations traced back in time to the
moment before their collision. The collision point and collision normal are
then computed from the relative displacement of the colliding bodies. Only
after this information is obtained does the collision-response module engage
to compute the appropriate impulsive or contact forces that will be applied
to change the direction of motion of the colliding rigid bodies.
The dynamic equations of all rigid bodies involved in a collision are then
numerically integrated for the remaining period of time, that is, from the
collision time to the end of the current time step. This new numerical inte-
gration will update the current rigid bodies' positions and orientations to
account for all collision forces. Notice that this also requires the numerical
integration of the dynamic state of all other rigid bodies connected to one
or more rigid bodies involved in a collision, since the connection usually
implies the existence of a force component between them. For example,
consider a simple rigid-body system consisting of four rigid bodies, namely
Bb B 2, B3 and B 4 , and suppose rigid bodies Bl and B2 are connected by
a spring.
Initially, the dynamic state of the system is numerically integrated from
ti (the beginning of the current time step) to t j (the end of the current
time step). Now, assume the collision-detection mod ule detected a collision
between bodies B2 and B3 at time tc such that ti < tc < tj (see Figure 4.2).
The colliding bodies are then traced back in time to the moment just be-
fore their collision (Le., traced back to t c ) and the collision impulses are
computed so as to prevent their interpenetration. Having applied the colli-
sion impulses to both bodies, their dynamic state is numerically integrated
again save for the remaining period of time only, that is, from tc to t j.
4.2 Rigid-Body Dynamics 163

FIGURE 4.2. A simple rigid-body system containing four particles. The dynamic
state of the system is numerically integrated from ti to t f. A collision between
bodies B2 and B3 is detected at time te.

\
\
\
\
\
\
\

I:--6
\ /

B2 (t,}

FIGURE 4.3. Bodies B2 and B3 are traced back in time to the moment just
before their collision.
164 4. Rigid-Body Systems

FIGURE 4.4. Body Bl is also traced back in time to tc before the numerical
integrator is used to recompute the positions and orientations of bodies B 1 , B2
and B 3 . Notice that body B4 was not affected by the collision, and therefore
remained unchanged throughout the collision-detection and response phase.

However, if we just trace back in time bodies B2 and B 3, the spring-force


computation between bodies Bl and B2 will be incorrect in the numerical
integration for the remaining period of time. The problem is that, since
body Bl was not involved in any collision, its dynamic state corresponds
to time t f' whereas the dynamic state of body B2 corresponds to time tc
at the beginning of the integration. So, if we do not trace back in time Bl
either, the spring-force computation will use B1's position and orientation
at time t f when it should use them at the same simulation time of B 2 ,
namely time tc (see Figure 4.3) . In other words, the numerical integration
of the dynamic state of all interconnected bodies should be synchronized to
provide the correct system behavior (see Figure 4.4). On the other hand,
bodies that are not involved in a collision can be asynchronously moved
within the same simulation time step. This is the case of rigid body B 4 , as
shown in Figure 4.4, since the numerical integration of B2 and B3 for the
remaining period of time did not affect its dynamic state already computed
in the first pass. As far as implementation is concerned, this approach re-
quires some bookkeeping mechanism to efficiently determine which rigid
bodies are connected to others. The payoff is the significant efficiency gain
over the alternate solution of tracing back in time all rigid bodies, even
those not involved in a collision, to the moment before the most recent
collision.
The updated information about the final dynamic state of each rigid
body involved in a collision is used to check again for collisions between
them and all other rigid bodies in the simulation. This process repeats until
all rigid body-rigid body collisions detected within the current time step
have been resolved.
4.3 Interaction Forces 165

Clearly, the collision check is an intense process that can take up a lot
of computational time, especially in a naive implementation. We suggest
using the cell decomposition of the simulated world already discussed in
Section 2.3 to speed the collision-detection checks. As the system evolves,
the position of each rigid body relative to the cell decomposition of the
simulated world is tracked by assigning the rigid body to the cells its hier-
archical representation intersects. By so doing, only rigid bodies assigned
to the same cell need be checked for collisions. This dynamic assignment
can be efficiently implemented by observing that the cell decomposition
defines a uniform subdivision of the simulated world into cubic cells (see
Section 2.3 for more details).

4.3 Interaction Forces


The interaction forces used in most rigid-body system simulations can be
categorized into two different types offorces. The first type considers global
interaction forces, that is, forces independently applied to all rigid bodies in
the system. Examples include gravity and viscous drag (used to simulate
air resistance). These are the least expensive interaction forces available
and their required computational cost is often negligible compared with
that of the second type of interaction forces discussed in this book.
The second type considers point-to-point forces between a specific num-
ber of rigid bodies. Damped springs are a good example of such interaction
forces between two given bodies. Interactive-user manipulation is also mod-
eled as a point-to-point force between the current mouse position and the
selected rigid body. The idea of using a fictitious interaction force between
the mouse and the selected rigid body is to prevent the introduction of
unstable configurations owing to abrupt mouse movements, as explained in
Section 4.3.4.

4.3.1 Gravity
The force contribution of gravity acting on each rigid body owing to its
attraction to the ground is directly obtained from

where 9 is the gravitational acceleration, m is the rigid body's mass and


F acts on the body's center of mass (see Figure 3.4). The gravitational
acceleration is in most cases assumed to have constant magnitude equal to
9.81 meters per second squared and downwards direction (Le., towards the
"ground" of the simulated environment.)
166 4. Rigid-Body Systems

FIGURE 4.5. Gravity pulling rigid body Bl with mass ml towards the ground
plane.

4.3.2 Viscous Drag


The most common use of viscous drag in dynamic simulations of rigid-body
systems is to model the air resistance to the body's movement. The goal
is to ensure that rigid bodies will eventually come to rest if there are no
other external forces acting on them. Figure 4.6 illustrates this. The force
component of the viscous drag is computed as

F= -kvv,
where v is the linear velocity of the rigid body's center of mass and kv is
the linear drag coefficient.

FIGURE 4.6. Rigid body Bl is moving in a random direction experiencing air


resitance modeled as viscous drag with force component F and torque component
T acting on Bl'S center of mass.

The torque component of the viscous drag is determined using a similar


formula given by
4.3 Interaction Forces 167

where wis the angular velocity of the rigid body and kw is the angular drag
coefficient.

4.3.3 Damped Springs


Springs are mostly used to keep the distance between pairs of rigid bodies
at a known value. Whenever the rigid bodies are pushed apart or pulled
together, a spring force is applied to both bodies, with same magnitude
and opposite direction.
Let Bl and B2 be two rigid bodies connected by a spring of resting
length TO. The spring is attached to bodies Bl and B2 at points PI and P2,
respectively. Let ih and ih be the velocities of points PI and P2, computed
using equation (4.6) On page 158. The spring-force component acting On
the center of mass of both rigid bodies is then given by

- - PI- I - ) + kd (V2 pd (fh - pd


- [k s (IP2 TO
- ) I(P2
- - VI - I] Ip2 - PI I
-P2 -- PI
(4.21)
fA -F2 ,

with ~ being the spring force acting On rigid body Bi for i E {I, 2}, ks being
the spring constant and kd being the damping constant (see Figure 4.7).
Since the spring force is applied to points PI and P2, it is substituted for a
force-torque pair (.F\ and 71) acting on body B 1 , and F2 and 72 acting on
body B 2 , with

(4.22)

The damping term of equation (4.21) is used to prevent oscillation, and


does not affect the motion of the center of mass of the connected bodies.

4.3.4 User-Interaction Forces


The user-interaction force is modeled as a damped spring connecting the
current mouse position to the position of the rigid body's point being
dragged. The idea of using this fictitious spring is to avoid the introduction
of unrealistically large external forces acting On the selected body owing
168 4. Rigid-Body Systems

(a)

(b)

FIGURE 4.7. Rigid bodies Bl and B2 are connected by a damped spring; (a)
Bodies at resting position; (b) Spring forces exerted on the rigid bodies when
they are pushed together.

to abrupt mouse movements. These large external forces can make the dy-
namic equations describing the rigid body's motion stiff. Stiff systems are
more susceptible to round-off errors and usually require the use of more
elaborate and time-consuming numerical-integration methods, such as the
implicit Euler method described in Appendix B.
The main difference between the damped spring described in Section
4.3.3 and the fictitious spring used here, is that the resting length of the
fictitious spring should be set to zero. A zero resting length means that
the selected rigid body will only stabilize its motion when its position is
coincident with the mouse position. Therefore, as the user drags the body
around, the current mouse position is used to update the actual distance
between the rigid body and the mouse. This distance is then used in equa-
tions (4.21) and (4.22) to compute the appropriate spring force-torque pair
to be applied to the rigid body's center of mass.

4.4 Collision Detection


Accurate collision detection on rigid-body dynamic simulations is much
more difficult to achieve than in particle systems because of a fundamen-
tal difference in modeling these systems. Particles are usually modeled as
simple spherical objects that can translate, but not rotate, during their
motion. Their trajectories therefore can be analytically computed as the
union of a cylinder and a sphere. Collision detection is then carried out
by checking for geometric intersections of the cylinders and spheres repre-
4.4 Collision Detection 169

senting the trajectories of all particles that are potentially colliding. Rigid
bodies, on the other hand, have convex and non-convex shapes and are
allowed to translate and rotate between two consecutive time steps. This
makes it very difficult to determine the volume spanned by their trajecto-
ries, and even when we can do it the added complexity and computational
time required would probably not meet the real-time interactive efficiency
goals of this book.
For example, an alternate approach to detect collisions taking into ac-
count the rigid body's trajectory considers time as an additional axis to
augment the three-dimensional space defining the simulation environment
to a four-dimensional space. By so doing, both numerical-integration and
collision-detection phases are carried out with respect to the four-dimen-
sional space. In particular, collision detection is carried out by checking for
geometric intersections between the volume swept in this four-dimensional
space. This by itself is not an easy task, especially if the rigid bodies have
non-convex shapes. Nonetheless, the problem of having geometric inter-
sections between trajectory positions associated with different simulation
times (such as we had with particle systems) is no longer relevant, since time
itself is used as an extra variable describing the trajectory. Even though
approaches like this one may work well for particular classes of rigid-body
shapes, or even general shapes moving along known parameterized trajec-
tories, they are not directly applicable to the general rigid-body simulation
scenario considered in this book. Here, we want solutions capable of effi-
ciently handling the motion of convex and non-convex rigid bodies following
the laws of physics, as opposed to being limited to scripted motions, as is
the case of parameterized trajectories.
Because considering the rigid body's trajectory to undertake collision
detection is infeasible for real-time simulations, the approach we shall take
in this book is to simplify the collision-detection problem by checking for
collisions between the bodies only after they are placed at the end of the
current simulation time step. In other words, we first numerically integrate
the dynamic state of the system without taking into account possible col-
lisions between the rigid bodies. The result of the numerical integration
is then the position and orientation of each rigid body in the system at
the end of the current simulation time step. Only then, do we check for
collisions between the bodies. Again, the collision check is undertaken by
ascertaining geometric intersections between the bodies. Whenever an in-
tersection is detected, the bodies are traced back in time to the moment
before their collision.
The trace back in time can be efficiently implemented using a root-finding
algorithm such as the bisection method. The bisection method works by
moving each colliding rigid body half way through the current time interval.
An intersection test is then conducted to determine whether the bodies
intersect at the middle point. If the bodies intersect at the middle point,
then the current time interval is substituted for its first half (i.e., from the
170 4. Rigid-Body Systems

start to middle points). Otherwise, it is substituted for its second half (Le.,
from the middle to end points). The current time interval is then recursively
subdivided into halves using the bisection method until it is shrunk to less
than a threshold value. In this case, the bodies will be intersecting at one
end of the time interval, and will not be intersecting at the other end. The
collision time (Le., time just before the collision) is approximated by the
end of the time interval in which the bodies are not colliding.
The rigid bodies' geometric displacement at the collision time is used
to compute the collision information, such as the collision point at each
rigid body, the collision normal and tangent plane. The collision points are
assumed to be the closest points between the bodies at the moment just
before their collision. The techniques used to determined such points vary
depending on both rigid bodies being convex, or at least on one being non-
convex. In Section 4.5 we address the problem of checking for geometric
intersections and computing the collision information when at least one of
the colliding bodies is non-convex. More specialized techniques to address
the case in which both bodies are convex are presented in Section 4.6.
Basically, these techniques use the convexity properties of the rigid bodies
to boost the efficiency of the collision-detection tests, providing substantial
gains over the more general non-convex technique.
The collision normal is computed from the closest features between the
rigid bodies at the moment just before their collision. A feature can be a
vertex, an edge or a face of the body. We say that the closest feature is a
vertex-face if it consists of a vertex of one body and a face of the other.
Possible closest-feature combinations are therefore vertex-vertex, vertex-
edge, edge-edge, vertex-face and edge-face. The face-face case is substituted
for three vertex-face cases, that is, one for each face vertex. By so doing,
the collision normal can be computed depending on the closest feature case,
as follows

1. Vertex- Vertex: unit vector connecting the vertices.

2. Vertex-Edge: unit vector parallel to the edge normal.

3. Edge-Edge: unit vector perpendicular to both edges. Can be com-


puted as the cross-product between the vectors defining the direction
of each edge.

4. Vertex-Face: unit vector parallel to the face normal.

5. Edge-Face: unit vector perpendicular to the face normal and the edge.
Can be computed as the cross-product between the face normal and
the vector defining the edge direction.

In all these cases, the actual direction of the collision normal is chosen
such that the relative velocity of the rigid bodies at the collision point along
4.4 Collision Detection 171

the collision normal is negative, indicating that the bodies are moving to-
wards each other. The tangent plane is directly obtained from the collision
normal and collision points, as explained in Section A.6. Once the colli-
sion information is gathered, a collision impulse or contact force of same
magnitude and opposite direction is then applied to each colliding body to
prevent their interpenetration.
Unfortunately, there are a couple of drawbacks to ignoring the rigid
body's trajectory when checking for rigid body-rigid body collisions. First
of all, collisions that occur at the beginning of the current simulation time
step have a higher probability of being missed than collisions that occur
near the end of the time step. This situation is illustrated in Figure 4.8.

~..., ,
to

, ),""" ""
"JP- ., rJifj"
,
to+%

"
""JP- W Ji)
B2
to +h

"""" B\

. • .
B2 B\ ">,
"" , , ,
[jf"'GJ •,," '" "" ,
B\ B2

(a) (b) (c)

FIGURE 4.8. (a) Rigid bodies Bl and B2 positioned and oriented at the beginning
of the current time step; (b) The bodies intersect at time to = ~; (c) But no
intersections occur at the end of the current simulation time step and the bodies
are treated as non-intersecting.

Since the bodies are positioned at the end of the current time step be-
fore any collision-checking is undertaken, intermediate collisions may be
missed during simulation. Of course, we could reduce the simulation time
step to catch these collision misses, but this would considerably slow the
simulation, defeating the purpose of using the simplification in the first
place.
The second drawback to our collision-detection scheme is that it is possi-
ble to have situations in which, even though the rigid bodies do not intersect
each other at the end of the current simulation time step, one is completely
inside the other (see Figure 4.9).
This is a difficult problem to deal with because using standard point-
in-polygon tests for checking whether the vertices of one rigid body are
included in the other rigid body's shape can be very time consuming, espe-
cially if we don't have a convex decomposition of the rigid body at hand.
Fortunately, this difficult problem can be efficiently resolved if we have a
convex decomposition of both rigid bodies. In this case, the specialized al-
gorithms covered in Section 4.6 are capable of detecting interpenetration
172 4. Rigid-Body Systems

t -t/ t - t,

&8 Bl B2
~--~ B2

(a) (b)

FIGURE 4.9. Drawbacks of considering only the final position and orientation to
undertake collision checks; (a) Rigid bodies Bl and B2 positioned at the beginning
of the current time step. No interpenetration occurs; (b) Bodies positioned at the
end of the current time step. Body Bl is completely included in body B2.

(partial or complete inclusion) between the convex bodies. However, if at


least one of the bodies is non-convex, and its convex decomposition is not
available at hand, then accurate inclusion tests are too time consuming to
warrant their use.

4.5 Collision Detection between Non-Convex


Bodies
Whenever two rigid bodies are checked for collision against each other,
the first thing the collision detection module does is verify that the bodies
are either convex, or decomposed into convex parts. The convex decom-
position can in most cases be computed using the algorithm presented in
Appendix F. However, sometimes the convex-decomposition algorithm is
incapable of determining the convex decomposition of the rigid body, pos-
sibly owing to a minimum dihedral angle or cut-face! requirement that
cannot be satisfied.
When both bodies are convex, or are represented by their convex de-
composition, the collision-detection module uses the more specialized al-
gorithms presented in Section 4.6 that take advantage of the convexity
properties to significantly improve overall collision detection. Otherwise, a
more costly collision-detection test for non-convex rigid bodies is used.
The collision-detection scheme for non-convex rigid bodies relies on their
hierarchical tree representation to detect and pin-point the colliding points,

IThe algorithm presented in Appendix F limits the set of valid cut faces to simple
polygons (without holes or double edges). This, in turn, makes the algorithm unsuitable
for decomposing complex geometric shapes.
4.5 Collision Detection between Non-Convex Bodies 173

and the moment before the collision. This in turn has the implicit assump-
tion that the bodies are treated as a polygon soup2.
The algorithm's purpose is to check for geometric intersections between
the non-convex rigid bodies using their hierarchical representations. If their
hierarchical representations do not intersect, then the bodies are quickly
dismissed and no collisions are reported from the collision-detection mod-
ule. However, if their hierarchical representations do intersect, then further
analysis is required to determine the collision point and normal, and to fix
the time just before the collision.
The collision time is computed by tracing back in time both bodies to
the moment before their collision. The trace back in time can be efficiently
implemented using a root-finding algorithm, such as the bisection method.
The bisection method works by moving each rigid body half way through
the current time interval. A hierarchical tree intersection test is then un-
dertaken to determine whether the bodies intersect at the middle point. If
so, the current time interval is substituted for its first half (Le., from the
start point to the middle point). Otherwise, it is substituted for its second
half (Le., from the middle point to the end point). This process is repeated
until the time interval is less than a threshold value, in which case the col-
lision time is assumed to be the one corresponding to the starting point of
the interval (Le., the point at which the bodies do not intersect).
The actual collision point and collision normal can be determined as a
byproduct of the back-tracing algorithm. Every time the hierarchical rep-
resentations intersect at the middle point of the current time interval, the
information about all pairs of intersecting faces is cached, replacing any pre-
viously cached information. When the tracing back in time is completed,
we assign the collision time to the starting point of the current interval
mainly because the bodies intersect at the end point of the interval. Since
we have cached the information about which pairs of faces intersect at the
end point, we can use it to compute their distance at the starting point of
the interval, that is, at the time just before their intersection. This distance
can then compared against a threshold value to select one or more pairs of
faces that are close enough to be considered colliding faces. We can then
compute the closest points between such pairs of faces and determine the
collision point and normal. Since in this book we restrict the polyhedral
representation to contain only triangles, most of the triangle-triangle inter-
section tests presented in Section 2.4.3, and the computation of the closest
point between a point and a plane (see Section A.3 of Appendix A), can
be used here.

2By "polygon soup" we mean the information about the face neighbor's connectivity,
that is, the information about which faces share an edge is not used.
174 4. Rigid-Body Systems

4.6 Collision Detection between Convex Bodies


The collision detection between rigid bodies can be carried out significantly
faster if the bodies are convex, or represented by their convex decomposi-
tion. In this case, convexity is used to gather coherence information between
two consecutive time steps, such that the result of the previous collision
check is used as the starting point of the following collision check. Usually,
the result is a pair of intersecting or closest (if no intersections are detected)
features 3 .
In this book, we present two extremely efficient algorithms to detect
collisions between convex rigid bodies. Mirtich's Voronoi Clip algorithm is
the most efficient feature-based algorithm known. The term feature-based
refers to the fact that the algorithm is based on geometric operations using
the features (Le., faces, edges and vertices) of the rigid bodies being checked
for collision. The Gilbert-Johnson-Keerthi (GJK) algorithm, on the other
hand, is the best performing simplex-based algorithm known to date. The
term simplex-based refers to the fact that the algorithm uses only the vertex
information of the rigid bodies to construct a sequence of convex hulls. The
operations are then carried out on subsets of points (Le., simplices) that
are part of such convex hulls.

4.7 The Voronoi Clip Algorithm


The basic idea of the Voronoi Clip algorithm is to subdivide the space
around a given rigid body into a set of Voronoi regions, each associated
with one rigid body's feature. A Voronoi region is defined as the region in
space in which any point inside the region is closer to its associated feature
than to any other feature of the rigid body. The proximity information
encoded in the Voronoi region of each rigid body being tested for collision
is used to determine the closest features between each pair of rigid bodies.
The closest features are then used to estimate the collision frame (Le.,
collision point, normal and tangent-plane vectors) if the bodies are not
intersecting, or to determine the intersecting features otherwise.
In general, the Voronoi regions are bounded by at most two types of
planes: vertex-edge and face-edge planes. Vertex-edge planes contain the
vertex and are normal to an edge incident on the vertex, whereas face-edge
planes contain the edge and are parallel to the normal vector of a face
that .contains the edge. More specifically, the Voronoi region associated
with a vertex is bounded by a set of vertex-edge planes, each constructed
from the vertex and an edge incident on it. The Voronoi region of an edge,
on the other hand, is made of two face-edge planes (one for each face

3Here used to mean a face, an edge or a vertex of the rigid body.


4.7 The Voronoi Clip Algorithm 175

sharing the edge) and two vertex-edge planes (one for each vertex defining
the edge). Finally, the Voronoi region of a face is made of the face itself
and face-edge planes, each constructed from the face and one of its edges.
Figures 4.10, 4.11 and 4.12 show examples of Voronoi regions of a vertex,
an edge and a face, respectively.

FIGURE 4.10. Voronoi region of a vertex.

FIGURE 4.11. Voronoi region of an edge.

v
In Figure 4.10, vertex has three incident edges, namely eI, e2 and e3.
Its associated Voronoi region is therefore made of three vertex-edge planes,
that is, planes 7r(v, ed, 7r(v, e2) and 7r(v, e3), where plane 7r(v, ei) contains
v
vertex and is perpendicular to edge ei. The normal vector ni and plane
constant di corresponding to each vertex-edge plane 7r(v, ei) are computed
as

(4.23)
176 4. Rigid-Body Systems

FIGURE 4.12. Voronoi region of a face.

with edge ei being defined by vertices V and Vi. Notice that the edge di-
rection used in equation (4.23) is not necessarily the edge direction corre-
sponding to an outward normal of the face containing the edge. Recall that
rigid bodies are assumed to be described by vertices, edges and faces, and
the edge direction is such that the normal of the face containing the edge
is pointing from the inside to the outside of the body, using the right-hand
coordinate system 4 .
Figure 4.11 shows the Voronoi region of edge e. Since the edge is made up
of two vertices and is shared by two faces, its corresponding Voronoi region
is made of two face-edge planes (n(h, e) and n(h, e)) and two vertex-edge
planes (n( VI, e) and n( V2, e)). The normal vector iii and plane constant d i
corresponding to each face-edge plane nU, e) are computed as

iii iif
di V· iii ,

where ii f is the outward normal vector of the face and V is one of the two
vertices defining edge e. An example of a Voronoi region associated with a
face is shown in Figure 4.12. In this case, the face f is triangular and its
associated Voronoi region is bounded by three face-edge planes (nU, el),
nU, e2) and nU, e3)) and the face itself.
Now, suppose we want to check for collisions between two convex rigid
bodies Bl and B 2 . Let b1 and b2 be features of these rigid bodies such that
bl E Bl and b2 E B 2 . Also, let ih and ih be the closest points between b1
and b2, such that ih E b1 and P2 E b2. It can be shown that, if point PI
is on the interior side of the Voronoi region of b2 and, conversely, point P2
is on the interior side of the Voronoi region of b1 , then the points PI and

4Since an edge is shared by two faces, the underlying implementation data structure
representing the rigid body's face must have its own edge structure because the same
edge has one direction for one of its faces, and the reverse of this direction for the
adjacent face.
4.7 The Voronoi Clip Algorithm 177

P2 are not only the closest points between b1 and b2 , but also the closest
points between the (convex) rigid bodies Bl and B 2 • We shall refer to these
as the closest feature conditions.
Because the Voronoi regions are bounded by vertex-edge and face-edge
planes that can be easily constructed from the current position and orien-
tation of the rigid body, checking whether a point lies on the interior side
of a given Voronoi region turns out to be equivalent to a simple sidedness
check of the point against each plane bounding the Voronoi region. Let
each plane 7r bounding a Voronoi region be defined by its normal vector n7r
and a point 'h. Any point p E 7r satisfies the plane equation

where d7r is the plane constant obtained from

Let Sp,7r, defined as

(4.24)
be the signed distance between point p and plane 7r. We have that p lies on
the interior side of the Voronoi region bounded by plane 7r if

Sp,7r > 0 (4.25)


and lies on the exterior side of the Voronoi region bounded by plane 7r if

Sp,7r < 0 . (4.26)


So, if point p lies in the interior side of all planes bounding a Voronoi
region, then it is said to be inside the Voronoi region. Otherwise, the point
lies outside the Voronoi region (see Figure 4.13).
The Voronoi Clip algorithm works as follows. We start by arbitrarily
selecting one feature of each rigid body being tested for collision. If the fea-
tures satisfy the closest-feature conditions, then the algorithm terminates
and the features are reported as being the ones that contain the closest
points between the rigid bodies. However, if the closest-feature conditions
are not satisfied, then the algorithm substitutes either one of the features
failing the closest-feature conditions for one of its neighboring features.
This process is repeated until the closest-feature conditions are satisfied.
In order to prevent cycles and guarantee the termination of the algorithm
after a finite number of feature updates, it is necessary to ensure that the
inter feature distance does not increase when a feature is substituted for one
of its neighbors. It turns out that, if the new feature is of a higher dimension
than the current feature being replaced, then the inter feature distance
strictly decreases. Such substitutions include changing a vertex for an edge,
178 4. Rigid-Body Systems

FIGURE 4.13. Testing whether points PI and P2 lie inside the Voronoi region
of face f consists of testing whether the points lie inside all face-edge planes
bounding the region. In this particular case, point PI lies on the inside of all
planes, meaning it is inside the Voronoi region of f. Point P2, on the other hand,
lies outside face-edge plane 7r(f, el), meaning it is outside the Voronoi region
associated with the face.

or an edge for a face. Moreover, if the new feature is of lower dimension than
the current feature being replaced, then the inter feature distance remains
unchanged. Examples of such substitutions include changing a face for an
edge or vertex, and changing an edge for a vertex. Therefore, independent
of the feature substitution made at intermediate steps of the algorithm, the
inter feature distance will never increase5 and the algorithm is guaranteed
to terminate.
Basically, testing whether the closest-feature conditions are satisfied at
each intermediate step of the algorithm consists of solving two instances
of the following problem, one for each Voronoi region of the features being
considered. Given features bl E Bl and b2 E B 2 , we need to check whether
the closest point ih E b2 to bl lies inside the Voronoi region of bl . If this
is the case, then we repeat the test for the closest point Pi E bl to b2 • If
not, then we need to update bl such that the inter feature distance does
not increase. This update consists of substituting bl for one of its neighbor
features. The difficult part of the problem resides in determining which
neighbor feature (bl)new should replace bl . We shall examine how this can
be done on a case-by-case basis, for each possible combination of (b l , b2 )
features.

4.7.1 Feature b2 is a Vertex


In this case, b2 = P2 is a single point. We get the planes associated with
the Voronoi region of bl and check for sidedness of vertex b2 using equa-

5This owes to the fact that the bodies have convex shapes. Unfortunately, the same
does not apply for the case in which the bodies have non-convex shapes.
4.7 The Voronoi Clip Algorithm 179

tions (4.25) and (4.26). If b2 lies on the inside of all planes of the Voronoi
region of b1 , then we are done with this intermediate test. Otherwise, there
exists at least one plane which b2 lies on the outside of. We substitute b1
for the feature associated with one of these violated planes 6 .
Consider the particular example illustrated in Figure 4.14, with b1 being
a triangular face. Vertex b2 is tested for sidedness against each of the three
face-edge bounding planes, and the face itself. In Figure 4.14(a), vertex b2
is on the interior side of all planes and we are done with this intermediate
test. In Figure 4.14(b), vertex b2 is on the exterior side of bounding planes
7r(b 1 , e2) and 7r(b 1 , e3). In this case, b1 should be substituted for the feature
associated with either one of these planes, namely edges e2 or e3.

(a) (b)

FIGURE 4.14. Example of an intermediate closest-feature test when b2 is a vertex


and bl is a face. (a) Vertex b2 is inside all Voronoi planes associated with b1 ; (b)
Vertex b2 lies behind Voronoi planes nU, e2) and nU, e3). In this case, b1 should
be substituted for either edge e2 or e3. Since the edge is of a lower dimension
than the face, the inter feature distance remains the same after the substitution.

4.7.2 Feature b2 is an Edge


Assume edge b2 goes from vertex ih to vertex ih In this case, ih can be
any point satisfying b2 's edge equation

(4.27)
with 0 :::; A :::; 17. The idea is then to clip edge b2 against all planes defining
the Voronoi region of b1 and check on which side of the clipped edge ih

6There is no particular preference for which violated plane should be used in the
event that there is more than one.
7We shall use the parameter>' to index the points on edge b2.
180 4. Rigid-Body Systems

is located 8 . Let [Amin, Amaxl be the portion of edge b2 that lies inside the
Voronoi region of b l . In other words, edge b 2 intersects two planes 'Trmin and
'Trmax bounding the Voronoi region of bl at points e(Amin) and e(Amax),
respectively. Also, let bmin and b max be the features associated with planes
'Trmin and 'Trmax. Figures 4.15, 4.16 and 4.17 illustrate possible situations
for the case where bl is a triangular face.

n(q,e2 )
q("-m..)
I
q(,,-) i
~_--r----------~----­

11 ",,"
" ....
........ e3
" ....
""" q "" ........
e2

FIGURE 4.15. Edge b2 intersects plane 7I"(b I ,e2) at point q(..\min) and plane
71"( bI , e3) at point q'( ..\max). Therefore, bmin = e2 and bmax = e3.

n (q,e2 )

FIGURE 4.16. Vertex ih lies inside the Voronoi region of bI and so, bmin is
undefined.

Edge b2 can be completely on the inside region of the bounding planes


(Le., Amin = 0 and Amax = 1), partially clipped by the bounding planes
(Le., Amin > 0 or Amax < 1), or totally clipped by the bounding planes
(Le., Amin = Amax = 0 or Amin > Amax, depending on how the edge is
excluded, as will be explained later in this section.)

8Recall that ih is the point on b2 closest to bl.


4.7 The Voronoi Clip Algorithm 181

FIGURE 4.17. Vertex V2 lies inside the Voronoi region of b1 and so, bmax is unde-
fined. Notice that bmin and bmax are undefined whenever edge b2 lies completely
inside the Voronoi region of b1 .

If edge b2 is completely on the inside region of the bounding planes, the


algorithm reports edge b2 and feature bl as the closest features between the
bodies. However, if edge b2 is clipped (either partly or completely), then we
need to determine whether the closest point ih on b2 to bl lies on the part
of the clipped edge b2 that is on the inside region of the bounding planes,
and if not, how to update it.

Case 1: Edge b 2 is partly clipped by the planes bounding the


Voronoi region of b 1 •
There are two approaches to check whether point ih E b2 lies inside the
Voronoi region of bl . The first and more natural approach is to explicitly
compute P2. This would entail solving one of the general geometric problems
of computing the closest point of an edge to a vertex, an edge to another
edge, or an edge to a face, depending on bl being a vertex, an edge or
a face. Having computed P2, we would then proceed by checking whether
its associated Ap2 satisfies Amin ~ Ap2 ~ Amax· If this is so, then P2 is
inside the Voronoi region of bl and we are done. Otherwise, we have either
o ~ Ap2 < Amin or Amax < Ap2 ~ 1, that is, ih lies outside the Voronoi
region of bl .
One of the problems of explicitly computing the closest point ih is the
possible exposure to numerical round-off errors. Notice that we do not nec-
essarily need to compute ih; we just need to determine in which interval
[0, Amin), [Amin, Amaxl or {A max , 1] it lies. This is the fundamental motiva-
tion behind the second approach.
The second and more efficient approach considers the distance function
from edge b2 to feature bl defined by

(4.28)
182 4. Rigid-Body Systems

which is a continuous, convex, and differentiable function of A, provided


that e( A) t/. bI · Because ih is the closest point of b2 to bI , its associated A
value is a minimum of the distance function. Therefore, checking in which
interval P2 lies is equivalent to checking the sign of the derivative of the
distance function at Amin and Amax. Let Dbl,b2 (A) be the derivative of the
distance function defined in equation (4.28). We have:

1. If bmin is well defined (see Figure 4.16) and D b1 ,b2(A min) > 0, then
the minimum (i.e., P2) lies in the interval [0, Amin). In this case, we
update bi to bmin .

2. If bmax is well defined (see Figure 4.17) and Dbl,b2(Amax) < 0, then
the minimum lies in the interval (A max , 1]. In this case, we update bi
to bmax .

3. Else, the minimum lies within the interval [Amin, Amax] and we are
done with this intermediate step.

The computation of the sign of the derivative of the distance function


depends on bi being a vertex, an edge or a face. If bi is a vertex (Le.,
bi = v), then the sign of the derivative is immediately obtained from

sign (Dv,b2(A)) = sign (ue . (e(A) - v)) , (4.29)


where ue is the unitary vector defining the direction of edge b2 given by
_ (112 - vd
Ue = IV2 - VI I .
In the case bi is a face (i.e., bi = f) with unit-normal vector iiI (pointing
outwards) and plane-constant value d I, then the sign of the derivative is
given by

if Sep..),J > 0
(4.30)
if Se(>"'),1 < 0 .
Finally, if bi is an edge, then we use its neighboring features bmin or bmax
associated with Amin and Amax to determine the sign of the derivative on
the intervals [0, Amin) and (A max , 1]. Notice that, since bi is an edge, its
neighboring features bmin and bmax must be a vertex or a face of the body
and we can use equations (4.29) and (4.30) to compute the sign of the
derivatives.
It is important to notice that the use of the neighboring features is only
possible because the distance function is continuous. In other words, the
computation of the sign of the derivative with respect to either bmin or
bmax is equal to the sign of the derivative with respect to edge bi at the
points where b2 crosses (i.e., enters or leaves) the bounding planes of its
Voronoi region, that is, at the points corresponding to Amin and Amax
4.7 The Voronoi Clip Algorithm 183

(see Figure 4.15). The only cases in which the computation of the sign of
the derivative fails is when the derivative function itself is undefined. This
occurs whenever there exists a A E [0, 1], such that

(4.31)
if bl is a vertex, or

Se(>-),b , = 0 (4.32)
if bl is a face. The geometric interpretation of being unable to compute the
sign of the derivative is that edge b2 intersects feature bl . More specifically,
equation (4.31) is satisfied whenever edge b2 contains vertex bl , and equa-
tion (4.32) is satisfied whenever edge b2 intersects face bl . In both cases,
the Voronoi Clip algorithm terminates reporting the pair (b l , b2 ) as being
interpenetrating.
One last remark on how to clip edge b2 against the planes bounding the
Voronoi region of bl . If bl is a vertex, then all of its bounding planes are
vertex-edge planes and we can clip against them in any order. However, if bl
is an edge, then its Voronoi region is bounded by two vertex-edge and two
face-edge planes. We should first clip edge b2 against the two vertex-edge
planes. If no clipping occurs, then we clip against the remaining face-edge
planes. Finally, if bl is a face, its Voronoi region is bounded by several face-
edge planes (one for each edge defining the face) and the face plane itself.
In this case, we should first clip edge b2 against the face-edge planes; if no
clipping occurs, then we clip against the face plane.

Case 2: Edge b 2 is completely clipped by the planes bounding the


Voronoi region of b l •
There are two types of complete exclusion: simple exclusion and com-
pound exclusion. Simple exclusion occurs whenever both vertices defining
edge b2 lie on the outside of a single plane bounding the Voronoi region of
feature bl . Compound exclusion occurs when both vertices defining edge b2
lie on the outside of different planes bounding the Voronoi region of feature
bl ·
Consider, for example, the simple-exclusion case illustrated in Figure 4.18,
with bl being a triangular face. Edge b2 is described by vertices ih and ih
corresponding to Amin = 0 and Amax = 1, respectively. The inclusion test
consists of checking whether edge b2 is on the interior side of all planes
bounding the Voronoi region of bl . For the case illustrated in Figure 4.18,
the result of the sided ness computation using equation (4.24) is

Sv"7I'(b , ,e,) > 0


SV2,7I'(b"e,j > 0
Sv"7I'(b , ,e2) < 0
184 4. Rigid-Body Systems

VII
I
I
I
I
I
I I V2
I
I I
~----------------~
FIGURE 4.18. An example of a simple exclusion with b1 being a triangular face.

FIGURE 4.19. An example of a compound exclusion with bl being a vertex with


three incident edges. Points ih and ifa correspond to the intersections of edge b2
(defined by points ih and V2) with planes 7r(b 1,e2) and 7r(b1,e3), respectively.
4.7 The Voronoi Clip Algorithm 185

SV2,7r(bl,e2) < 0
SVl,7r(bl ,e3) > 0
SV2,7r(bl,e3) > o.
Analyzing the results, we have that edge b2 is on the interior side of plane
7r(bt. el) (the signed-distance computations resolve to a positive value),
on the exterior side of plane 7r(b 1 , e2), and on the interior side of plane
7r(b 1 , e3). That is, edge b2 is on the interior side of all bounding planes save
7r(b 1 , e2), indicating the existence of simple exclusion. Feature b1 is then
substituted for the feature associated with plane 7r(bt. e2), namely edge
e2. In summary, simple exclusion can be detected whenever the signed-
distance computations resolve to a positive value for all bounding planes
save one, which has a negative sign. Feature b1 is then replaced by the
feature associated with the violated plane.
Figure 4.19 illustrates an example of compound exclusion, with b1 being
a vertex with three incident edges. Again, edge b2 is described by vertices fit
and fh corresponding to Amin = 0 and Amax = 1, respectively. Evaluating
the signed distance to plane 7r(b 1 , el) gives

SVI ,7r(bl,el) > 0


SV2,7r(bb el) > 0,
indicating that edge b2 is completely on the interior side of plane 7r(b 1 , et}.
Evaluating the signed distance to plane 7r(b 1 , e2) gives

SVl,7r(bl,e2) < 0
SV2,7r(b 1 ,e2) > 0,
indicating that edge b2 intersects plane 7r(bt. e2). Because vertex fit lies on
the exterior side of 7r(bt. e2), we update Amin = 0 to Amin = A2 > 0 corre-
sponding to point ih. Effectuating the last signed-distance computation to
plane 7r(bl, e3) gives

SVI ,7r(bl ,e3) > 0


SV2,7r(bl,e3) < 0,
indicating that edge b2 also intersects plane 7r(bt. e3). Because vertex fh
lies on the outside region of 7r(bl, e3), we update Amax = 1 to Amax < 1
corresponding to point ih. Notice, however, that point ih corresponding to
Amin is closer to ih than point ih corresponding to Amax. That is, Amin >
Amax which is clearly degenerate. In summary, a compound exclusion can
be detected whenever Amin > Amax. Feature b1 is then replaced by bmax if
186 4. Rigid-Body Systems

the last update that caused Amin > Amax was triggered by a reduction of
Amax. On the other hand, feature b1 is replaced by b min if the last update
that caused Amin > Amax was triggered by an increase of Amino
The way feature b1 is updated depends on b2 lying on the exterior side of
a vertex-edge or a face-edge plane bounding the Voronoi region of bl. This
in turn depends on b1 being a vertex, an edge or a face. In the following
paragraphs we shall examine all possible combinations and show how b1
should be updated on each of them.

Case 2.1: Feature hI is a vertex and h2 is a simple exclusion.


In this case, the Voronoi region of b1 is bounded by vertex-edge planes
only, and edge b2 lies on the outside region of one of these planes, say plane
7r(bI, ei). Vertex b1 should then be substituted for the feature associated
with 7r(b 1 , ei), that is, edge ei.
For example, consider the simple-exclusion case shown in Figure 4.20,
with vertex b1 having three incident edges.

FIGURE 4.20. Simple exclusion with b1 being a vertex with three incident edges,
that is, its Voronoi region is bounded by three vertex-edge planes.

Evaluating the signed distance of the vertices defining edge b2 to each of


the bounding planes gives

Sih ,Tr(b l ,el ) > 0


Sih,Tr(bl ,el) > 0
SV! ,1r(b! ,e2) < 0
Sih ,1r(b l ,e2) < 0
SVl ,1r(b l ,e3) > 0
SV2,1r(bl ,e3 ) > 0,
4.7 The Voronoi Clip Algorithm 187

indicating that edge b2 is completely on the exterior side of plane 11"(bt, e2).
So, we substitute b1 for edge e2, which is the feature associated with
11"(bt, e2).

Case 2.2: Feature hI is a vertex and h2 is a compound exclusion.


Again, the Voronoi region of b1 is bounded by vertex-edge planes only,
but edge b2 spans the exterior side of two of these planes, say planes 11"(b1 , ei)
and 11"(bt,ej). We have that

o < Amax < Amin < 1 ,


indicating that this is a compound exclusion. Assume Ai = Amin and Aj =
Amax. In other words, the intersection of edge b2 with planes 11"(bt, ei) and
11"( bt, ej) corresponds to points iii and ih associated with Amin and Amax,
respectively. Vertex b1 is then updated as follows.

1. If the minimum lies in the interval [0, Amax), that is, if

Dbl,b2(Amax) > 0
Dblob2 (Amin) > 0,

then we substitute bl for the feature associated with plane 11"(bt, ei),
namely edge ei.
2. If the minimum lies in the interval (Amin, 11, that is, if

Dbl,b2 (Amax) < 0


Dblob2 (Amin) < 0,

then we substitute b1 for the feature associated with plane 11"(bt, ej),
namely edge ej.
3. If those tests fail, then the minimum lies in the interval [Amax, AminI
and we substitute b1 for ei if the last update was reducing Amax, or
ej if the last update was increasing Amin.

Figure 4.19 shows an example of a compound exclusion when b1 is a


vertex and b2 is an edge.

Case 2.3: Feature hI is an edge and h2 is a simple exclusion.


As mentioned before, the Voronoi region of an edge is bounded by two
vertex-edge and two face-edge planes. In both cases, b1 (Le., the edge) is
substituted for the feature of the plane excluding b2 • More specifically, if
188 4. Rigid-Body Systems

f.
FIGURE 4.21. Edge b2 is simply excluded from vertex-edge plane 71'( Qi., el) bound-
ing the Voronoi region of edge b1 • In this case, b1 is substituted for vertex Qi..

f.
FIGURE 4.22. Edge b2 is simply excluded from vertex-edge plane 71'(th, eI) bound-
ing the Voronoi region of edge b1 . In this case, b1 is substituted for vertex th.
4.7 The Voronoi Clip Algorithm 189

b2 is simply excluded from either vertex-edge planes, then b1 is replaced by


the vertex associated with the plane (see Figures 4.21 and 4.22).
Otherwise, b2 is simply excluded from either face-edge planes, and b1
is substituted for the face associated with the plane (see Figures 4.23
and 4.24).

FIGURE 4.23. Edge b2 is simply excluded from face-edge plane 7r(bl' h) bounding
the Voronoi region of edge b1 • In this case, b1 is substituted for face h.

FIGURE 4.24. Edge b2 is simply excluded from face-edge plane 7r(bl' h) bounding
Voronoi region of edge b1 • In this case, b1 is substituted for face 12.

Case 2.4: Feature hl is an edge and h2 is a compound exclusion.


Compound exclusions can occur with one vertex-edge and one face-edge
plane, or the two face-edge planes. The compound exclusion cannot occur
190 4. Rigid-Body Systems

for the two vertex-edge planes because they are parallel. If the compound
exclusion occurs with a vertex-edge and a face-edge plane, then edge bl
is substituted for the vertex of the vertex-edge plane if the sign of the
derivative at the vertex is positive, that is9 , if

sign (Dth,b2(),)) = sign (ile . (e(),) - <12)) > 0, (4.33)


where ile is the unitary vector defining the direction of edge b1 (see Fig-
ure 4.25). Otherwise, b1 is replaced by the face associated with the face-edge
plane.

FIGURE 4.25. Example of a compound exclusion with a vertex-edge (Le., 11'2) and
a face-edge (Le., 11'3) plane. Edge b1 is substituted for vertex ih if equation (4.28)
is satisfied. Otherwise, it is substituted for face fa.

However, if the compound exclusion occurs with two face-edge planes,


say planes 7r(b1.li) and 7r(b1.h), then edge b1 is replaced by the face of
the face-edge plane as follows.

• If b2 intersects plane 7r(b1.li) at point ifmin, then b1 is substituted for


face Ii associated with 7r(b1 , Ii) if the sign ofits derivative is negative.

• If b2 intersects plane 7r(b 1 , Ii) at point ifmax, then b1 is substituted for


face Ii associated with 7r( b1 , Ii) if the sign of its derivative is positive.

• Otherwise, b1 is substituted for face h associated with plane 7r(b 1 , Ii)·

The sign of the derivative at the faces is obtained by substituting I in


equation (4.30) for the face being considered. Figure 4.26 shows an example
of a compound exclusion with two face-edge planes.

9Equation (4.33) is the same as equation (4.29), and is repeated here for convenience.
4.7 The Voronoi Clip Algorithm 191

FIGURE 4.26. Example of a compound exclusion with two face-edge planes,


namely planes 71"3 and 71"4. Edge bl is substituted for face fa if the sign of its
derivative, evaluated using equation (4.30), is positive. Otherwise, b1 is substi-
tuted for face 14.

Case 2.5: Feature b i is a face and b 2 is either a simple or com-


pound exclusion.
This is the most time-consuming update that can occur on the Voronoi
Clip algorithm. The problem is that, even if the edge is reported to be a
case of simple or compound exclusion, it can still span the exterior side of
several face-edge planes bounding the Voronoi region of face b1 , as shown
in Figure 4.27.

FIGURE 4.27. Edge b2 is simply excluded from face-edge plane 7I"(el,bl ) associ-
ated with edge el. Nonetheless, it spans the vertex-edge planes 7I"(qL ell, 71"(1/2, ell,
7I"(I/2,e2), as well as the face-edge plane 7I"(e2,bl) (not shown in the Figure).
192 4. Rigid-Body Systems

In order to overcome this drawback, we need to clip edge b2 against the


vertex-edge planes bounding face b1 . For each vertex-edge plane considered,
we check whether edge b2 intersects the bounding plane, or lies on its
interior or exterior sides. If b2 intersects the plane, then we compute the
sign of the derivative at the intersection point using equation (4.29), and use
it to update the current vertex-edge plane by the neighboring vertex-edge
plane associated with the interval in which the minimum point lies. On the
other hand, if b2 lies on the interior or exterior side of the plane, then we
still need to check whether it lies, respectively, on the exterior or interior
side of the corresponding neighboring vertex-edge plane. Depending on the
result, face bl is updated to one of its vertices or edges.
Consider, for example, the situation shown in Figure 4.27. We start
clipping edge b2 against a randomly selected vertex-edge plane, say plane
7r( tli, en) associated with vertex iiI- Testing b2 against 7r( qi , en) gives

Sfh,7r(iil,e n ) < 0
SV2,7r(iil,e n ) < 0,
indicating that edge b2 lies completely on the interior side of 7r(tli,en ).
Therefore, we consider clipping b2 against vertex-edge plane 7r(iiI, el), which
is the neighbor plane on the interior side of 7r(qi, en). Clipping b2 against
7r(qi, el) make us find the intersection point P3(A3) between plane 7r(tli, el)
and edge b2 • So, we need to compute the sign of the derivative to determine
on which interval [ih,P'3] (Le., [O,A3]) or [P3,V2] (i.e., [A3,1]) the minimum
point lies. If the minimum point lies on the interval [P3, V2], that is, if

then the closest point on b2 to bl lies somewhere between the bounding


planes 7r(qi, en) and 7r(qi, ed. In this case, we substitute face bl for vertex
iiI (see Figure 4.27). Otherwise, the minimum point lies on the interval
[ii1,P3], that is

sign Diil,b2(A3) > 0 ,

and we proceed clipping sub-edge [VI,P3] against vertex-plane 7r(Q2, el).


This, in turn, lets us determine the intersection point jJ4(A4) between the
sub-edge and plane 7r(Q2, ed. Again, we need to check the sign of the deriv-
ative to determine on which interval [iiI, P4] or [P4, P'a] the minimum lies. If
it lies on the interval [P4,P'a], that is

then the closest point on b2 to bl lies somewhere between the bounding


planes 7r(Q2, el) and 7r(tli, el). Therefore, we substitute face bl for edge el
4.7 The Voronoi Clip Algorithm 193

(see Figure 4.27). However, if the minimum lies on the interval [ih,P4], that
is

sign D<h,b2(A3) = sign (Ub2 . (iJ4 - Q2) > 0 ,

then we need to proceed by clipping sub-edge [ih,P4] against vertex-edge


plane 11"(Q2, e2). This is analogous to the previously explained situation
where we clipped edge b2 against vertex-edge plane 1I"(Qi,et}. So, we con-
tinue clipping for as long as needed until we find the interval on b2 that
contains the point closest to b1 , and substitute b1 for the closest feature
associated with this interval.

4. 7.3 Feature b2 is a Face


The way the Voronoi Clip algorithm is set up, it can never compare a face
with another face, with the exception of the initial choice of features done
at the time the algorithm starts. So, in practice, we can not really select
any pair b1 and b2 of features to start with, but a pair that contains at
most one face of either rigid body. Consequently, if the initial selection for
b2 is a face, then b1 should be either a vertex or an edge. The results of the
previous sections are then directly applicable to this case (we just need to
replace bl for b2 and vice-versa in the derivations of the equations obtained
so far).

4.7.4 Dealing with Interpenetration


Interpenetration of the bodies being tested for collision occurs only when
b1 is a face and b2 is an edge. Recall that the Voronoi region in this case is
bounded by a set of face-edge planes, one associated with each edge, and
the face itself. So far, we have shown how to clip edge b2 against the face-
edge planes of b1 . Interpenetration can be detected only when we clip edge
b2 against the face plane itself. If the clip results on the determination of an
intersection point between b2 and the face (Le., bt}, then the rigid bodies
are intersecting and the Voronoi Clip algorithm reports features bl E Bl
and b2 E B2 as the violating features (see Figure 4.28).

4.7.5 Avoiding Local Minima


Up till now, we have shown how the Voronoi Clip algorithm updates fea-
ture b1 according to the relative position of feature b2 with respect to the
bounding planes of b1 's Voronoi region. Unfortunately, there is a situation
in which the algorithm can find itself trapped in a local minima. This occurs
whenever:

• b1 is a face, and
194 4. Rigid-Body Systems

v(",)

FIGURE 4.28. Edge b2 was clipped against the face-edge planes bounding the
Voronoi region of face bl , resulting in points V(Amin) and V(Ama.,). Before the
algorithm substitutes bl for bmin or bma." it checks whether ba intersects bl. In
the case shown, an intersection point V(Ai) was found and the bodies are reported
as interpenetrating.

• b2 is a vertex inside the Voronoi region of bl, and


• b2 lies "below" b1 , and
• all edges connected to b2 are directed away from b1 .

Here, the algorithm, if implemented as is, reports vertex b2 and face b1


as the closest features between the rigid bodies. However, this is not always
true, since the bodies can be interpenetrating, or there may exist another
face ba E Bl closer to vertex b2 than face b1 (see Figure 4.29).
In order to avoid such local minima, we have to modify the Voronoi Clip
algorithm with the following extra steps, applicable whenever b1 is a face,
b2 is a vertex, and b2 is in the Voronoi region of bl:

1. Check whether vertex b2 lies on the interior side of bl, that is, if b2
lies "below" b1 . If so, then move on to the next step. Otherwise, this
is not a local minimum situation, and we are done.
2. For each edge ei connected to vertex b2 , check whether it is directed
away from b1 , that is, check whether

(4.34)

where Vi is the other vertex of edge ei, and iibl and dbl are the normal
vector and plane constant of face b1 •

If both of the above conditions are true, then we are dealing with a
potential local minimum. Therefore, we need to test whether vertex b2 is
4.7 The Voronoi Clip Algorithm 195

(a) (b)

FIGURE 4.29. Examples of possible local minima. The algorithm reports ver-
tex b2 and face b1 E Bl as closest features: (a) The bodies are actually inter
penetrating; (b) There exists another face b3 closer to vertex b2 than face bl.

inside rigid body Bl by testing whether it is on the interior side of all


B1's faces. If so, then the bodies are interpenetrating and the algorithm
terminates. Otherwise, the bodies are not intersecting, hence there exists
a face b3 ::f. b1 that is closer to vertex b2 than b1 is, and we substitute b1
for b3 • Notice that b3 can be obtained as a by-product of the inclusion test
provided we also keep track of the face that has the smallest value obtained
using equation (4.34).
Clearly, this is a computationally intense procedure, especially when we
carry out the inclusion test of vertex b2 with respect to rigid body B 1 •
Fortunately, the appearance of local minima is rare in practice, leading us
to the conclusion that the average running time for the algorithm is rarely
affected by this computation.

4-7.6 The GlK Algorithm


The Gilbert-Johnson-Keerthi (GJK) algorithm is used to compute the sep-
aration distance between two convex bodies, as well as a lower bound to
their interpenetration distance if the bodies are intersecting. The general
idea is to randomly select a point inside each convex body and use their dis-
tance as an initial value to the distance between the bodies. This distance
is then iteratively refined as new pairs of points are found that are closer
to each other than the ones already selected. The algorithm continues until
there are no more pairs of points closer to each other than the current pair
being considered, or a zero distance is found indicating that the bodies are
intersecting. The rigid-body features that contain the closest pair of points
are then reported back as the closest features between the bodies.
The distance between bodies Bl and B2 is defined as
196 4. Rigid-Body Systems

(4.35)
Let b1 = bi and b2 = bi be the values associated with the minimum
distance given by equation (4.35). In other words, bi and bi are the closest
pairs of points between the bodies. The lowest dimensional features con-
taining them are said to be the closest features between the bodies. For
instance, if bi lies on an edge of body B 1 , then we report the edge as the
closest feature associated with B 1 , as opposed to reporting one of the faces
containing the edge.
Since computing the distance for every possible combination of pairs of
points is clearly impractical, the GJK algorithm computes successive ap-
proximations to points bi and bi. These approximated points are iteratively
refined until their distance differs from a lower bound to the actual distance
between the bodies (i.e., lower bound to Ibi - biD by less than a tolerance
value.
The mathematical foundation of the approximation algorithm consists
of rewriting the distance between the bodies as their Minkowski difference
\II, defined as

If Bl and B2 are convex bodies, it can be shown that their Minkowski


difference is also convex. The distance equation (4.35) can then be expressed
as

dB1,B2 = min I\II B1,B2 I. (4.36)


From equation (4.36), we immediately have that the distance between the
bodies is given by the point in the Minkowski difference closest to the origin.
In other words, the GJK algorithm transforms the problem of computing
the distance between two convex bodies into the problem of finding the
point of the Minkowski difference nearest to the origin. Moreover, if the
bodies are intersecting, then there exists a point b[ in both bodies such
that b1 = b[ = b2 , and the point of the Minkowski difference nearest to the
origin is the origin itself.
The main idea behind the approximation algorithm is to construct a
sequence of simplexes whose vertices are points of the Minkowski difference,
such that at each iteration the current simplex is closer to the origin than
any previously computed simplex.
At the first iteration, the initial simplex Qi is set to empty, reflecting
that no points of the Minkowski difference have been selected so far. We
then pick an arbitrary point Pi E \II B1 ,B2 and use it to compute an auxiliary
point iii E \II B1 ,B2 such that:

(4.37)
4.7 The Voronoi Clip Algorithm 197

where SWB1.B2 (-Pi) is known as the support mapping of III Bl,B2 with re-
spect to point (-Pi). It can be shown that the support mapping of the
Minkowski difference can be computed as a function of the support map-
ping of each individual body as

SWB1.B2 (-Pi) = SB 1 (-iJ;,) - SB2 (iJ;,) , (4.38)


where S B (ji), with B E {B 1, B 2 } and P= ± iJ;" is defined as

(4.39)
max{p· xl x E B} .

According to equations (4.39), the support mapping SB(ji) with respect


to point Pis the point on B that has maximum projection along the direc-
tion defined by p. In other words, the support mapping takes a point pin
B and maps it to another point SB(ji) also in B, such that its component
along P is maximum for all points in B (see Figure 4.30).

FIGURE 4.30. The support mapping SB(P) is the point on B with the maximum
projection along p.

There are three important issues that need to be mentioned before we can
proceed with the explanation of the GJK algorithm. First, equation (4.38)
says that there is no need to compute the Minkowski difference between
the bodies. The support-mapping computations can be done independently
for each body and then merged according to equation (4.38). Second, since
the support mapping is the maximum projection along p, it can only be a
point on the boundary of the rigid body's shape. Therefore, we can limit
our search for the support mapping to the vertices defining the rigid body's
198 4. Rigid-Body Systems

boundary, as opposed to looking for candidate points inside that body.


Third, because the support mapping is on the rigid body's boundary, the
initial point Pi in the Minkowski difference can be selected as the difference
between any vertex of Bl and any vertex of B2. In other words, the deter-
mination of the initial point does not require the explicit computation of
the Minkowski difference between the bodies.
Having determined Pi and Qi, as well as the auxiliary point iii at iteration
i, we move on to compute PHI and QHl associated with iteration (i + 1),
such that

PHI min{convex(Qi U {iii})} ,


(4.40)

QHl is chosen as the smallest nonempty set with Pi+1 E convex(Qi+1).


In other words, the simplex QHl corresponding to iteration (i + 1) is the
convex hull of (Qi U {iii} ), with the added constraint that PH 1 must be one
of its vertices.
The operation convex(X) that appears in equation (4.40) is known as
the convex combination of a finite set of points Xj of polyhedron X, and is
defined as
n
convex(X) = L Aj Xj ,
j=1

with

n
LAj 1
j=1
Aj > O,Vj E {1,2, ... ,n}.

Another useful operation is the affine combination affine(X) of a finite


set of points Xj of polyhedron X, expressed as
n
affine(X) = LAjXj,
j=1

with the restriction

By definition, the vertices of the simplex QHl form a set of affinely in-
dependent points, that is, none of the points in Qi+1 can be written as an
4.7 The Voronoi Clip Algorithm 199

affine combination of the other vertices. Moreover, it can be shown that


there exists only one QHl satisfying equation (4.40). Figure 4.31 illus-
trates a few steps of the GJK algorithm, with polyhedron I}i B1 ,B2 being
the Minkowski difference of two hypothetical convex bodies (not shown in
the figure).

(a) (b)

(c)

FIGURE 4.31. Visualizing a few steps of the GJK algorithm being executed.

On Figure 4.31(a), we start with an arbitrary point Po that is the subtrac-


tion of a vertex in B2 from a vertex in Bl, that is, a point on the'boundary
of the Minkowski difference, since both bodies are convex. The initial sim-
plex Qo is set to empty. The next step is then to compute the auxiliar
point qo using the support mapping SWB1,B2 (-Po) (see equation (4.37)).
This is done by computing the support mapping for each individual body
and merging the results using equation (4.38). Figure 4.31(a) shows the
equivalent of this computation if we had to compute the convex polygon
representing the Minkowski difference of the bodies. Point qo is chosen such
that it is the point on the Minkowski difference closest to the origin. It hap-
pens that computing qo is equivalent to finding the point on the Minkowski
difference that has minimum projection along Po. Having determined Po, qo
and Qo, we use equation (4.40) to continue to the next step. In this case,
PI = qo and Ql = {qo}. Figure 4.31(b) and (c) shows the procedure just
explained applied to the next two iterations of the GJK algorithm.
The only remaining steps that need clarification are how to compute
PH 1 = min {convex (Q i U {t]i} )}, and how to construct the simplex Qi+1 s;::
(Qi U {t]i}) such that PHI E convex(Qi+1)' Here, we shall focus on the
results of how PHI and QHl can be obtained. The interested reader is
200 4. Rigid-Body Systems

referred to Section 4.10 for references to the literature that presents a full
derivation and proof of the results here described.
We shall first concentrate on how to determine the simplex QHl. Later,
we shall see that the point PHl can be directly obtained from the QHl
computations.
Let's assume the set (Qi U {qi}) is represented by

Clearly from equation (4.40), QHl is restricted to being a subset of


(Qi U {qi}) at each iteration. We want to determine QHl such that it is
the smallest non-empty subset of (Qi U {qi}) with PHl E convex(QHl).
Let Is <;:; {I, 2, ... , n} be the set of indexes corresponding to the vertices of
QHl.
In general, any point P inside the simplex QHl can be described as an
affine combination of its vertices Xj, that is

P= L AjXj,
JEIs

with

Since we are dealing with three-dimensional spaces, the maximum num-


ber of vertices a 3D simplex can have is four. That is, the maximum number
of vertices in Is is limited to four, corresponding to QHl being a tetrahe-
dron. So, if Qi already has four vertices, then (Qi U {qi}) will have five
vertices, indicating that one of them can be written as an affine combi-
nation of the others. The simplex Qi+1 will then be characterized by the
affinely independent vertices Xj of (Qi U {qi}), that is, by the vertices Xj
with Aj > O.
Putting it into equations, we have that QHl is defined by the vertices
Xj satisfying

Aj > 0, Vj E Is ,
Aj < 0, Vj ~ Is .

In other words, the simplex QHl is the convex hull of the affinely inde-
pendent vertices of (Q i U {qi} ), and point PH 1 is the point in Qi+1 closest
to the origin, given by

Pi+l = L AjXj, (4.41 )


JEIs
4.7 The Voronoi Clip Algorithm 201

with

L Aj = l. (4.42)
jEI.

Assume Is has r ~ n vertices, and let Xl, X2, ... , xr represent an arbitrary
ordering of the vertices of Is. In this context, equation (4.42) can be re-
written as
r
A1=1-LAj.
j=2
Since we want PH1 to be the point closest to the origin, the A2, ... , Ar
are computed from the unconstrained minimization of
r

F(A2,"" Ar) = IXl +L Aj (Xj - Xl) I.


j=2
Since F(A2,"" Ar) is a convex function, it is minimized whenever

8F(A2,"" Ar) = 0 (4.43)


8Aj ,
for j E {2, ... ,r}. Equation (4.43) can then be written in matrix format

ArX = b,
with Ar E IRrxr and bE IRr, such that:

1 ... 1 )
A = (X2 - Xl) . Xl ... (X2 - xt) . xr
(
.. .. ..
r . . .

( Xr - Xl . Xl
~ ~) ~
... Xr -
(~~)
Xl • Xr
~

Using Cramer's rule, we can compute each Aj as

where

L 6j(Qi+l) ,
jE1s
202 4. Rigid-Body Systems

with m ~ Is and k being the minimum index in Is. It happends that the
smallest Qi+ I C (Q i U {Qi}) is such that

6(Qi+I)
6j(Qi+I)
> °
> 0, V j E Is (4.45)
6 m(Qi+1 U {xm}) < 0, Vm ~ Is.
Notice that equations (4.44) are solved for each possible instance of Is,
that is, for each possible subset of (QiU{Qi}). We then select as the solution
the subset that satisfies the constraints described in equations (4.45). It can
be shown that exactly one solution subset satisfies equations (4.45).
Since the maximum number of vertices n in (Qi U {Qi}) is small (Le.,
n :::; 4), the determination of Qi+1 can be done by an exhaustive search
among all possible nonempty subsets of (Qi U {Qi}). This translates into
searching among
n ,

L
m=1
m! (nn__ m)!

candidate subsets that satisfying equations (4.45).


Having determined the subset Qi+1 that satisfies equations (4.45), point
Pi+l follows directly from equation (4.41), that is

Pi+1 = L Aj Xj .
JEI.

We proceed to iteration (i + 2) to determine Qi+2 and Pi+2, and so on,


until we reach the termination condition explained in Section 4.7.7. Let t
be the iteration at which the termination conditions are reached. We have

(4.46)
JEIs
Each point Xj in the Minkowski difference of BI and B2 can then be
expressed as

(4.47)
with (Cd j E Bl and (b2 )j E B 2 • Substituting equation (4.47) into (4.46)
gives:

Pt L Aj ((bt)j - (b )j) 2
JEI.

JEI. JEIs
4.7 The Voronoi Clip Algorithm 203

Because Bl and B2 are convex, bi E Bl and b2 E B2 are the closest


points between the bodies.

4.7.7 Termination Condition


Even though it is guaranteed that the GJK algorithm will end in a finite
number of iterations whenever bodies Bl and B2 are convex polyhedra,
the presence of numerical round-off errors in a computer implementation
makes it necessary to formulate a termination condition to be checked at
the end of each iteration.
The termination condition consists of checking whether point Pi obtained
at iteration i lies within a tolerance value from the origin. If so, then Pi is
considered close enough to the origin and the algorithm terminates. The
tolerance value used is a lower bound on the module of Pi computed as the
signed distance of the supporting plane 7r pi ,ij; to the origin. The supporting
plane is defined by its normal vector ni and plane constant di as lO

ni -Pi
di Pi·iIi·
The signed distance of the supporting plane to the origin is then

Notice that, for di > 0, the origin lies in the positive half space of 7rPi ,Qil
x
that is, if we substitute = 0 in the plane equation, we get

whereas the Minkowski difference always lies in the negative half space of
the plane. Therefore, at iteration i we use

Lb = max{ O,do,d ll ... , di }

as the lower bound of 1Pi I, and we terminate the algorithm at iteration i


whenever

with I-l being the error-tolerance value.

lOThe plane in this case is defined as 7rpi ,qi = {X' : (iii' X' + di) = a}, as opposed to
{X': (iii' X' - di) = a}. The latter is the definition used in all other sections of this book.
204 4. Rigid-Body Systems

4.8 Rigid Body-Rigid Body Collision Response


Whenever a rigid body-rigid body collision is detected, the collision-response
module is invoked to compute the appropriate collision impulses or contact
forces that will prevent interpenetration between the colliding bodies. As
explained in Section 4.4, the colliding rigid bodies are traced back in time
to the moment before their collision. The collision point and normal are
then determined from their geometric displacement.
The colliding bodies are arbitrarily assigned indexes 1 and 2, and the
normal direction is selected such that the relative velocity (ift - 712 ) of the
rigid bodies at the collision point along the collision normal is negative just
before the collision, that is, we choose fi such that

(4.48)

is satisfied just before the collision, indicating that the bodies are mov-
ing towards each other (see Figure 4.32). Notice that the velocities at the
collision points PI and P2 are computed using equation (4.6), described in
Section 4.2.

FIGURE 4.32. Rigid bodies BI and B2 at the moment just before their collision.
The relative velocity of the closest points PI and P2 is used to determine the
direction of the collision normal. Notice that at the exact moment of collision we
have PI = P2 = pc.

This index assignment is critical because, from Newton's principle of


action and reaction, the collision impulses and contact forces between the
rigid bodies have the same magnitude, but opposite directions. Following
our convention, a positive impulse should be applied to the rigid body with
index 1, whereas a negative impulse should be applied to the rigid body
of index 2. Therefore, it is important to keep track of the index assigned
to each rigid body, so as to later apply the collision impulses and contact
forces on the correct direction (Le., with the correct sign) to each body.
Also, notice that, in the case of multiple rigid body-rigid body collisions,
4.8 Rigid Body-Rigid Body Collision Response 205

a rigid body might be assigned different indexes for each collision it is


involved in.
The difference between a collision and a contact is determined from the
module of the relative velocity along the collision normal, at the collision
point. If the relative velocity of the rigid bodies at the collision point along
the collision normal, at the moment before the collision, is less than a
threshold value, then the rigid bodies are said to be in contact and a con-
tact force is computed to prevent their interpenetration. Otherwise, the
rigid bodies are said to be colliding and an impulsive force is applied to in-
stantaneously change their direction of motion to avoid the imminent inter
penetration.
Also, there may be situations in which several rigid bodies are involved in
multiple collisions and contacts. If so, the collision-response module should
first resolve all collisions by simultaneously computing all impulsive forces.
Having determined all impulsive forces, the collision-response module pro-
ceeds by applying the impulses to the appropriate rigid bodies. By the time
the impulses are applied, some of the contacts mayor may not break, de-
pending on whether the relative acceleration of the rigid bodies at their
contact point, along the contact normal, is positive, zero or negative. A
contact force is then simultaneously computed for all contacts that have a
negative relative acceleration along their contact normal.

4.8.1 Computing Impulsive Forces for a Single Collision


Let's start by examining the case where we have one or more simultaneous
collisions, each involving two different rigid bodies. Here, each collision can
be dealt with separately and in parallel, since they do not have bodies in
common.
Let collision C, involving rigid bodies B1 and B 2 , be defined by its col-
lision normal ii and tangent axes f and k, as indicated in Figure 4.33.
Let ih = ((V1)n, (vdt, (V1)k) and W1 = ((W1)n, (wdt, (Wdk) be the linear
and angular velocities of rigid body B1 just before the collision. Analo-
gously, let ih = ((V2)n, (V2)t, (V2)k) and W2 = ((W2)n, (W2)t, (W2)k) be the
linear and angular velocities of rigid body B2 just before the collision. All
these components are known quantities. We need to compute the linear
and angular velocities of both bodies just after the collision, namely V1 =
((V1)n, (V1)t, (V1)k), 01 = ((Odn' (01)t, (01)k), V2 = ((V2)n, (V2)t, (V2)k)
and O2 = ((02)n, (02)t, (02)k). These, together with the impulsive force
P = (Pn , Pt , Pk), sums to a total of fifteen unknowns, thus requiring the
solution of a system with fifteen equations.
206 4. Rigid-Body Systems

FIGURE 4.33. Single rigid-body collision, showing just the closest points PI and
ih, as well as the location of the center of mass of each colliding body, at the
moment just before the collision. A negative and a positive impulse is applied to
the body of indexes 2 and 1, respectively. Also, the distance between the closest
points is exaggerated to facilitate drawing the tangent plane.

Applying the principle of impulse and linear momentum to each rigid


body along the three axes defining the collision frame, we obtain six out of
the fifteen equations needed 11:

ml (VI - ih) P (4.49)


m2 (V2 - V2) -p. (4.50)

Applying the principle of impulse and angular momentum for each rigid
body along the three axes defining the collision frame, we obtain another
set of six equations:

11 (n 1 - wd 1"1 X P = 1'1 P (4.51)


12 (n 2 - W2) -1"2 X j3 = -1'2 P , (4.52)

where fIP and 1'2P are the matrix-vector representation of their respective
cross-products, as explained in detail in Section A.7 of Appendix A.
The next equation is obtained by the empirical relation involving the
coefficient of restitution and the relative velocity of the rigid bodies at the
collision point along the collision normal. Let e denote the coefficient of
restitution along the normal direction. We have

11 We will use the vector-based notation as much as possible to keep the equations
concise. However, there are cases in which we do need to rewrite the equations using
the individual components of each vector, such as when computing the critical-friction
coefficient covered later in this section.
4.8 Rigid Body-Rigid Body Collision Response 207

((VI + fil X rl) - (V2 + fi2 X f2)) . n =


-e((ih +Wl x rl) - (V2 +W2 X f2)). n
or equivalently

((Vl)n + (rt}k (OI)t - (rl)t (Ot}k)


((V2)n + (r2)k (02)t - (r2h (02)k)
-e (((Vl)n + (rl)k (Wl)t - (rl)t (Wl)k)
((V2)n + (r2)k (W2)t - (r2h (W2)k)) . (4.53)

The remaining two equations are obtained from the Coulomb friction
relations at the collision point. If the relative motion of the rigid bodies at
the collision point along { and k is zero just before the collision, that is, if

((VI +Wl X rl) - (V2 +W2 X f2)). { 0


((ih+Wlxrl)-(V2+W2xr2))·k = 0,
then their relative motion will remain zero after the collision. More specif-
ically, we use

(VI + fil X rl)· { = (V2 + fi2 X r2) . { (4.54)


(VI + fil X rl) . k = (V2 + fi2 X r2) . k (4.55)

as the two remaining equations to solve the system. However, if the relative
motion is not zero, then the rigid bodies are sliding along f and k at the
collision point. The collision impulse will then act on the opposite direction
of motion, trying to prevent the sliding. If it succeeds, then equations (4.54)
and (4.55) should be used. Otherwise, the rigid bodies continue sliding
throughout the entire collision, and we use

(4.56)
(4.57)

as the two remaining equations to solve the system. Notice that (/-td)t and
(/-td)k are the dynamic Coulomb friction coefficients along the {and k direc-
tions, respectively. Since Pt and Pk are always opposing the sliding motion,
the coefficients of friction can be either positive or negative to reflect that
condition. The actual signs of the coefficients depend on the relative veloc-
ity of the rigid bodies at the collision point along axes {and k, just before
the collision. The signs are directly obtained from
208 4. Rigid-Body Systems

((ih + WI x rt) - (ih + W2 X 7'2)) . f


(4.58)
(( ih + WI X rt) - (V2 + W2 X r2)) . n
((VI +WI X rI) - (V2 +W2 X 7'2)). k
(4.59)
((VI + WI X rI) - (V2 + W2 X r2)) . n .
As already explained in Chapter 3, this directional-friction model is a
generalization of the widely used model of relating the tangential and nor-
mal impulses using just one omnidirectional coefficient of friction ltd, as
in

Ptk = ltd Pn , (4.60)


where Ptk is the impulse on the tangent plane given by

For example, if friction is isotropic, that is, independent of direction,


then we can write

(ltd)t = ltd cos cp


(ltdh = ltd sin cp
for some angle cp, and so

Ptk VP? + P'f


Vr-It-~-P-;-c-o-s-cp-2-+-It-~-P-n-2-s-in-cp-2

ltd Pn ,

which is the same result obtained using the omnidirectional-friction model


of equation (4.60). The main advantage of using this model is that the
non-linear equation:

that needs to be enforced when the rigid bodies are not sliding at the
collision point can be substituted for two linear equations

IPt I < (ltd)t Pn


IPk I < (ltd)k Pn ,
4.8 Rigid Body-Rigid Body Collision Response 209

which are equivalent to the non-linear equation if friction is isotropic, and


most important, are easier to handle in matrix form, as we shall see shortly.
As far as friction is concerned, we have to consider two possible cases. In
the first, we assume the rigid bodies continue sliding along the tangent plane
after collision, and we use equations (4.49) to (4.53) with equations (4.56)
and (4.57) to compute the collision impulse and velocities after the collision.
In the second, the rigid bodies are not sliding along the tangent plane after
the collision, and we use equations (4.49) to (4.53) with equations (4.54)
and (4.55) instead. For now, let's focus on the solution corresponding to
the first case. Later, we shall consider the modifications needed to address
the second case.
Instead of jumpstart-solving the fifteen-equation system, let's first con-
sider its partitioned block-matrix representation and show how we can use
linear-system methods to efficiently resolve the collision. Besides being ex-
tremely useful for the single-collision case, the block-matrix representation
proves to be invaluable when dealing with multiple simultaneous collisions,
as we shall see later in Section 4.8.2.
As mentioned, if the rigid bodies continue sliding along the tangent plane
after collision, we need to use equations (4.49) to (4.53) with equations
(4.56) and (4.57). Here, the fifteen-equation system can be put into the
following matrix format:

a a a 1 a a a (rl)k -(rI}t
-(J.1,d)t 1 a a a a a a a
-(J.1,d)k 1 a a a a a a a
-1 a a ml a a a a a
a -1 a a ml a a a a
a a -1 a a ml a a a
a (rI}k -(rI}t a a a (h)nn (h)nt (h)nk
-(rdk a (rdn a 0 0 (Idtn (Idtt (h)tk
(rdt -(rdn 0 0 0 0 (Idkn (II}kt (Idkk
1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 -(r2)k (r2)t 0 0 0 0 0 0
(r2h 0 -(r2)n 0 0 0 0 0 0
-( r2)t (r2)n 0 0 0 0 0 0 0
210 4. Rigid-Body Systems

-1 0 0 o -(r2)k (r2)t Pn
000 o o o Pt
000 o o o Pk
000 o o o (Vl)n
000 o o o (Vl)t
000 o o o (vdk
000 o o o (fh)n
000 o o o (fh)t
000 o o o (n1)k
m2 0 0 o o o (V2 )n
o m2 0 o o o (V2)t
o 0 m2 o o o (V2)k
000 (I2)nn (I2)nt (h)nk (n 2 )n
000 (I2)tn (I2 )tt (I2)tk (n 2 )t
000 (I2 )kn (h)kt (I2 )kk (n 2 )k
(4.61)
-e «Vl)n + (rl)k (wdt - (rl)t (Wl)k)-
«V2)n + (r2)k (W2)t - (r2)t (W2)k))
o
o
ml (Vl)n
ml (vdt
ml (Vdk
(Idnn (wdn + (It)nt (Wl)t + (It)nk (Wl)k
= (It)tn (Wt}n + (It)tt (Wt}t + (Ilhk (Wl)k
(It)kn (Wt}n + (It)kt (Wl)t + (It)kk (Wl)k
m2 (V2)n
m2 (V2)t
m2 (V2)k
(I2)nn (W2)n + (I2)nt (W2)t + (I2)nk (W2)k
(I2)tn (W2)n + (I2)tt (W2)t + (I2)tk (W2)k
(I2)kn (W2)n + (I2)kt (W2)t + (I2)kk (W2)k

where the order in which the equations are laid out in each row is equation
(4.53) first, then equations (4.56) and (4.57), followed by equations (4.49),
(4.51), (4.50) and (4.52). This order is very important, since it simplifies
the description of the above system using the partitioned block-matrix
representation
4.8 Rigid Body-Rigid Body Collision Response 211

C 1 ,2 -B 1 ,2
o o d-;,2]
m1 ih
o = ( I1W! '
m2 V2
o o hW2
(4.62)
where 0 is the 3 x 3 zero matrix, I is the 3 x 3 identity matrix, and P1,2 = P,
with the index (1,2) indicating that the impulse corresponds to the collision
between bodies B1 and B212. The matrices T1 and T2 are the matrix-vector
representations of the cross-products 1"1 x P and 1"2 x P, respectively. The
other matrices are given by

A',2 ~
0
0
( -{t. Ld)t 1
-(J.Ld)k 1
0

n) B 1 ,2 = COO )
000
000

0 )
(r1)k -(r1)t -(r2)k (r2)t
C,,2~ 0
0
0
0
E 1 ,2 = 0
0
0
0

and the vector d-;,2 is computed as

_ ( -e ((ih +w, x Ttl - (ii, +W2 x r,))· n )


d1,2 = 0 (4.63)
0
We can then solve the (often) sparse linear system described in equa-
tion (4.62) using Gaussian elimination, or a more sophisticated system
solver suitable for sparse matrix only. The latter is more difficult to imple-
ment, but yields significant efficiency gains over the former method.
Notice that this partitioned-matrix representation is applicable only to
the case where the colliding rigid bodies continue sliding throughout the
collision. If the bodies are not sliding after collision, either because they
were not sliding before the collision or the sliding motion stopped during
the collision, then equations (4.54) and (4.55), namely

(V1+n x 1"1)·f
1 (V2 + n2 x 1"2) . f
(V1 + n x 1"1) . k
1 (V2 + n2 x 1"2) . k

12Even though the use of the indexes is not particularly useful for the single-collision
case, they will be extensively applied in the block-matrix representation of multiple
collisions to distinguish between equations associated with collisions involving different
rigid bodies.
212 4. Rigid-Body Systems

should be used instead of equations (4.56) and (4.57). This in turn requires
modifying the second and third rows of the partitioned-matrix represen-
tation, or equivalently, the second and third rows of matrices A 1 ,2, B 1 ,2,
C 1 ,2 and E 1 ,2. The modification consists of updating the second row to

if there is no sliding motion along the f direction, and updating the third
row to

if the bodies are not sliding along the k direction.


Notice that the sliding motion on the tangent plane is directly affected by
the coefficients of restitution and friction, as well as by the relative velocities
of the rigid bodies just before the collision. Intuitively, for a given coefficient
of restitution and relative velocities, the sliding motion will continue if
the coefficient of friction is small, or will stop if the coefficient of friction
is sufficiently large. Therefore, there exists a critical-coefficient-of-friction
value associated with a given coefficient of restitution and relative velocity.
If the actual coefficient of friction is less than the critical coefficient of
friction, then sliding continues throughout the collision and the system
equations associated with the first case should be used. However, if the
actual coefficient of friction is greater than or equal to the critical coefficient
of friction, then the sliding stops somewhere during the collision and the
system equations associated with the second case should be considered
instead 13 .
Let's derive an expression for computing the critical coefficients of fric-
tion (J.ld)'i and (J.ld)'k along the tangent-plane directions f and k. This will
be done by first expressing all velocity components in equation (4.53) as
a function of the normal-impulse component Pn , and solving for Pn . The
computed impulse component Pn will then be substituted back into the
expressions for each velocity component. This in turn will give us all ve-
locities as a function of the restitution and friction coefficients, as well as
the velocities of the bodies just before their collision 14 . Lastly, we shall
substitute these expressions into equation (4.54) to determine the critical-
coefficient value (J.ld)'i along f, and into equation (4.55) to determine the
critical-coefficient value (J.ld)'k along k.
So, from equations (4.49) and (4.50), we can write the linear velocity
components as

13 If the actual coefficient of friction is equal to the critical coefficient of friction, then
the sliding motion will stop exactly at the instant corresponding to the end of the
collision.
14Keep in mind that the velocities computed so far assume that the sliding motion
continues throughout the collision.
4.8 Rigid Body-Rigid Body Collision Response 213

Pn
(Vl)n -ml + (vdn (4.64)
P
(Vl)t - t + (Vl)t (4.65)
ml
Pk
(V1 )k -ml + (Vdk (4.66)

(V2)n -P-n + (V2 )n (4.67)


m2
P
(V2)t - -t + (V2)t (4.68)
m2
P
(V2)k - -k + (v2h . (4.69)
m2

Expressing the angular velocities as a function of Pn is a bit more com-


plicated. Using equations (4.51) and (4.52), each angular velocity can be
written as

n 1 = 11 - 1 'hP+Wl
n 2 = -12 - 1 f 2 P+W2.
Let A1 = 11 - 1 h and A2 = h -1 f2 be the result of the multiplication
of these four known matrices, where

for i E {l,2}. Using the fact that Pt = (/ld)t Pn and Pk = (/ldh Pn ,


after considerable manipulation, we obtain the following expressions for
the angular-velocity components.

(OI)n ((A 1 )nn + (/ld)t (A 1 )nt


+ (/ld)k (A 1 )nk) Pn + (wdn (4.70)
(OI)t ((A 1 )tn + (/ld)t (A 1 )tt
+ (/ld)k (A 1 )tk) Pn + (Wl)t (4.71)
(OI)k ((Adkn + (/ld)t (A 1 )kt
+ (/ldh (A 1 )kk) Pn + (Wl)k (4.72)
(02)n -((A2)nn + (/ld)t (A2)nt
+ (/ldh (A 2)nk) Pn + (W2)n (4.73)
(02)t -((A2)tn + (/ld)t (A 2)tt
214 4. Rigid-Body Systems

+ (/1d)k (A2)tk) Pn + (W2)t (4.74)


(f2 2)k -((A2)kn + (/1d)t (A2)kt
+ (/1d)k (A2)kk) Pn + (W2)k (4.75)

Substituting equations (4.64), (4.67), (4.71), (4.72), (4.74) and (4.75)


into equation (4.53), and grouping the terms that have Pn in common, we
get

Pn (m + ((r1h (At}tn - (rt}t (A 1)kn) +


((r2)k (A2)tn - (r2)t (A2)kn) + (/1d)t (((rt}k (A 1)tt - (r1)t (A 1)kt) +
((r2)k (A2)tt - (r2)t (A2)kd) + (/1d)k (((r1)k (A 1)tk - (rt}t (A 1)kk) +
((r2)k (A2)tk - (r2)t (A2)kk)))
-(1 + e) ((v\ + W1 x fi) - (V2 + W2 x 1'2)). n (4.76)

where

m= (_1 +~) .
m1 m2

This equation can be further simplified if we observe that

(ri)k (Ai)tn - (ri)t (Ai)kn ((Ai)n x fi) . n


(ri)k (Ai)tt - (ri)t (Ai)kt ((.«)t x fi) . n (4.77)
(ri)k (Ai)tk - (ri)t (Ai)kk ((Ai)k x fi) . n

for i E {I, 2}. Substituting these equations into (4.76), gives

Pn (m + ((A1)n x r1 + (A2)n x 1'2) . n +


(/1d)t ((A1)t x r1 + (A2)t x 1'2). n +
(/1d)k ((A1)k x r1 + (A2)k x r2) . n)
-(1 + e)((v1 + W1 x r1) - (V2 + W2 x r2)) . n (4.78)

Equation (4.78) can be reduced even further if we consider the following


constants

(4.79)
4.8 Rigid Body-Rigid Body Collision Response 215

with i,j E {n,t,k}. Using these constants, equation (4.78) can then be
rewritten as

which can be solved for Pn , giving

(4.80)

Having computed Pn , we can substitute its value back into equations


(4.64) to (4.75) to obtain the values of each velocity component after the
collision, for the case where the sliding motion continues throughout the
collision. We are now ready to derive the expressions for computing the
critical coefficients of friction along the tangent directions f and k.
Let's start by computing (/Ld)f. This coefficient can be obtained if we
expand equation (4.54) to

that is

(Vl)t + (n1h (rl)n - (n1)n (rdk


(V2)t + (n 2 h (r2)n - (n 2)n (r2h (4.81 )

and substitute the value of each velocity component computed as a function


of Pn into this equation, giving

P
- t + (vdt + (rdn ((A1)kn Pn +
ml
(A1)kt Pt + (A1)kk Pk ) + (rl)n (Wl)k
(rdk ((Adnn Pn + (Al)nt Pt + (A1)nk Pk) - (rl)k (wdn (4.82)
P
- -t + (V2)t - (r2)n ((A 2 )kn Pn +
m2
(A2)kt Pt + (A2hk Pk) + (r2)n (w2h +
(r2)k ((A 2)nn Pn + (A2)nt Pt + (A2)nk Pk) - (r2)k (W2)n

From Pt = (/Ld)t Pn and Pk = (/Ld)k Pn , we can group the terms of equa-


tion (4.82) so as to expose the constant values defined in equations (4.79).
We have
216 4. Rigid-Body Systems

-«AI)" XTI +(A2)" XT2)'{


A

Pn '«rl)n (A 1 )kn - (rl)k (Adnn + (r2)n (A2)kn - (r2)k (A2)nn)' +


~ _ _ _ _ _ _ _ _ _ _ _-«Ad.
_____ XTI +(A2).XT2)·{
____________
~A~ ~_ _ _ _~

(J.Ld)t Pn (rl)n (Adkt - (rdk (A 1)nt + (r2)n (A2)kt - (r2); (A2)nS +


-«At}k XTI +(A2)k XT2)·f
"

that is

gi'
, " "
Pn «A1 )n x rl + (A2)n x f2) . r
~ ______
g~'
~A~ ______ ~

(J.Ld)t Pn ((A1 )t x rl + (A2)t x f2) . t

which can be written in the condensed form

«J.Ld}t m - 9"it
(J.Ld)t 9it - (J.Ld)k 9~t) Pn = -g~ .
- (4.83)
Finally, substituting the value of Pn given in equation (4.80) into equa-
tion (4.83), and solving for (J.Ld)t, we can compute the critical coefficient of
friction along the tangent-plane direction r as
( ) _ ( )C _ g~ (m + g"in + (J.Ld)k g~n) + (1 + e) g'f] (g"it + (J.Ld)k g~t)
J.Ld t - J.Ld t - (mt- tgl) (1 + e) g2n - g2t gltn '
(4.84)
where (J.Ld)f is the critical value of the coefficient of friction along such r
that the sliding motion stops exactly at the end of the collision.
The derivation of the critical coefficient of friction (J.Ld)f: along the tangent-
plane direction k is very similar to that shown for (J.Ld)f. We start by ex-
panding equation (4.55) to

(V1 )k + (OI)n (rl)t - (OI)t (rl)n


(V2)k + (02)n (r2)t - (02)t (r2)n
and substitute the velocity-component values obtained from equations (4.66),
(4.69) to (4.71), (4.73) and (4.74). We then group the terms in order to ex-
4.8 Rigid Body-Rigid Body Collision Response 217

pose the constant-value expressions given in equations (4.79). After some


manipulation we get

Finally, substituting the value of Pn obtained from equation (4.80) into


this expression, and solving for (/-Ld)k, we can compute the critical coefficient
of friction along the tangent-plane direction k as

( ) _ ( )C _ g~ (m + gr n + (/-Ld)t gin) - (1 + e) g~ (gr k + (/-Ld)t glk)


/-Ld k - /-Ld k - (-
m + g1kk) (1 + e) g2n - g1kn g2k '
(4.85)
where (/-Ld)~ is the critical value of the coefficient of friction along k such
that the sliding motion stops exactly at the end of the collision.
We do the following in practice. First, compute the critical coefficients
of friction using equations (4.84) and (4.85). Next, compare the actual
coefficient of friction (/-Ld)t and (/-Ld)k to their associated critical values. If
t:
(/-Ldh < (/-Ld)~, then sliding continues along and we use equation (4.56).
Else, if (/-Ld)t ~ (/-Ld)~, then sliding along f stops during the collision, and
we use equation (4.54) instead. The same analysis is used for comparing
(/-Ld)k with (/-Ld)~ and selecting the appropriate system equation.
As far as the block-matrix representation is concerned, the choice of the
equation to use as a function of the critical-coefficient-of-friction values di-
rectly affects the rows of matrices A 1 ,2, B 1 ,2, C 1 ,2 and E 1 ,2 being used. We
have, therefore, the following four possible cases to consider when building
the system matrix:

1. If (/-Ld}t < (/-Ld)t and (/-Ld)k < (/-Ld)k, then:

A.,2 ~ (
0
-(/-Ld)t
o10
0) B.,2~ 0 oo
o
0)
0

0 0
-(/-Ld)k 1 0 0

C.,2~
(r1)k
0
0
-(t) E.,2~
-(r2)k
0
0
("t )
2. If (/-Ld)t ~ (/-Ld)~ and (/-Ld)k < (/-Ld)~, then:

A.,2 ~(
0
0
-(/-Ld)k
0
0
1 n B 1 ,2 =
0n
0
1
0
218 4. Rigid-Body Systems

~ ( -(~,)k )
(rdk -(rdt
C,,' 0 (rl)n
0 0

E", ~ ( )
-(r2)k (r2)t
(ril> 0
0
--(r2)n
0

3. If (J.ld)t < (J.ld)~ and (J.ldh ~ (J.ld)k, then:

A 1 ,2 = ( -(i·), B 1 ,2 =

(rdk
o
-(rl)n
-(r2)k
o
(r2)n

A 1 ,2 = 0 B 1 ,2 = I
C 1 ,2 = -Tl E 1 ,2 = T2

Having built the system matrix associated with the collision, we can use
Gaussian-elimination or sparse-matrix techniques to solve the linear system
of equations and determine the collision impulse, and linear and angular
velocities, of the bodies at the moment after their collision.

4.8.2 Computing Impulsive Forces for Multiple Collisions


If three or more rigid bodies are simultaneously colliding with each other,
the collision impulse of each individual collision will simultaneously affect
the dynamics of the system. Therefore, instead of resolving one collision at
a time ignoring the presence of the others, the simulation engine needs to
group the rigid bodies into clusters that share at least one collision. The col-
lisions within each cluster can then be simultaneously resolved independent
of all other clusters (see Figure 4.34).
Consider the computation of the collision impulses associated with clus-
ter G 1 , as shown in Figure 4.34. Let collisions C 1 and C 2 be the collisions
involving bodies (Bl - B 2) and (B2 - B 3 ), respectively. As far as rigid
4.8 Rigid Body-Rigid Body Collision Response 219

Cluster G2 Cluster G3

FIGURE 4.34. Multiple rigid-body collisions separated into three clusters. Body
Bi is added to cluster Gj if it is colliding with at least one rigid body already
in G j • The collision-response module resolves each cluster in parallel, since they
have no collisions in common and therefore can be viewed as independent groups
of collisions.

body B2 is concerned, the linear- and angular-momentum equations owing


to both collisions are

m2 CV2 - V2) + P 2>-+ 1,3>-+2


- Pl,2
12 (0 2 - W2) T2 (-P1,2 + P 2>-+1,3>-+2) ,

where P2>-+l,3>-+2 is the impulse P 2,3 of collision C 2 expressed in the local-


coordinate frame l5 associated with collision C 1.
Clearly, the impulse arising from collision C2 will also affect the compu-
tation of the impulse arising from collision C 1 , and vice-versa. The correct
way to compute the collision impulses is, then, to take both collisions into
account when solving the system equations. Recall from Section 4.8.1 that
we adopted the convention that a positive impulse is applied to the rigid
body with index 1, and a negative impulse is applied to the rigid body
with index 2. The choice of indexes is related to the relative velocities of
the rigid bodies at the collision point along the collision normal, such that
equation (4.48) is satisfied at the moment before the collision.
Whenever a rigid body is involved in multiple collisions, it is possible to
have it assigned to different indexes for each collision. For the particular
situation of cluster G 1 , rigid body B2 has index 2 with respect to its collision
with Bl, and index 1 with respect to its collision with B 3 . This in turn,

15The local-coordinate frame is defined by the collision normal and tangent plane.
220 4. Rigid-Body Systems

affects the choice of sign when combining the multiple-collision impulses in


the system equations. For example, the minus sign on P1,2 indicates that
rigid body B2 has index 2 with respect to collision C 1 , whereas the plus
sign on P2 ..... 1,3..... 2 indicates body B2 has index 1 with respect to collision
C2 • Moreover, the collision normal and tangent plane are different for each
collision. So, we also need to carry out a change of base between the collision
impulses before combining them.
The best way to deal with multiple collisions is to represent the system
equations associated with each cluster in its block-matrix form

where x is the state vector containing the variables that need to be de-
termined. In the single collision case, the state vector is defined by the
collision impulse, and the final linear and angular velocities of the colliding
bodies. However, when dealing with multiple collisions, the state vector can
be viewed as the concatenation of several single-collision state vectors, with
the added complexity that no variables should be accounted for more than
once. For instance, Figure 4.35(a) shows the result of a naive concatena-
tion of state vectors for the multiple collisions associated with cluster G 1
of Figure 4.34.

State vector State vector


q - 02 Collision: ~.2 _ ~.2 01 - O2 Collision: ~.2 _
~.2
t;;- t;; t;;- t;;
w.- w. w.- w.
~-

~~
~ 172
W;- W; W;
02 - 0 3 Collision: ~.3 _ 02 - 0 3 Collision: P:3 ~.3
~.3
~- ~ ~
W;- W;
~-
w.-3
~
W;
~1
~
W;
W;

(a) (b)

FIGURE 4.35. (a) A naive concatenation creates multiple entries for the final
linear and angular velocities of all bodies involved in more than one collision; (b)
The state-vector variables should have a link back to their collisions. More than
one link is used for multiple collisions, as is the case of V2 and Q2.

Since rigid body B2 is involved in both collisions, its final linear and
angular velocities V2 and O2 are accounted twice. The correct way to create
the state vector is, then, to keep track of which variables were already
4.8 Rigid Body-Rigid Body Collision Response 221

added, and mark as "common" the ones added more than once. This is
illustrated in Figure 4.35{b).
Having determined the state vector associated with a cluster, the next
step is to fill in the rows of matrix A and vector b. This can be done by
considering the equation associated with the first link of each variable in the
state vector. For example, for the G 1 cluster of Figure 4.34, the first variable
of the state vector is P1,2. This variable is linked to the (B1 - B 2) collision.
Its associated equations are those involving the coefficient of restitution
and friction. Therefore, the first row of matrix A and vector bis:

A 1 ,2 B 1 ,2 C 1 ,2 -B 1 ,2 E 1 ,2 0 0 0
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x X

P1,2 d~,2
V1 x
01 X

~ X

O2 X

P2,3 X

Va x
03 X

The second variable of the state vector is V1 . This variable is also linked
to the (B1 - B 2) collision. Its associated equations are the conservation of
linear momentum for body B 1 • So, the second row of matrix A and vector
b is:

A 1 ,2 B 1 ,2 C 1 ,2 -B 1 ,2 E 1 ,2 0 0 0
-I m11 0 0 0 0 0 0
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
222 4. Rigid-Body Systems

Pu, d-;',2
V1 m1 V1
01 X
V2 x
=
O2 X
P23, X

V3 x
03 X

Doing the same for all other state variables, we obtain:

A 1,2 B 1,2 C 1,2 -B1,2 E 1,2 0 0 0


-I m11 0 0 0 0 0 0
-T1 0 11 0 0 0 0 0
I 0 0 m21 0 0 0 0
T2 0 0 0 12 0 0 0
0 0 0 B 2,s C 2,S A 2,s -B2,s E 2,s
0 0 0 0 0 I m3 1 0
0 0 0 0 0 T3 0 Ts

P12, d-;',2
V1 m1 V1
01 11 W1
V2 m2V2 (4.86)
O2 12 w2
P23, d-;,3
V3 m3 V3
03 Isw3

Notice the difference in the order of the matrices displayed on rows 1


and 6 of the system matrix shown in equation (4.86). Since V2 and O2 are
common to both (B 1-B2) and (B 2-B3) collisions, the matrices A 2 ,s, B 2 ,s,
C 2 ,s and E 2 ,s were rearranged to correctly multiply their associated state
vector variables. The correct order is B 2 ,s multiplying the linear velocity of
the body with index 1 (Le., V2), C 2 ,s multiplying the angular velocity ofthe
body with index 1 (Le., O2 ), A 2 ,s multiplying the impulse associated with
collision (B2 - B3) (Le., P2 ,3), (-B2,S) multiplying the linear velocity of
the body with index 2 (Le., V3), and E 2 ,s multiplying the angular velocity
of the body with index 2 (Le., 0 3 .)
Also, notice that equation (4.86) was built following only the first link of
each state-vector variable. We still need to update equation (4.86) with the
multiple-collision terms. This can be done by considering the state variables
that have more than one associated link. The first link was used to define
4.8 Rigid Body-Rigid Body Collision Response 223

the row. The following links are used to update some elements of this row
with the multiple-collision terms.
In general, if body Bi is involved in more than one collision, then the
rows associated with ~ and ~t, that is, the rows associated with its final
linear and angular velocities, need to be updated. Say, for example, that
body Bi has a second link to body B j . Let Pi,j designate the state-vector
variable corresponding to the impulse associated with this collision. So,
the indexes of ~ and Oi in the state vector define the rows of the system
matrix to be updated, and the index of Pi,j in the state vector defines the
column of the system matrix that needs to be updated. Therefore, we need
to update the elements

[index of ~][index of Pi,j]

of the system matrix given in equation (4.86).


The actual update consists of accounting for Pi,j in the linear- and
angular-momentum equations associated with body B i . This can be done
by expressing Pi,j with respect to the local-coordinate frame of the collision
corresponding to the first link of the state variables ~ and Oi'
Say, for example, that the first link of the state variables ~ and Oi is
associated with collision Cm involving bodies Bm and B i . Let the local-
coordinate frame fm,i of collision (Bm - B i ) be defined by vectors iim,i,
4n,i and km,i'
Let the second link of the state variables ~ and Oi be associated with
collision Cj involving bodies Bi and B j . Let the local-coordinate frame fi,j
of collision (Bi - B j ) be defined by vectors iii,j, 4,j and ki,j' The collision
impulse Pi,j defined in the local frame fi,j is expressed in the local frame
fm,i as

with

Mit-+m,jt-+i = >. ( - -
ii·'t,)··iim,'l.. ii·'t,)··fm,t. ii···k
't,J
~,j . iim,i f.'t,l.. f m,t. ti,j . km,i
m,?'. )
.
ki,j . iim,i k-'t,].. f m,t. k-'t,l.. kffl,'l..

The variable>. can be either 1 or -1, depending on whether body Bi is


assigned to index 2 or 1 in collision Cj . The necessary updates are then

[index of ~] [index of Pi,j] = Pit-+m,jt-+i ,


224 4. Rigid-Body Systems

[index oHli ][index of Pi,j] = ). Ti .


As an example, let's apply this multiple-collision-terms update to the G 1
cluster example of Figure 4.34. In this example, the second link of V2 and
O2 points to the collision between bodies B2 and B 3 • Therefore, we need
to update the elements at
[index of V2][index of P2,3] = [4,6]

[index of O2][index of P2,3] = [5,6]


in the system matrix of equation 4.86. The actual update will be to sub-
stitute the current 0 matrix at position [4,6] for

n2,3 . nl,2 n2,3· t;,2 n2,3· k1,2 )


M 2o-+ 1 ,3o-+2 = ). ( t;,3 . nl,2 t;,3 . t;,2 t;,3 . k1,2 , (4.87)
k2,3 . nl,2 k2,3· [1,2 k2,3 . k1,2
where frame :F"t,2 is defined by vectors nl,2, t;,2 and k1,2, and frame :1"2,3
is defined by vectors n2,3, t;,3 and k2,3. We also need to substitute the
element at position [5, 6] for

(4.88)
Also, since body B2 is assigned to index 1 in its collision with body B3
(see Figure 4.34), we should use). = +1 in equations (4.87) and (4.88).
The final system matrix for this particular example is then:

A 1 ,2 B 1 ,2 C 1 ,2 -B 1 ,2 E 1 ,2 0 0 0
-I mIl 0 0 0 0 0 0
-Tl 0 11 0 0 0 0 0
I 0 0 m21 0 M 2 o-+1 ,3o-+2 0 0
T2 0 0 0 12 T2 0 0
0 0 0 B 2 ,3 C 2 ,3 A 2 ,3 -B 2 ,3 E 2 ,3
0 0 0 0 0 I m3 1 0
0 0 0 0 0 T3 0 T3

P1,2 d~,2
VI ml ih
01 11 (.It
V2 m2ih
O2 12 w2
P2,3 d;,3
V3 m3 V3
03 13 w3
4.8 Rigid Body-Rigid Body Collision Response 225

In summary, for each state-vector variable with more than one link, we
need to update the elements of the system matrix corresponding to each
of these collisions. When all elements are updated, we solve the resulting
linear system using, for example, Gaussian elimination techniques. Another
option would be to use specialized methods to solve sparse linear systems,
since the system matrix is often sparse. The solution would then give the
correct values of the state-vector variables to be used by the collision-
response module to prevent the objects from interpenetrating after collid-
ing.

4.8.3 Computing Contact Forces for a Single Contact


Two rigid bodies are said to be in contact whenever their relative velocities
along the collision normal is either zero, or less than a threshold value. In
such situations, a contact force should be applied, instead of the impulsive
force described in Section 4.8.l.
In the case of computing impulsive forces for rigid body-rigid body col-
lisions, the system is described by equations of conservation of linear and
angular momentum, and the coefficients of friction and restitution. Unfor-
tunately, these equations are no longer valid for the contact-force computa-
tion. Therefore, we need to derive other conditions to compute the contact
forces, based on the contact geometry 16 and dynamic state of each rigid
body. These conditions are exactly the same as those described in Chapter 3
for the particle-particle contact. They are rephrased here for convenience.
The first condition states that the relative acceleration of the rigid bodies
at the contact point, along the contact normal, should be greater than or
equal to zero, assuming that a negative value indicates that the bodies are
accelerating towards each other. In this case, if the computed contact force
is such that the relative acceleration at the contact point along the contact
normal is zero, then the bodies remain in contact. However, if their relative
acceleration is greater than zero, then contact is about to break.
The second condition implies that the contact-force component along the
contact normal should be greater than or equal to zero, indicating that the
rigid bodies are being pushed away from each other. The contact force is
not allowed to have a negative value, that is, is not allowed to keep the
bodies connected to each other, preventing their separation.
The third and last condition states that the contact force should be set
to zero if the contact between the rigid bodies is about to break. In other
words, if the relative acceleration at the contact point, along the contact
normal, is greater than zero, then contact is about to break and the contact
force should be set to zero.

16Whenever a collision becomes a contact, the collision normal will be referred to as


the contact normal.
226 4. Rigid-Body Systems

Let's translate these three conditions into equations that can be used
to compute the contact force. Figure 4.36 illustrates a typical situation in
which rigid bodies Bl and B2 are shown at the moment before contact, in

§
contact, and interpenetrating if a contact force is not applied.

B2

v
2 )

_ CM2 002

PI P2

(a) (b) (c)

FIGURE 4.36. (a) Rigid bodies Bl and B2 are about to touch each other at points
Pl and P2; (b) Contact is established whenever Pl = P2; (c) Interpenetration
occurs if (Pl - P2) . n < 0, where n is the contact normal.

Let ih(t) and P2(t) be the points on bodies Bl and B 2, respectively, that
are about to be in contact. Consider the vector if(t) defined as

qn(t)) ((Pl(t) - P2(t)) . ii(t) )


if(t) = ( qt(t) = (fh(t) - ih(t)) . ~t) , ( 4.89)
qk(t) (Pl(t) - P2(t)) . k(t)
where ii(t) is the contact normal, pointing from body B2 to body B l , and
itt) and k(t) are vectors defining the tangent plane at the contact. Clearly,
qn(t) defines a distance measure between points Pl(t) and ih(t), along the
contact normal, as a function of time. We have qn (t) > 0 if the bodies
are separated, qn(t) = 0 if the bodies are in contact, and qn(t) < 0 if the
bodies are interpenetrating (see Figure 4.36). Let tc be the instant at which
contact is established, that is

The first condition states that the relative acceleration at the contact
point, along the contact normal, should be greater than or equal to zero.
This is equivalent to assuring

(4.90)

If we let a( t) = (an (t), at (t), ak (t)) be the relative acceleration at the


contact point, we can rewrite equation (4.90) as
4.8 Rigid Body-Rigid Body Collision Response 227

The components at(t) and ak(t) define the relative acceleration at the
contact point on the tangent plane of the contact. They are used only if
static or dynamic friction are considered at the contact point, as will be
explained later in this section.
The second condition states that the contact-force component along the
contact normal should be non-negative, that is

(4.92)

where F = (Fn' Ft , Fk) is the contact force to be determined. If friction is


taken into account, the tangent components Ft and Fk of the contact force
are computed according to the Coulomb friction model. To elaborate, if
the relative velocity of the points ih and P2 along f is zero, or less than a
threshold value, then there is no sliding at the contact point. In this case,
the component F t will assume values in the range

depending on the relative acceleration component at (t) being positive or


negative. In other words, Ft will do its best to prevent the bodies from
sliding at the contact point by always opposing the relative acceleration
at (t) 17. On the other hand, if the relative velocity along f is greater than
the threshold value, then the bodies are sliding at the contact point and

depending on the relative acceleration at(t) being negative or positive. Here,


(Md)t is the dynamic coefficient of friction along direction f. A similar analy-
sis holds for k.
The third and last condition states that the contact force is zero if the
contact is breaking away, that is, if the relative acceleration along the con-
tact normal is positive. Equivalently, we have

(4.93)

meaning that, if Fn is greater than zero, then the bodies are in contact and
the relative acceleration is zero. Otherwise, if an is greater than zero, then
the contact is about to break and the contact force should be zero. Putting
it all together, we have that the computation of the contact force involves
solving the following system of equations:

17Notice that Ft is zero if at(t) is zero.


228 4. Rigid-Body Systems

an(tc) > 0
Fn > 0 (4.94)
Fn an(t c) O.

Here, we adopt the convention that a positive contact force + F is applied


to the rigid body BI (Le., the body with index 1) and a negative contact
force -F is applied to the rigid body B2 (Le., the body with index 2).
According to equation (4.90), the relative acceleration an(t), along the
contact normal, can be obtained by differentiating equation (4.89) twice
with respect to time. The first time derivative of equation (4.89) gives

( dfh(t) _ dih(t)) . ii(t) +


dt dt
( ~ ~) dii(t)
PI-P2 '~' (4.95)

or equivalently

(4.96)

where vPl (t) and vP2 (t) are the velocity vectors of points fit (t) and P2(t).
This gives us an expression for the relative velocity vn(t) = dq(t)/ dt of
points PI (t) and P2 (t) along the contact normal, as a function of their
velocities and collision normal. The time derivative of the collision normal
indicates its rate of change in direction as a function of time.
Differentiating equation (4.95) once more with respect to time, we obtain

(4.97)

or equivalently

(4.98)
4.8 Rigid Body-Rigid Body Collision Response 229

where ap ! (t) and ap2 (t) are the acceleration vectors of points PI (t) and P2(t).
This gives us an expression for the relative acceleration an(t) = d 2 q(t)j dt 2
of points PI (t) and P2 (t) along the contact normal, as a function of their
accelerations, velocities, contact normal and rate of change in direction of
the contact normal.
At the instant of contact t = t e , points PI(t) and P2(t) are coincident,
that is

(4.99)
Substituting equation (4.99) into (4.98), we obtain an expression for the
relative acceleration along the contact normal at the instant of contact:

According to equation (4.100), the relative acceleration at the instant of


contact has two terms. The first depends on the accelerations of the contact
points, which in turn are related to the contact force using Newton's law.
The second depends on the velocities of the contact points and the rate of
change in direction of the collision normal.
For now, let's assume the contact is frictionless, that is

F = Fn ii.
Later in this section, we shall relax this assumption and show how the
system of equations used in the frictionless case can be extended to cope
with friction.
If we isolate the terms that depend on the contact force from the terms
that do not, we can rewrite equation (4.100) as

an(te) = (all)n Fn + bl . (4.101)


Substituting equation (4.101) into (4.94) we obtain

((all)nFn+bt) > 0
Fn > 0 (4.102)
Fn ((all)n Fn + bt) O.

Thus, the computation of the contact force involves solving the system of
equations defined in (4.102), which is quadratic on Fn. One way of doing so
is to use quadratic-programming techniques. However, such techniques are
difficult to implement, often requiring the use of sophisticated numerical
software packages.
230 4. Rigid-Body Systems

Fortunately, the system of equations defined in (4.102) is also formally


similar to a numerical programming technique called linear complementar-
ity. The implementation using linear-complementarity techniques is signif-
icantly easier than the implementation of a quadratic program, and is dis-
cussed in detail in Appendix G. There, we start presenting solution methods
for the frictionless case, and show how to modify them to cope with static
and dynamic friction at the contacts. These modifications on the solution
method require that equation (4.102) be expanded to also consider the re-
lation between the relative-acceleration and contact-force components on
the tangent plane of the contact.
In the general case where friction is taken into account, the system of
equations becomes

(al1)n (a12)t (a13)k


( (a2dn (a22)t (a23)k
(a3dn (a32)t (a33)k
AF+b,
where

(4.103)

(4.104)

The solution method presented in Appendix G assumes both matrix A


and vector b are known constants computed from the geometric displace-
ment and dynamic state of the bodies at the instant of contact. Therefore,
we need to determine the coefficients of matrix A and vector b, before we
can apply the linear-complementarity techniques of Appendix G.
The first row of matrix A and vector b is obtained by expressing the
normal relative acceleration an(t c) at the instant of contact as a function
of the contact-force components Fn , Ft and Fk. This can be done using
equations (4.100), (4.103) and (4.104). Let's start by examining the second
term of these equations, namely

dfi(tc)
dt
df(t c)
dt
4.8 Rigid Body-Rigid Body Collision Response 231

The velocities of points PI and P2 are known quantities independent of


the contact force. We still need to compute the rate of change in direction
of the contact normal as a function of time. Section E.3.2 of Appendix E
presents a detailed description of how the time derivative of the contact
normal for the rigid body-rigid body case can be computed. There are
two possible ways of computing the time derivative of the normal vector,
depending on the type of contact being a vertex-face or edge-edge contact.
In either case, the result of the time derivative of the contact normal is
independent of the contact force. So, the contribution of the second term
of equations (4.100), (4.103) and (4.104) to matrix A is none, and to vector
b is

~
2 ( VI+ WI
~ X (~
PI -
~ ) - V2
rl ~ ~ X (~
- W2 P2
dn
~)) . dt
- r2

_ _ _ _ _ . . ,. _ _ dt
2 (VI + WI X (PI - rI) - V2 - W2 X (P2 - r2))· dt

~
2 ( VI ~
+ WI X
(~PI -
~)-
rl ~ ~
V2 - W2 X
(~ ~)) . dt
P2 - r2
dk
'
(4.105)

where d t; dt and d k/ dt are the time derivatives of the tangent-plane di-


rections computed following the techniques presented in Section E.4 of
Appendix E.
Now, let's focus on the first term of equations (4.100), (4.103) and (4.104),
namely the terms

(ap1 (te) - ap2 (t e)) n(t e )


(ap1 (t e ) - ap2 (t e )) r(te) (4.106)
(ap1 (t e ) - ap2 (t e )) k(t e ) .

The acceleration ap1 of point PI is obtained directly from equation (4.8)


as
ap1 = al x (PI - f't) + WI x (WI X (PI - TI)) + al ,
where aI, WI and al are the angular acceleration, angular velocity and
linear acceleration of body BI (see Figure 4.36). Using equation (4.11), the
linear acceleration al can be obtained from the net force (FI)net acting at
contact point PI as
232 4. Rigid-Body Systems

where (Fdext is the net external force (such as gravity, spring forces, spa-
tially dependent forces, etc.) acting on body B1 at t = t e , and F is the
contact force to be determined. Also, using equation (4.17), the angular
acceleration a1 can be computed from the net torque (ft}net acting at
contact point PI as

~
a1 =
I 1 -1 (~)
71 net + I 1 -1 H~1 X WI
~
, (4.107)

where 11 and iiI are the inertia tensor and angular momentum of body B 1,
respectively. The net torque acting on body B1 is computed by summing
the torque induced by all external forces, that is

torque resulting from contact force


..-----"----..
(f1)net = (f1)ext + (PI - r1) X F (4.108)

where

(f1)ext = ~)pi - r1) X (Fi)ext


i

with Pi being the point on body B1 at which the external force (Fi)ext is
being applied. Substituting equation (4.108) into (4.107), we obtain

(4.109)
The acceleration apl vf point PI is then

(4.110)

Using the general cross-product relations

ax b -b x a
axb ab
and letting

we can further simplify the first term of equation (4.110) as follows:


4.8 Rigid Body-Rigid Body Collision Response 233

(It -1 (ih - PI) X F) X (PI - PI)


(11 -1 Xl X F) X Xl
-Xl X (11 -1 Xl X F)
-Xl (11 -1 Xl X F)
-(XlI1-I)XI xF
- I 1 -1) Xl
- (Xl - F~ . (4.111)

Substituting equation (4.111) into (4.110), we have

~
apt
( ml
1 I -
- I 1 -1 Xl
Xl
- ) F~

+ ~ (FI)ext + (11 -1 (i't)ext + iiI X WI) X Xl


ml
+ WI X (WI X xd , (4.112)

which can be written as

(4.113)
with

Al (~l I - xIII -1 Xl)


bl ~ (FI)ext + (1 1 - 1 (rI}ext + iiI X wI) X Xl
ml
+ WI X (WI X xI) .

Analogously, the acceleration (12 of point P2 is given by

(4.114)

which can be further simplified to

(4.115)
with
234 4. Rigid-Body Systems

A2 1 1 - X2
( m2 - 12 -1 X2
- )

b2 = J-.
m2
(F2)ext + (12 -1 (T2)ext + H2 X W2) X X2
+ W2 X (W2 X X2) .
The relative acceleration at the contact point is therefore

(4.116)
The final contribution to the elements of vector bis obtained by summing
the individual contributions of equations (4.105) and (4.116). The matrix
A is obtained by adding up At and A 2 , as indicated in equation (4.116).
Applying the linear-complementarity techniques of Appendix G, we can
determine the components of the contact-force vector F. Having F, we
update the dynamic state of each rigid body by applying +F on body B1
and -F on body B 2 •

4.8.4 Computing Contact Forces for Multiple Contacts


The principle behind the computation of multiple rigid body-rigid body
contact forces is the same as that behind the computation of multiple rigid
body-rigid body collision impulses. Again, the simulation engine needs to
group the rigid bodies into clusters that share at least one contact. The con-
tacts within each cluster can then be simultaneously resolved independent
of all other clusters (see Figure 4.37).
Whenever a rigid body is involved in multiple contacts, it is possible to
have it assigned to different indexes for each contact. For the particular
situation of cluster G 2 in Figure 4.37, body B2 has index 2 with respect
to its contact with body Bb and index 1 with respect to its contact with
body B 3 • This in turn affects the choice of sign when combining the multiple
contact forces in the system equations. Moreover, the contact normal and
tangent plane are different for each contact. So, we also need to carry out
a change of base between the contact forces before combining them.
In the single rigid body-rigid body contact, the contact-force computa-
tion taking friction into account was done using linear-complementarity
techniques to solve a system of equations of the form

> 0
an(t c )
Fn > 0
Ft(AF+b) 0,
where
4.8 Rigid Body-Rigid Body Collision Response 235

Cluster G2

Cluster G1 Cluster G3

FIGURE 4.37. A multiple rigid body-rigid body contact-force computation. In


the situation shown, the rigid bodies are grouped into three clusters that can be
resolved in parallel.

A
( (all).
(a2dn
(a3dn
(a12)t
(a22)t
(a31)t
(a13)k
(a23h
(a33)k
)
F (Fn' FhFk)t
b ((bl)n, (b1)t, (b1)d .
This solution method can be extended to the case of multiple-contact-
force computations. The main difference between multiple- and single-
contact-force computation involving a given body is that the contact force
at contact Oi can affect the computation of the contact force at contact
Cj . So, instead of solving one contact at a time, we need to simultaneously
solve all contacts having a body in common. This in turn has the same
effect as merging the several individual systems of equations for each con-
tact into one larger system, and then applying the linear-complementarity
techniques to the merged system.
For example, suppose we have a cluster with m simultaneous contacts.
Each contact Ci is defined by its contact-normal (ii)i and tangent-plane
vectors (t)i and (kk The contact force at contact Ci is then expressed as

The contact-force vector for the multiple-collision system is obtained by


concatenating the contact-force vectors for each of the m contacts, that is
236 4. Rigid-Body Systems

The vector b becomes

and the matrix A is enlarged to accommodate all contact forces. Its parti-
tioned representation is given by

where each sub-matrix is given by

(ai(j+l) )ti
(a(i+l)(j+l) )ti
(a(i+2)(j+l»)ti

If contacts Ci and Cj have no bodies in common, the sub-matrix Aij is


set to 0, indicating that their contact forces do not affect each other. How-
ever, if contacts Ci and Cj do have a body in common, then the coefficients
aij are the contribution of the contact force at contact Cj to the relative
acceleration at contact C i . More specifically, the coefficient (aij )n, is the
contribution of the contact-force component (Fj)nj to the relative accel-
eration at the contact Ci . Analogously, the coefficients (aij)ti and (aij)ki
are, respectively, the contribution of the contact-force components (Fj)tj
and (Fj)k j to the relative acceleration at the contact Ci .
Also, notice that the contact force Pj is given with respect to the contact
frame of Cj , whereas the relative acceleration iii is given with respect to
the contact frame of Ci . Therefore, a change of basis is required when
computing the coefficients of matrix Aij and vector bi •
Suppose contact Ci involves bodies Bl and B 2 , and contact C j involves
bodies B2 and B 3 , that is, they have body B2 in common. We want to
determine the contribution of the contact force Pj of contact Cj to the
relative acceleration of contact Ci . This in turn involves determining the
coefficients of the sub-matrix Aij and the components (bi)n" (bi)t, and
(bi)k, of vector b. The relative acceleration at contact Ci between bodies
Bl and B2 is given by

(4.117)
4.8 Rigid Body-Rigid Body Collision Response 237

As explained in the single-contact case, only the first term of equa-


tions (4.117) depends on the forces exerted at contact Ci • The second term
depends on the linear and angular velocities, and is added to (bi)n" (bi)ti
and (bi)kil as appropriate. Thus, the contribution of the contact force Fj of
contact Cj does not affect the components of vector b. In other words, the
expressions used to compute vector b for the single-contact case are still
valid for the multiple-contact case, that is, the components (bi)n" (bi)ti
and (bi)ki of vector b are given by summing equations (4.105) and (4.116).
Using equation (4.61), the contribution of the contact force Fj of contact
Cj to the acceleration al of body Bl involved in collision Ci is

Conversely, the contribution of Fj to a2 is

The net contribution of Fj to the relative acceleration (al -(2) at contact


Ci is then

Substituting this into the first terms of equations (4.117), we obtain the
contributions of Fj to each relative-acceleration component at contact Ci
as

contribution to (ai)n; = i
9j· -
ni

contribution to (ai)ti g~. 4


contribution to (ai)k i

Using the fact that the contact force Fj is expressed with respect to the
contact frame Cj as

it can be written with respect to the contact frame Ci as


238 4. Rigid-Body Systems

with

Therefore, the coefficients of the sub-matrix Aij can be immediately ob-


tained after carrying out the matrix multiplication

(4.118)

Notice that, if i = j, then the matrix Mj>-ti becomes the identity ma-
trix, and the matrix Aij in (4.118) is the same as that obtained in equa-
tion (4.116) for the single-contact case. Also, if friction is not taken into
account, the sub-matrix Aij is reduced to

Aij = (aij)n. ,
since the contact-force components (Fj)tj and (Fj)k j are zero in the fric-
tionless case. This result is also compatible with that obtained for the
frictionless single-contact-force computation explained in Section 4.8.3.
Having computed the contact force Pi for each contact Gi , 1 ::; i ::; m,
we update the dynamic state of each rigid body involved in contact Ci by
applying +~ to body Bi (Le., the body with index 1) and -Pi to body
B2 (Le., the body with index 2.)
When a rigid body is involved in multiple contacts, it is possible to have
it assigned to different indexes for each contact. For the particular situation
of cluster G 2 in Figure 4.37, body B2 has index 2 with respect to its contact
C i with body B i , and index 1 with respect to its contact C 2 with body
B3. So, the net cQntact force actually applied to body B2 after all contact
forces have been computed is

with Pi and P2 being the contact forces associated with contacts C i and
C2 , respectively.

4.9 Particle-Rigid Body Contact Revisited


As mentioned in Section 3.7 of Chapter 3, the contact between a particle
and a rigid body is modeled as a particle-particle contact between the
4.9 Particle-Rigid Body Contact Revisited 239

particle itself and another particle on the rigid body's surface. Modeling
the contact in this way has the advantage of letting us use techniques
similar to those applied to the particle-particle case. The main differences
are:
1. The velocity and acceleration of the particle associated with the rigid
body are computed using the rigid-body dynamic equations derived
in Section 4.2, as opposed to using the particle dynamic equations of
Section 3.2.
2. The normal and tangent-plane directions are determined from the
rigid-body geometry. If the particle on the rigid body lies on a face,
edge or vertex, then the contact normal is assigned to the face, edge or
vertex normal, respectively. The actual computation of these normals
was already covered in Section 4.4.

Consider, for example, the particle-rigid body contact illustrated in Fig-


ure 4.38. Assume particle 0 1 is in contact with particle O2 of rigid body
B2•

FIGURE 4.38. Particle 01 is colliding with rigid body B1 at 02. The velocity vP2
and acceleration iip2 of point ih are computed using the rigid body's equations
of motion.

Let ih(t) and P2(t) be the points representing the particles in contact.
Analogously to both particle-particle and rigid body-rigid body single con-
tact cases, we consider the vector q(t) defined as

qn(t)) ((P1(t) - P2(t))· n(t) )


q(t) = ( qt(t) = (P1(t) - P2(t)) . ~t) , (4.119)
qk(t) (P1(t) - P2(t))· k(t)
where n(t) is the contact normal, pointing from particle O2 to particle 0 1 ,
and l{t) and k(t) are vectors defining the tangent plane at the contact.
240 4. Rigid-Body Systems

Clearly, qn (t) defines a distance measure between points PI (t) and P2 (t),
along the contact normal, as a function of time. We have qn(t) > 0 if
the particles are separated, qn (t) = 0 if the particles are in contact, and
qn(t) < 0 if the particles are interpenetrating (see Figure 4.39).

OltiJ P1
I
I
I
I
I

(a) (b) (c)

FIGURE 4.39. (a) Particles 0 1 and O 2 E B2 are about to touch each other at
points ift and ih; (b) Contact is established whenever PI = P2. In this case, a
positive contact force F is applied to particle 0 1 and a negative contact force - F
is applied to particle O2; (c) Interpenetration occurs if (PI - P2) . n < 0, where n
is the contact normal.

The relative normal acceleration at the contact point is therefore that


obtained for the particle-particle single contact, given by

(4.120)

The contact conditions derived in Section 3.6.3 still hold here:

an = «al1)n Fn + (bdn) > 0


Fn > 0
Fn «al1)n Fn + (bl)n) 0

and the contact force can be computed using the linear-complementarity


techniques presented in Appendix G. The relative acceleration can be writ-
ten as a linear function of the contact force, that is

(4.121)

and we need to determine the coefficients of matrix A and vector b corre-


sponding to the particle-rigid body contact case. Equation (4.121) can be
expanded to
4.9 Particle-Rigid Body Contact Revisited 241

(adt (aI3)k
(a22)t (a23)k
(a32)t (a33h

where

(4.123)

(4.124)

and

is the associated contact force. From the results already obtained in Sec-
tions 3.6.3 and 4.8.3, we know that the contributions of the contact force to
the relative acceleration come only from the first term of equation (4.120).
More specifically, the acceleration of particle 0 1 can be expressed as

(4.125)

where (.F\)ext is the sum of all external forces acting on particle 0 1 , The
acceleration of particle O2 can be determined from the rigid-body motion
as

where matrix A2 and vector 62 are obtained from equation (4.115). The
relative acceleration (apt - apJ is then

(4.126)

which is already in the desired matrix format of equation (4.122).


242 4. Rigid-Body Systems

Now, let's examine the second term of equations (4.120), (4.123) and
(4.124), namely:

dii
2(Vpl - Vp2 )
dt
dt
2(Vpl - Vp2 ) (4.127)
dt
dk
2(VPl - vp2 ) dt
From the results of Sections 3.6.3 and 4.8.3, we already know that these
terms are independent of the contact force, meaning they only affect the
coefficients of vector b. The computation of the time derivatives of the
contact frame, that is, the derivatives of the normal and tangent vectors ii,
t and k is covered in Sections E.3.2 and E.4 of Appendix E. Therefore, in
the following derivations we shall assume these to be known quantities.
The velocity of particle O2 is computed from the rigid-body motion as

V P2 = V2 + W2 X (P2 - r2) • (4.128)


Substituting equation (4.128) into (4.127), we have that the contribu-
tion of the second term of equations (4.120), (4.123) and (4.124) to the
coefficients of vector b is:

_ _ _ (_ _)) d fi
2 (Vi - V2 - W2 X P2 - r2 .-
dt
-
2( Vi - - W2
- V2 - X (-
P2 -)) .dt
- r2 - (4.129)
dt
(b 1 )k -
2 (Vi - - W2
- V2 - X (-
P2 -)) .
- r2 dk .
dt
The final coefficients of vector b are obtained by summing equations
(4.129) with the components of the b vector of equation (4.126). Having
computed the contact force, we apply +F to particle 0 1 and - F to rigid
body B2 at point P2.

4.10 Notes and Comments


Nowadays, there is a substantial number of books and journal articles in
the literature that address several aspects of the dynamics of rigid bodies.
In this chapter, we used the classic Goldstein [GoI50], and the more recent
Beer et al. [BJ77b] and Shabana [Sha94], books as the main references to
rigid-body dynamics. Another excellent reference is Baraff et al. [BW98b]
4.10 Notes and Comments 243

SIGGRAPH course notes. For example, the derivations of the dynamic


state of a rigid body using the position, rotation matrix, linear and angular
momenta follows the same line of thought as that presented by Baraff et
al. in their course notes.
The collision-detection and response algorithms presented in this chap-
ter assume rigid bodies to be described by their boundary representation,
that is, a list of vertices, edges and faces that make up the rigid body's
contour. Campagna et al. [CKS98] present a data-structure representation
especially tailored for triangle meshes using this boundary representation.
It trades memory usage for access time by adding redundant linking. in-
formation. Using this representation, we can access in constant time every
edge and vertex of a given face, every edge incident on a given vertex and
every face that contains this vertex, as well as every vertex of a given edge
and the faces that share an edge. As far as the collision normal computa-
tion is concerned, Thiirmer et al. [TW98] present an alternate method for
computing vertex normals that reduces the dependence of the normal on
the underlying mesh representation. This is achieved by adding weights to
the contribution of each face using the angle under which the face is inci-
dent to the vertex in question (Le., it uses the average normal computation
weighted by incidence angle).
We also discussed in detail two collision-detection algorithms especially
tailored for convex bodies, namely the Voronoi Clip and the GJK algo-
rithms. The Voronoi Clip algorithm was developed by Mirtich [Mir97],
whereas the GJK algorithm was developed by Gilbert, Johnson and Keerthi
(see [GJK88]). The original references have pointers to implementations of
these algorithms provided by their authors. In the case of the GJK algo-
rithm, Bergen [vdB99]' Cameron [Cam97] and Ong et al. [OG97] describe
more robust and efficient implementations than that provided by the origi-
nal authors. Even though the Minkowski difference is never explicitly com-
puted in the GJK algorithm, the interested reader is referred to Berg et
al. [dBvKOS97], Rourke [O'R98] or Skiena [Ski97] for an in-depth descrip-
tion of how the Minkowski sum and difference are computed.
The collision-response module described in this chapter can be sub-
divided into two sub-modules: one to compute collision impulses, and an-
other to compute contact forces. Hahn [Hah88] and Mirtich [Mir96b] used
the concept of micro-collisions to simulate bodies in contact. That is, con-
tact is simulated as a series of several consecutive collisions. Mirtich went
one step further and modeled the relative slipping and sticking of the col-
lision point through the (very short) time interval the bodies are colliding.
Another interesting approach to model the relative slipping and sticking of
the collision point was developed by Keller [KeI86].
The approach developed in this chapter to deal with friction in collisions
is based on the critical-friction-coefficient formulation of Brach [Bra91].
We have extended his work in several ways, however. First, we have ex-
plicitly derived the computation of the critical-friction coefficient for sin-
244 4. Rigid-Body Systems

gle collisions. Second, we present an innovative matrix representation with


columns and rows arranged in such way that it can be easily extended to
multiple collisions. Last, but not least, our method reduces the multiple-
collision problem to the solution of a large sparse linear system (see Duff
et al. [DER86] for a comprehensive treatment of sparse matrix methods).
The formulation of the contact-force computation as a quadratic-pro-
gramming problem was originally introduced by Lotstedt [Lot84]. Baraff
(see [Bar92, Bar89, Bar90]) initially modeled the contact-force computation
as a quadratic program, but used a heuristic formulation to solve the prob-
lem by linear-programming techniques. He then extended his heuristic ap-
proach to cope with friction (see Baraff [Bar91]), and later presented other
algorithms to solve the quadratic program using the linear-complementarity
(see Baraff [Bar94]) formulation.
In this book, we focused our approach to computing contact forces using
Baraff's linear-complementarity formulation. We have modified Baraff's
formulation to cope with directional friction at the contact points. This in
turn required some modification of the linear-complementarity algorithm
used to compute the contact forces, described in detail in Appendix G.
Preliminary results on an alternate contact-force computation technique
using singular value decomposition are presented by Mirtich [Mir98]. An-
other interesting work in applying the linear-complementarity formula-
tion to compute multiple collision impulses with friction was presented
by Kawachi et al. [KSK97].
Lastly, the integration of particle and rigid-body systems proposed in
this book is at the simulation-engine level, that is, embedding the neces-
sary functionality into a single simulation engine. However, there may be
situations in which we want to merge different simulation engines, perhaps
developed by different teams. In this case, a simulation-engine level inte-
gration may be very difficult, and a higher-level integration technique is
needed. Such a technique can be found in Baraff et al. [BW97].
5
Articulated Rigid-Body Systems

5.1 Introduction
The dynamic simulation of rigid-body systems covered in the previous chap-
ter can be further extended to the case of articulated rigid-body systems,
where bodies are attached to each other using joints. There are several
types of joints that can be used to connect bodies, and they differ from
each other by the degree of freedom of the relative motion allowed. Sev-
eral methods have been proposed to address the dynamics of articulated
systems, and most of them fall into one of the following two categories.
In the first category, the dynamic equations describing the system's mo-
tion are formulated using a reduced set of variables. This is the so called
reduced coordinate formulation. The reduced set of variables, also known
as generalized coordinates, is obtained by removing all degrees of freedom
constrained by the joints. The result is a set of parameterized coordinates
that fully describes the motion of the entire articulated system while as-
suring the joint constraints. In the second category, additional constraint
forces are introduced in the system to assure the joint constraints through-
out motion. This method is known as the Lagmngian formulation. The idea
is to formulate equations relating the constraint forces (also referred to as
the Lagrangian mUltipliers) with the dynamic state of the articulated sys-
tem. In the case of articulated rigid-body systems, the formulation consists
of building and solving a linear system (often sparse) for the joint forces.
Sparsity can then be used advantageously to derive O(n) algorithms, where
n is the total number of articulated bodies being considered.

M. G. Coutinho, Dynamic Simulations of Multibody Systems


© Springer Science+Business Media New York 2001
246 5. Articulated Rigid-Body Systems

In this book we shall direct our analysis to techniques based solely on


the Lagrangian formulation. Even though the reduced-coordinate formula-
tion is in some cases more effective than the Lagrangian approach, there
are still several reasons for using the Lagrangian formulation as opposed
to the reduced-coordinate formulation in a software implementation. The
most important reason in our view is modularity, in the sense that, once
the joints are specified, their constraints can be formulated in terms of ac-
celeration conditions at the joint points, and a linear system relating the
joint forces with the dynamic state of the system is readily obtained from
such acceleration conditions. In other words, as soon as the acceleration
conditions are determined from the type of joints being used, the mathe-
matical framework for computing the joint-constraint forces is exactly the
same for all types of joints. For simplicity, we shall focus on the underlying
mathematical framework for the case in which the articulated system is
connected by spherical joints only. Section 5.5 contains pointers to the lit-
erature where the derivation of the acceleration conditions for other types
of joints can be found. Such conditions can be easily applied to the math-
ematical framework presented in this chapter.
By definition, spherical joints do not allow relative translations, only
relative rotations between the interconnected bodies. Therefore, they have
three degrees of freedom to rotate the bodies with respect to the coordinate
axis defined by the joint axis and two orthogonal axes on the plane per-
pendicular to the joint axis. Figure 5.1 shows the schematic representation
of a spherical joint.

FIGURE 5.1. Bodies Bl and B2 connected by a spherical joint. The joint con-
strains the motion to relative rotations only (relative translations are disallowed).

Most of the notions discussed in Chapter 4 for rigid-body systems can


be directly applied to articulated rigid-body systems. The main difference
in the mathematical formulation between rigid bodies and articulated rigid
bodies consists of enforcing the joint constraints throughout the motion,
especially when the articulated body is colliding, or in contact with itself
or other articulated bodies.
5.2 Articulated Rigid-Body Dynamics 247

5.2 Articulated Rigid-Body Dynamics


The dynamic state of an articulated rigid body can always be viewed as
the concatenation of the dynamic state of each of its links. Consider the
articulated rigid body shown in Figure 5.2, containing eight links (Le., eight
rigid bodies) and eight spherical joints.

FIGURE 5.2. An example of an articulated body with eight bodies connected by


eight spherical joints.

The dynamic state of the articulated rigid body can be expressed as

(5.1)

where each iMt) for i E {1, ... ,8}, represents the dynamic state of body i
given by

with fi(t), Ri(t), Li(t) and Hi(t) being the position and orientation of body
Bi'S center of mass, and the body's linear and angular momenta, respec-
tively. To numerically integrate the equations of motion of the articulated
body, we first need to compute the time derivative of its dynamic state.
Deriving equation (5.1) with respect to time, we get

d y(t) _ (d Yl(t) d Y2(t) d Ys(t)) t


( i t - ---;],t' ---;],t' ... , ---;],t , (5.2)

where each d Yi (t) / dt is given by


248 5. Articulated Rigid-Body Systems

dili(t) = (
dt
Wi(~~i(t) )
~i(t)
. (5.3)
fi(t)
The variables Vi(t), Wi(t), FHt) and fi(t) in equation (5.3) are body Bi'S
linear velocity, angular velocity, net force and net torque acting on its center
of mass.
Clearly from equations (5.2) and (5.3), the numerical integration of the
equations of motion can only be carried out if all external forces and torques
acting on each body (Le., each link) are known. In the case of articulated
bodies, the motion of the bodies is constrained by the joints attached to
them. This constraint is represented by a joint force Pi associated with
joint J i , which acts as an external force applied to the connected bodies.
So, in order to numerically integrate the equations of motion of an articu-
lated body, we need to first determine the constraint forces associated with
each joint in the system. These constraint forces are then summed with all
other external forces acting on each interconnected body, thus completely
defining the net external force and torque on each link. Having determined
the net external force and torque acting on each body, we can proceed with
the numerical integration of equation (5.2) and determine the position and
orientation of each link at the end of the current time step being considered.
Since the motion of each body influences the motion of all other bodies
it is connected to, all constraint forces need to be simultaneously computed
to ensure that the connected bodies will remain connected after all external
forces and torques are applied to all bodies in the articulation. The goal is
then to derive an expression that relates how the dynamics of each inter-
connected rigid body are affected by the application of the joint force. This
expression will then be used to simultaneously compute all joint forces.
As far as notation is concerned, the notation in this section significantly
differs from that used in upcoming sections 5.4.1 and 5.4.2, for computing
impulsive and contact forces between connected links. In those sections,
the index of the linked bodies is used to generate the correct index of
the impulsive or contact forces associated with each joint. For example,
the joint connecting bodies Bi and B j is referred to as joint Jij , and its
associated contact and impulsive forces are Pij and Pij . In this section, the
index of each joint is used to generate the correct index of the linked bodies.
For instance, the bodies connected by joint Ji are referred to as bodies
(Bl)i and (B 2 )i, and the Pi represents the joint force constraining their
relative motion l . These different notations for computing the dynamics of
the articulated system and responding to collisions and contacts requires a

1 By convention, a positive joint force +Pi is applied to body (Bl)i, whereas a negative
joint force -Pi is applied to body (B2k
5.2 Articulated Rigid-Body Dynamics 249

redundant underlying representation of the system. More specifically, the


software data structures should be such that given a link (i.e., a body) we
can efficiently obtain the joints it is connected to, and given a joint we can
quickly return the two links attached to it.
For the sake of clarity, we shall first focus on the derivation of the expres-
sion relating the joint force and the dynamics of the interconnected bodies
for the two-body articulated system shown in Figure 5.3. Later in this sec-
tion, we shall generalize the derivation for the case of a n-body articulated
system.

-I;
(B2 ),

FIGURE 5.3. Bodies (Bl)i and (B 2)i are connected by the spherical joint Ji at
points (Pl)i E (Bt)i and (P2)i E (B2k

Let (fit)i and (P'2)i be the points on bodies (B1)i and (B 2 )i to which joint
Ji is attached. Since the relative motion of the interconnected bodies in the
case of spherical joints is constrained to rotations only, the relative position
of the joint points on each body should remain the same throughout the
motion, that is

(5.4)
Using techniques similar to those in Section 4.8.3 for computing the
contact force between two rigid bodies, we can relate the joint force to
the dynamic state of the connected bodies by differentiating equation (5.4)
twice in time. Differentiating once we have

(5.5)
that is, the velocity at the joint points should remain the same throughout
the movement. Differentiating one more time, we obtain

(5.6)
indicating that the accelerations at the joint points should be the same as
well. According to equation (4.110) on page 232, the acceleration (ap1)i of
the joint point (Pdi is given by
250 5. Articulated Rigid-Body Systems

(5.7)

where Fi , (Fdext and (fi)ext are, respectively, the joint force, the net exter-
nal force and the net external torque acting on body (Blk The variables
11 , 1"1, iiI and WI are the inertia tensor, center of mass position, angular
momentum and angular velocity of body (Bl)i, all computed with respect
to the world-coordinate frame.
Equation (5.7) can be further simplified to (see derivation of equation
(4.113) on page 233):

(5.8)
with

(~l I - Xl 11 -1 Xl)
~
ml
(Fl)ext + (1 1 - 1 (Tl)ext + iiI X wI) X Xl
+ WI X (WI X xI)
(Pdi - 1"1 .
Analogollsly, the acceleration at joint point (P2)i can be expressed as

(5.9)
with

(~2 I - X2 h -1 X2 )

~ (F2)ext + (h -1 (T2)ext + ii2 X W2) X X2


m2
+ W2 X (W2 X X2)
(P2)i - 1'2 .
Substituting equations (5.8) and (5.9) into equation (5.6), we get

that is
5.2 Articulated Rigid-Body Dynamics 251

«A1)i + (A 2 )i) Fi = -(bdi + (b2 )i . (5.10)


Clearly, the joint force Fi can be immediately obtained by solving the
linear system given in equation (5.10). Also, it can be shown that matrix
«A1)i + (A 2 )i) is always invertible, and that the linear system in equa-
tion (5.10) is always solvable.
Now, consider the situation in which the articulated system is composed
of n bodies connected by q spherical joints. For each joint J i in the system,
we still have to assure

(5.11)
where the indexes 1 and 2 refer to bodies (B 1 )i and (B 2 )i connected by
joint J i • However, the accelerations at the joint points (Le., points (iJdi
and (ft2)i) may involve one or more joint forces, as opposed to just one
joint force, as in equations (5.8) and (5.9) for the two-body case. More
specifically, the accelerations at the joint points will involve as many joint
forces as there are joints attached to the body. Consider the articulated
body of Figure 5.2, repeated in Figure 5.4 with the body index assignment
for each joint.

FIGURE 5.4. For each joint in the system, we assign indexes to the bodies at-
tached to it. Bodies attached to more than one joint are assigned multiple indexes.
We then use this assignment to build the linear system containing all joint equa-
tions.

With this arbitrary index assignment, bodies attached to multiple joints


may have different indexes associated with each joint. For instance, body
B3 has index 1 with respect to joint h and index 2 with respect to joints
hand J8' Recall that the index relates the sign of the joint force applied
to the body, namely index 1 indicates a positive sign and index 2 indicates
a negative sign. So, the constraint equation (5.11) applied to joint J 1 gives

(5.12)
252 5. Articulated lligid-Body Systems

that is, the acceleration (aPt h depends only on the joint force fA, whereas
the acceleration (ap2 h depends on the joint forces fA and P2 , since body
B2 is attached to joints J 1 and J 2 (see Figure 5.4). Since body B2 has index
2 with respect to joint Jl, and index 1 with respect to joint h, we use a
negative sign preceeding PI and a positive sign preceeding P2 on the right
term of equation (5.12).
Notice the extra superscript used on all matrices and vectors in equa-
tion (5.12). This superscript indicates the joint point the computation is
referring to. For example, matrix (A2H is computed as the coefficient ma-
trix of the body with index 2 of joint J 1 , applied to the joint point on J 1 •
Matrix (Al)~' on the other hand, is the coefficient matrix of the body with
index 1 of joint h, applied to tje joint 'point on Jt.
In general, the terms (Ai)1 Fj and (bi )3 refer to the coefficients of the
body with index i E {1,2} of joint J j , applied to the joint point on Jq , and
are computed as

( -mi l
-q
1 I -x· I i -1 X·
l
-q)
= ~ (Pi)ext + (Ii -1 (1;)ext + iii
mi
X Wi) x Xi
+ Wi X (Wi X Xi) ,
with

Notice that, for the two-body case, we have just one joint, that is, q = i
and the superscript index q can be ignored.
Moving all unknown forces to the left side of equation (5.12), we can
rewrite it as

Now, applying the constraint equation (5.11) to joint h gives

which can be rearranged as


5.3 Collision Detection 253

Doing the same for all other joints, we can group the eight joint equations
into the following linear system:

(AlH + (A2H -(Al)~ 0 0


-(A2)~ (Ad~ + (A2)~ -(Al)~ 0
0 -(A2)~ (Al)g + (A 2)g -(Al)~
0 0 -(A2): (Al)~ + (A2)~
0 0 0 (A2)~
0 0 0 0
0 0 0 0
0 (A2)~ -(Al)~ 0
0 0 0 0
0 0 0 (A2)~
0 0 0 -(A2)g
(A2): 0 0 0
(Al)g + (A 2)g (Al)g 0 0
(Al)g (Al )3 + (A2)3 (A2)~ 0
0 (A2)~ (Al)i + (A 2 )i (Al)~
0 0 (Al)~ (Ad: + (A2):

Solving this linear system for the joint forces, we can obtain the contact
forces at each joint and compute the net force and net torque acting on
each body. This will let us numerically integrate the articulated system's
equation of motion.

5.3 Collision Detection


The collision detection between articulated bodies and other rigid bodies,
articulated rigid bodies and particles, can be viewed as an extension of the
collision-detection techniques already explained in Chapter 4. Detecting
collisions between articulated bodies and other bodies is the roughly same
as detecting collisions between each individual link of the articulation and
other bodies. Efficiency is achieved by taking advantage of the hierarchical
254 5. Articulated Rigid-Body Systems

tree representation of each link in the articulation to build a hierarchical


tree representation of the articulated system as a whole.
The idea is to use a two-level hierarchical tree representation of the artic-
ulated system to efficiently carry out the collision checks. At the first level,
each individual link is represented by its own hierarchical tree. The leaves of
such trees are the triangular faces defining the geometric boundary of the
link. At the second level, the individual hierarchical tree representations
of each link are substituted for the root node of their tree, and another
hierarchical tree is built having the root nodes of each link as its leaves.
In other words, the second-level hierarchical tree is a tree where each of
its leaves is a hierarchical tree itself. Figures 5.5, 5.6 and 5.7 show this
two-level hierarchical tree representation for a simple articulated body.

FIGURE 5.5. An articulated body.

FIGURE 5.6. First-level hierarchical tree representation contains the individual


representations of each link of the articulated body shown in Figure 5.5.
5.3 Collision Detection 255

FIGURE 5.7. Root node of the hierarchical tree representation of each link ob-
tained in the first level is used as a leaf of the hierarchical tree built at the second
level. The root node of the tree at the second level contains the entire articulated
structure, as shown here.

The collision check involving articulated rigid bodies is therefore a two-


step process. Checking for collisions between two articulated bodies con-
sists of first checking for geometric intersections between their second-level
hierarchical tree representations. If no intersections are found, then the
articulated bodies are not colliding. Otherwise, the intersecting leaves of
their second-level representation are substituted for their· corresponding
first-level hierarchical tree (recall that each leaf of the second level is a
hierarchical tree of itself). The algorithm proceeds checking for collisions
between the hierarchical tree representations of the intersecting leaves. If
no intersections are found, then the articulated bodies are not colliding.
Otherwise, the intersecting leaves of the first level are substituted for the
triangular faces they represent. At this point, several triangle-triangle inter-
section tests are carried out to detect whether there are pairs of intersecting
triangular faces, one on each articulated body being checked for collision.
Whenever an intersection is detected, the articulated bodies are said to be
colliding and their trajectories are traced back in time to the moment be-
fore the most recent collision, that is, just before a pair of triangular faces
intersects for the first time. The geometric displacement of the faces is then
used to compute a collision normal and tangent plane, in the same manner
already explained in Section 4.4, for rigid body-rigid body collisions.
Checking for collisions between an articulated body and a single rigid
body is equivalent to checking for collisions between two articulated bod-
ies, with one of them having just one link and zero joints. Again, we start by
checking for geometric intersections between the root node of the hierarchi-
cal tree representation of the rigid body and the second-level hierarchical
tree representing the articulated body. If an intersection is detected, then
256 5. Articulated Rigid-Body Systems

the leaves of the second-level tree that are intersecting the root node of the
single rigid body are further expanded into their corresponding first-level
hierarchical trees. The collision detection then proceeds by checking for in-
tersections between the expanded leaves and the rigid body's hierarchical
tree. The latter is analogous to intersecting two rigid bodies.
The two-level hierarchical tree representation of articulated bodies can
also be used to detect self-collisions. Notice that each link in the articulated
body can be viewed as a single rigid body itself. Therefore, checking for self-
collisions is equivalent to checking for collisions between several single rigid
bodies (Le., the links) and the !1rticulated body, as explained in the previous
paragraph. Of course, the collision check between a link and the articulated
body will always return the link itself as an intersection. We should discard
this case and look for the existence of intersections between the link being
considered and other links in the articulation. If the intersection of the
link with itself is the only one found, then the link does not intersect any
other link in the articulation. Repeating this process for each link in the
articulation will efficiently detect whether self-collisions exist.

5.4 Collision Response


Responding to collisions involving articulated bodies is inevitably a multi-
collision problem. Whenever a collision is detected with one of the artic-
ulated links, the resulting collision impulse propagates its reaction to all
other bodies in the articulation through their joint connections. In other
words, external collisions between the articulated rigid body and other
bodies (possibly other articulated rigid bodies as well) create a sequence
of internal collisions between the links at their connecting joints. The way
this sequence of internal collisions is resolved depends on the mathematical
model used to describe the collisions.
Consider the situation illustrated by Figure 5.8(a), where two articulated
rigid bodies are colliding at point Pi. The collision normal and tangent plane
at the collision point Pi are computed from the bodies' relative geometric
displacement just before their collision, using the same techniques discussed
in Section 4.8, page 204, for the case of rigid body-rigid body collisions.
The external-collision impulse Pl,4 generated by this collision will affect
the dynamic state of bodies Bl and B 4 , as well as all other bodies attached
to them. This modification of the dynamic state of each link is represented
by a set of internal-collision impulses, one for each joint of the articulation
(see Figure 5.8(b)). Clearly, one way to solve this multiple-collision problem
would be to propagate the impulsive reactions to the external collision as if
it were a wave passing through each joint. In this case, the joint-impulsive
reactions would be incrementally computed as if they happened at different
instants. For example, we would first compute P1,4 ignoring the internal
5.4 Collision Response 257

(a) (b)

FIGURE 5.8. (a) Two articulated rigid bodies are colliding at point Pii (b) The
external-collision impulse Pl,4 between bodies Bl and B4 creates impulsive reac-
tions at each joint.

dynamics of the articulation. Then we would solve for P3,4 and P4,5 on
one articulation, and for PI ,2 on the other. Finally, we would compute P5 ,6
taking into account that the other impulses have already been applied to
the system (i.e., they occured at different instants).
There are two fundamental problems with this approach. The first prob-
lem is efficiency. In the particular situation shown in Figure 5.8, we would
have to execute the collision-response module three consecutive times, one
for computing PI,4, another for P3,4 and P4,5, and a third for P5 ,6' The sec-
ond problem has the potential to never successfully complete the internal-
collision-impulse computations, by going to an infinite-loop mode. This can
potentially happen every time one of the articulated systems has cycles (see
Figure 5.9).
In this book, we shall overlook the propagation time and assume that all
internal collisions happen at the same time as the external collisions gener-
ating them. By so doing, the external-collision impulses will simultaneously
affect the dynamic state of all links. Put another way, all collision impulses
(external and internal) will be simultaneously computed by solving a linear
system of equations involving the dynamic state of the bodies and the im-
pulses. Notice, however, that, even though this assumption produces very
good results for articulations containing a small number of links, it can sig-
nificantly over simplify the impulse-propagation mechanism for articulated
systems containing a large number of interconnected links.
In the following sections we shall examine in more detail how the several
collision-response mechanisms discussed in Chapter 4 can be adapted to
the case of articulated systems.
258 5. Articulated Rigid-Body Systems

FIGURE 5.9. Hazardous situation when incrementally computing the inter-


nal-collision impulses at each joint in response to an external collision. The exis-
tence of closed loops in the articulated topology requires all internal impulses to
be computed at once.

5.4.1 Computing Impulsive Forces for Single or Multiple


External Collisions
The simultaneous computation of all internal and external collision im-
pulses can be done using exactly the same multiple-rigid-body-collision
techniques already developed in Section 4.8.2. Recall that the computation
of multiple-collision impulses consists of building and solving a sparse lin-
ear system of equations. It was shown that the sparse-system matrix can
be partitioned into block matrices of the form Ai,q, Bi,q, Ci,q and Ei,q,
where the indexes i and q refer to collision C iq between bodies Bi and B q.
The rows of each block matrix are chosen from a set of four possible com-
binations by comparing the coefficient of friction along each tangent-plane
direction with their associated critical coefficient of friction 2 •
Using this multiple-rigid-body-collision response framework, each indi-
vidual link will be treated as a single, independent body, and each joint
will be dealt with as a collision point between its links. It remains to assure
that the links stay together at their joint points, as opposed to separat-
ing because of the application of the collision impulses. In other words, we
need to assure the joint constraints at each joint when computing their
corresponding collision impulses.
In the case of spherical joints, the relative motion of its links is con-
strained to rotations only. According to equations (5.4), (5.5) and (5.6), the
position, velocity and acceleration of the joint points on each link should
coincide throughout the motion. This was used in Section 5.2 to derive
expressions relating the joint forces and the dynamics of their links. Here

2Refer to Section 4.8.1, page 212, for a detailed discussion of the techniques used to
compute the critical coefficient of friction.
5.4 Collision Response 259

we use the other two constraints, on position and velocity, to relate the
impulses at each joint with the dynamic state of their corresponding links.
Let's start by analyzing the position constraint. Because the positions
of the joint points on each link should coincide for the entire motion (see
equation (5.4)), they cannot slide with respect to each other during a col-
lision. In other words, the use of the critical-coefficient-of-friction value to
determine whether the colliding points (Le., joint points) are sliding or
sticking during a collision is no longer necessary. There is no need to com-
pute the value for each joint because we already know that the collision
points should stick to each other during a collision.
As for the velocity constraint, the joint points should always remain
with the same velocity throughout the motion (see equation (5.5)), that is,
the links should not separate at their joint points after any collision. This
condition can be translated into all joint collisions having a zero coefficient
of restitution (inelastic collisions).
In general, the coefficient-of-restitution equation should be replaced by
the velocity-constraint equation imposed by the type of joint being used.
In the case of spherical joints, the velocity-constraint equation is equivalent
to forcing the coefficient of restitution to be zero, but this is not always the
case for other types of joints. Please refer to Section 5.5 for pointers to the
literature where the velocity-constraint equations for other types of joints
are derived, such as the prismatic and revolute joints.
Therefore, the four possible cases for defining the rows of each block
matrix Ai,q, Bi,q, Ci,q and Ei,q, as discussed in Section 4.8.2, are reduced
to just one case, namely the case in which

(5.13)

In summary, we build the system matrix containing all internal and ex-
ternal impulses by selecting the appropriate block-matrix representation
for each collision. The block-matrix representation associated with all ex-
ternal collisions is selected following the same rules applied to the single-
rigid-body-collision case, in which the colliding points can slide or stick to
each other during the collision. However, the block-matrix representation
associated with each internal collision is constrained to that shown in equa-
tion (5.13), where the indexes i and q refer to bodies Bi and Bq connected
by joint J iq 3 .

3Using this fonnulation, a positive collision impulse Pi,q is applied to body Bi, and
a negative collision impulse -Pi,q is applied to body Bq at joint Jiq'
260 5. Articulated Rigid-Body Systems

5.4.2 Computing Contact Forces for Single or Multiple


External Contacts
Whenever one or more links of an articulated body are in contact with
each other, or with other bodies in the simulated world, the contact force
at the each contact point will affect the dynamics of motion of the entire
articulation. This is analogous to the multiple-rigid-body-contact situation
described in Section 4.8.4 on page 234. Recall that the simultaneous com-
putation of all contact forces involves building and solving a Linear Com-
plementarity Problem (LCP), with the contact forces and accelerations
constrained to non-negative values. Contact points that end with zero rel-
ative accelerations remain in contact after the application of the contact
forces, whereas contacts with positive accelerations will break up as soon
as the contact forces are applied. Contacts having zero contact forces are
just touching each other and mayor may not break up, depending on the
value of their corresponding relative accelerations.
The idea here is to use the exact techniques already described in Sec-
tion 4.8.4. The only modifications needed are those necessary to assure
the spherical-joint constraints after the contact forces be applied to the
system. These modifications should be implemented as part of the LCP so-
lution method described in Appendix G. According to the results presented
in Appendix G, the LCP solution method incrementally computes the con-
tact force at contact Ci while enforcing the normal- and frictional-contact
conditions at all other contacts j (with j < i) already considered. This
requires bookkeeping the indexes of all contact points already considered
such that, at any point during the computation, an index will be in one
subset of each of the following three groups.
1. ZAn or ZFn , depending on its normal-acceleration and contact-force
components along the normal direction n.
2. ZA t , MaxFt or MinFt, depending on its tangential-acceleration and
contact-force components along the tangent direction f.
3. ZA k , MaxFk or MinFk , depending on its tangential-acceleration and
contact-force components along the tangent direction k.
Because the position of the joint points must coincide throughout the
entire motion, it is necessary to assure that the relative acceleration at
all joint contacts must always be zero. This requires modifying the LCP
solution method to assign all indexes corresponding to a joint contact to
groups ZAn, ZA t and ZAk, and never displace them. Doing this guarantees
that the relative acceleration at the joint points will be zero after all contact
forces are applied, that is, that the links will remain connected at their joint
points throughout the entire motion.
According to the LCP solution method discussed in Appendix G, the
contact-point indexes are moved back and forth between different subsets
5.4 Collision Response 261

of each of the three main groups, depending on their relative accelerations


or contact forces be assigned a negative value. For instance, a contact point
with index in ZAn has a positive normal-contact-force component and zero
relative normal acceleration. If in the next iteration of the LCP solution
algorithm the normal-contact-force component assumes a negative value,
then the system is evolved up to the point at which the normal-contact-
force component assumes a zero value, and the index of such a contact point
is moved from ZAn to ZFn in order to prevent the normal-contact-force
component becoming negative. This in turn permits the relative normal
acceleration to assume any positive value.
In the case of a joint contact, we need to force the relative accelera-
tion to be always zero. This may require having a negative contact force
at the joint, since we cannot move the contact index out of the zero-
acceleration subsets. The following modifications are needed for computing
contact forces when the contact index refers to a joint contact.

1. The joint contact force can have any value, as opposed to having only
non-negative values (as is the case of external contacts). In practice,
a negative joint contact force means that the local-coordinate frame
used at the joint contact (Le., the direction of the normal and tan-
gential coordinate axes) is inverted.
2. The tangential components of the joint-contact force can also have
any value, as opposed to being limited to J.L F n , that is, the normal
component multiplied by the coefficient of friction associated with
the tangent direction being considered.
In summary, the LCP solution method discussed in Appendix G can be
modified to deal with joint contact forces by forcing their indexes to be
always included in the zero-acceleration subsets, and by letting the joint
contact forces assume any finite value. This requires keeping track of which
indexes correspond to joint contacts, and adding a conditional statement
at the force-computation module to not bother if the contact force of a
joint contact becomes negative.
As for implementation, numerical round-off errors can offset the joint
points by small values each time the simulation loop is executed. The offset
is usually not noticeable at the first few simulation time steps, but can be-
come a problem for simulations that are executed for a substantial amount
of time. In these cases, the position of the joint points computed using their
corresponding links' dynamic state may no longer coincide with each other,
reaching a situation in which their separation is visible on the screen. This
is clearly not a "feature" that dynamic-simulation systems want to exhibit.
A practical workaround to situations like this consists of adding a fictitious
spring with zero resting length connecting the joint points. Whenever the
joint points separate from each other owing to round-off errors, the spring
force will bring the points together again. The stiffness of the spring to be
262 5. Articulated Rigid-Body Systems

used depends on the mass of the bodies connected by the joint (the heavier
the bodies, the stiffer the spring should be).

5.5 Notes and Comments


In this chapter we have tried to cover a small but important subset of the
several types of techniques applicable to mechanisms commonly used in
dynamic simulations of articulated systems. Even though we have concen-
trated our analysis on rigid bodies connected by spherical joints, the same
techniques can be applied to other types of joints. Different types of joints
have different joint constraints to be enforced, thus requiring modifications
on the actual constraint equations to be used. However, the general princi-
ple of defining the joint constraints and differentiating them twice in time
to relate the joint forces and the dynamic state of the articulated system
remains unchanged. The differentiation in time may be easier or more dif-
ficult to obtain depending on the joint being considered, but the principle
remains the same.
As for responding to collisions, independent of the type of joint be-
ing used, its velocity constraint should always replace the coe£ficient-of-
restitution equation. The latter is applicable only when the colliding bodies
are not interconnected at the collision point. The contact-force computa-
tion, on the other hand, may require creating other types of groups on the
LCP solution method described in Appendix G, in order to accommodate
the joint constraints. For example, in the case of prismatic joints, the inter-
connected bodies are constrained to translations along the joint axis only.
The relative acceleration of the bodies along the joint axis can be zero,
positive or negative, whereas their relative-acceleration components on the
contact plane perpendicular to the joint axis should always be zero. This in
turn requires creating special-purpose subsets to keep track of the indexes
of the prismatic-joint contact forces. For instance, we can think of creating
a ZAanYn subset for normal component accelerations that can assume any
value.
The derivation of the dynamics of motion of multibody systems intercon-
nected by spherical joints was based on the work of Hecker [HecOOa, HecOOb]
and Baraff [Bar96]. The use of springs, as well as other techniques, to off-
set the existence of numerical round-off errors on the position of the joint
points can be found in Baumgarte [Bau72] and Barzel et al. [BB88J, among
others.
Shabana [Sha94] presents joint-constraint formulations for other types of
joints not covered in this book, such as the prismatic joint(one degree of
freedom to translate along the joint axis), the revolute joint (one degree
of freedom to rotate about the joint axis), and the cylindrical joint (two
degrees of freedom to translate along, and rotate about, the joint axis).
5.5 Notes and Comments 263

Other interesting types of constraint formulations can be found in Barzel


et al. [BB88].
Mirtich's [Mir96b] work on constrained rigid-body dynamics is focused on
using revolute and prismatic joints to interconnect bodies. His formulation
uses spatial-operator algebra (see also Rodriguez et al. [RJKD92j), and ex-
tends Featherstone [Fea83, Fea87] to cope with tree-like linkage structures;
it further presented some control-systems techniques to kinematically con-
trol 4 the motion of articulated bodies. Brach [Bra91] considers chains of
rigid bodies interconnected by several types of joints, but limits his analyzes
to the two-dimensional case.
Finally, readers interested in the simulation of flexible bodies are referred
to the work of Terzopoulos [Ter87] and Shabana [Sha98], where the work
on computational dynamics is extended to the study of elastic deformable
bodies.

4By kinematical control we mean that the linear and angular position, velocity and
acceleration of the bodies are obtained from an animation system, possibly by interpo-
lating their values between two consecutive animation frames.
Appendix A
Useful 3D Geometric Constructions

A.I Introduction
In this appendix we shall cover some geometrical constructions used as
building blocks to implement the several intersection tests that are part of
the particle-particle, particle-rigid body and rigid body-rigid body collision-
detection algorithms presented in this book. We shall also discuss in Sec-
tion A.6 how the tangent plane of a collision (or contact) can be determined
given the collision (or contact) normal vector.
We shall use the following notation to describe some of these tests. A
point Pi in 3D space will be denoted as

Pi = ((Pi)X, (Pi)y, (Pi)z) .


A line segment Ls is defined by its two end points PI and jh, and is given
by

with 0 ~ k ~ 1.
The plane f3 is described by its normal n{3 and a point P!3 in the plane.
Any point PE f3 satisfies the equation
p. n{3 = d{3 ,
where d{3 is the plane constant obtained from
266 Appendix A. Useful 3D Geometric Constructions

A.2 Projection of a Point on a Line


The projection il of point P on line L passing through points PI and P2 is a
point of L (see Figure A.I) and therefore satisfies the line equation, that is

FIGURE A.I. Projecting p on line L.

il = PI + k (ff2 - pt) , (A.I)


where k E IR is a scalar variable to be determined. Notice also that the
vector (p - ij) is perpendicular to the line, that is

(p - ij) . (P2 - pt) = 0 . (A.2)


Substituting equation (A.I) into (A.2) and solving for k, we have

(p - PI) . (P2 - PI)


(A.3)
k = (P2 - pt) . (P2 - PI) .
The projection point ilis directly obtained by substituting equation (A.3)
into (A.I). The distance d between P and line L is given by

d = Ip- ill·

A.3 Projection of a Point on a Plane


The projection il of a point P on a plane /3 can be computed as follows. The
projected point il satisfies the plane equation, that is

(A.4)
Moreover, the vector (p - ij) is parallel to the plane normal n{3 (see
Figure A.2), that is

(A.5)
A.4 Intersection of a Line Segment and a Plane 267

------ ij

FIGURE A.2. Projecting p on plane (3.

where k is a scalar that needs to be determined.


Substituting equation (A.5) into (A.4), and solving for k, we obtain

k = p._nf3 -_ df3 . (A.6)


nf3 • nf3
Substituting equation (A.6) into (A.5) we obtain the projected point if
_ _ p. nf3 - df3 _
q= p- _ _ nf3.
nf3 . nf3

The distance d between point p and plane (3 is computed from

d= Ip _ ifl = Ip ._nf3 -= df31 .


nf3 . nf3

A.4 Intersection of a Line Segment and a Plane


The intersection between a line segment and a plane can be the line segment
itself (if the line is in the plane), a point or an empty set. Let L be the line
segment connecting points PI and P2, and let (3 be the plane with which
we want to compute the intersection.
The intersection will be the line itself whenever

that is, the line is perpendicular to the plane normal, and

that is, its points belong to the plane as well.


Now, suppose the line is such that
268 Appendix A. Useful 3D Geometric Constructions

The idea is then to first intersect the infinite line supporting the line
segment with the plane (let's call gthis intersection point), and then check
whether 9 lies between the end points defining the segment. If it does, then
9 is the actual intersection. Otherwise, the line segment does not intersect
the plane. Let's first compute the intersection point g. We know 9 lies on
the infinite line supporting the line segment, that is

(A.7)
where kg E IR is a scalar variable to be determined. We also know that the
intersection point belongs to the plane, that is

(A.8)
Substituting equation (A.8) into (A.7), and solving for kg, we obtain

d{J - PI . ii{J
kg = (~ ~)~.
P2 - PI . n{J
If 0 :::; kg :::; 1, then the intersection point 9 lies between the end points
of the line segment, and the line segment does intersect the plane. Other-
wise, the intersection point lies outside the segment and the plane does not
intersect the line segment.

A.5 Closest Point between a Line and a Line


Segment
Given a line L passing through points hI and h2' and a line segment Ls
defined by its two end points PI and P2, we want to determine the point
pELs that is closer to line L than any other point in Ls. This is illustrated
in Figure A.3.
The closest point P belongs to line segment L s , that is

(A.9)
where 0 :::; kp :::; 1 is a scalar to be determined. Alternatively, we can rewrite
equation (A.9) as

(A.lO)

Let iit and ih be the projections of points PI and P2 on line l L. We


compute d l and d 2 as the distance between points PI and P2 and their
associated projection points.

lThe projection of a point on a line was already discussed in Section A.2.


A.5 Closest Point between a Line and a Line Segment 269

FIGURE A.3. Computing the closest point between a line and a line segment.

Now, consider the auxiliary plane /3 perpendicular to line L and passing


through fit (see Figure A.3). Let ii be the projection of point P2 on plane /3,
computed according to Section A.3. We compute the distance d3 between
ii and Pl.
Let crepresent the projection of point P(still to be determined) on plane
/3. By construction, triangles (P1.c,PJ and (P1.ii,P2) are similar, that is

(A.ll)

where the last equality was obtained using equation (A.lO). Also, notice
that triangles (ii, qi, C) and (p1, c, ib) are rectangular on c, and

Applying the Pythagorean theorem to each triangle, we obtain

d~ = 1c - qi 12 + 1c - P1 12 ,
d~ 1c - q1 12 + 1ii - cl 2 .

Eliminating 1c - ql1 2 from the above equations, we have


d 21 - d22 - 12 - 1a- - c-1 2 .
= 1-C - P1 (A.12)
Factoring out the right-hand side of equation (A.12):

d~ - d~ = (I c - P1 1+ 1ii - cD(1 c - P11-1 ii - cD· (A.13)


From Figure A.3, we immediately have
270 Appendix A. Useful 3D Geometric Constructions

12- PI 1+ 1a- 21 = d3 . (A.14)


Substituting equation (A.14) into (A.13):

( 2l 2)
1C- - PI- 1- 1a- - c-I = d d- d 2
3
. (A.15)

Solving equations (A.15) and (A.14) for 12- PI I, we obtain


_ - 1 - (di - d~ + d~)
1
C - PI - 2d3 . (A.16)

Finally, substituting equations (A.16) and (A.14) into (A.U) we compute


the scalar kp as

k _ (di - d~ + d~)
p - 2d 2
3

If 0 < kp < 1, then the closest point P lies inside the line segment L8
and is obtained directly from equation (A.9). If kp :S 0, then we set P = Pl.
Otherwise, kp ~ 1 and we set P = P2.

A.6 Computing the Collision- or Contact-Local


Frame from the Collision- or Contact-Normal
Vector
The relative displacement of the colliding particles or rigid bodies is used
to determine the collision normal at the collision point. The actual com-
putation of the collision normal is slightly different depending on whether
we are considering particle-particle, particle-rigid body or rigid body-rigid
body collisions. Assume that the collision- or contact-normal vector is given
by n, and that the tangent plane is defined by two vectors f and k, mu-
tually perpendicular and perpendicular to n as well. Together, they form
the local-coordinate system, usually referred to as the collision frame, with
origin at the collision (or contact) point. The computation of the tangent
planes done after the collision normal is determined, and depends strictly
on it.
All impulsive and contact forces are computed with respect to their local
collision frames. Assuming n is known, the question is how we can determine
the other vectors f and k? The answer is simple: there are several ways we
can generate the other two vectors from the normal vector. In this book,
however, we shall use the following approach.
Let the collision normal be given as n = (nx, ny, n z ). The vector f =
(tx, t y , t z ) is perpendicular to n, that is
A.7 Representing Cross-Products as Matrix-Vector multiplication 271

f· n = tx nx + ty ny + tz n z = 0 . (A.17)
Clearly, we have just one equation and three variables, namely tx, ty
and t". The idea is then to establish some rules to assign values to the
variables so that equation (A.17) can be satisfied. To that end, we undertake
the following steps. Compute the absolute value of each component of the
normal vector n, and compare them such that:

1. If Inxl < Inyl and Inxl < Inzl, then set the auxiliary vector a to

2. If Inyl < Inxl and Inyl < Inzl, then set the auxiliary vector a to

3. If Inzl < Inxl and Inzl < In"l, then set the auxiliary vector a to

The tangent vector f will then be given by

The other vector k is immediately obtained as


k = n x f,
since it is perpendicular to both nand f.

A.7 Representing Cross-Products as Matrix-Vector


multiplication
Sometimes it is useful to represent a cross-product as a matrix-vector mul-
tiplication. Consider the cross-product between vectors a = (ax, ay, a,,) and
b= (b x , by, b,,), namely
ay b" - by az )
a x b= ( -ax b" + bx az . (A.18)
ax by - bx ay
Now, let's define the matrix a obtained from vector a as
272 Appendix A. Useful 3D Geometric Constructions

( )
0 -a z ay
a= az 0 -ax (A.19)
-a y ax 0

If we multiply b by the matrix a we obtain

(A.20)

Comparing equations (A.18) and (A.20), we immediately conclude that

(A.2I)
Equation (A.2I) is known as the matrix-vector representation of the
a
cross-product between vectors and b, where the matrix a is constructed
a
from vector as indicated in equation (A.19).

A.8 Suggested Readings


Most of the geometric constructions presented in this appendix are stan-
dard and can be found in almost all computer graphics books. In this
appendix, we decided to use the same notation and solution methods pre-
sented by Glassner [Gla90], excepting both the computation of the clos-
est point between a line and a line segment (obtained from Karabassi et
al. [KPTB99]), and the determination of the tangent plane given the normal
vector (obtained from Hughes et al. [HM99]).
Appendix B
Numerical Solution of Ordinary
Differential Equations of Motion

B.l Introduction
The simulation engine is constantly required to compute the dynamic state
of all rigid bodies and particles in the scene!, owing to the net torque and
net force being exerted on them. In the case of rigid bodies, this com-
putation requires numerically solving four first-order ordinary differential
equations (ODEs) of motion: two coupled equations for the linear momen-
tum and linear position of the body, and two coupled equations for the
angular momentum and angular position of the body. The four ODEs of
motion are:

dx(t)
iJ(t) = fx(t, x)
dt
dL(t)
F(t) = h(t, L)
dt
(B.l)
dR(t)
w(t) R(t) = fR(t, R)
dt
dH(t)
dt

1 In this appendix, the word scene refers to the simulated world containing all bodies
being simulated.
274 Appendix B. Numerical Solution of ODEs of Motion

where x(t), iJ(t), L(t), w(t) and ii(t) are the linear position, linear velocity,
linear momentum, angular velocity and angular momentum, respectively,
of the body being moved. The optional function-style representation of the
time derivatives in equation (B.l) is used to simplify the notation and make
the equations in this Appendix more readable.
Recall from Chapter 4 that the linear and angular momentum are com-
puted as

L(t) miJ(t)
ii(t) = I(t) w(t) ,

with m and I(t) being the mass and inertia tensor of the body at time t.
The inertia tensor of the body is computed relative to the world (fixed)
frame, and is given by

where Ib is the (constant) inertia tensor relative to the body's frame 2 •


The remaining variables in equation (B. 1) are the rotation matrix R( t)
representing the angular position of the body at time t, the net force F(t)
acting on the center of mass of the body, and the net torque r( t) computed
from
n
r(t) = ~)Xi(t) - xcm(t)) x Fi(t) ,
i=l

where n is the total number of external forces acting on the body at time
t, Fi(t) is the ith external force, Xi is the point on the body at which force
Fi(t) is being applied, and Xcm(t) is the current position of the body's
center of mass.
In the case of particle-systems simulation, the angular-momentum and
angular-position equations in (B.1) are not applicable, and the ODEs of
motion are reduced to the two coupled equations involving the linear mo-
mentum and linear position of the particle. Here, we shall represent the
dynamic equations as a single state vector Y(t), given by

Y(t) = ( ~(t) ) dY(t) = ( ~(t) ) (B.2)


L(t) dt ~(t)

for particles, or

2See Appendix D for details on how to compute the inertia tensor Ib in body-frame
coordinates.
B.1 Introduction 275

_
(
x(t) )
R(t) dY(t)
( w(t2'v(t)R(t) )
(B.3)
Y(t) = ~(t) dt F(t)
H(t) i'(t)
for rigid bodies. Most of the formulas presented in this appendix are ex-
pressed in terms of this single state vector representation, also referred to
as the dynamic-state vector of a particle or rigid body in Chapters 3 and 4,
respectively. Since the ODEs for particles are a subset of the ODEs for rigid
bodies, we shall focus on the solution equations for the latter.
The numerical integration of the ODEs of motion consists of starting at
an initial configuration where all positions and momenta are known, and
gradually increase the independent variable t (time) through finite steps
h (time step), computing the approximate value of the linear and angular
positions and momenta of the body being moved that best match the Taylor
series expansion of their exact solution. The Taylor series expansion of the
exact solution Y(t) at t = (ti + h), when the values of Y(t i ) (the initial
condition) and h are known, is given by the infinite sum

Y-(. h) = ~ h n [)nY(ti) = y-(.) h[)Y(ti ) h 2 [)2Y(ti) (B 4)


t, + ~'>l n
n. vt t, + >l
v + .2' vt
t >l 2 + . ... .
n=O

The degree to which the approximate solution matches the exact solution
depends on how close it matches the Taylor series expansion of the exact
solution. In other words, the approximate solution is usually a truncation of
the Taylor series expansion and the omitted terms reflect the error between
the exact and approximate solutions. The point at which the truncation
takes place depends on the integration method being used.
In general, the numerical solution of equations (B.2) and (B.3) for time
t = (ti + h) requires the complete knowledge of the state of the system
at time t = ti' Starting at the very first time step t = to, the simulation
engine knows the initial state of the system, that is, it knows the linear and
angular positions and momenta of each body in the scene. In most cases,
the initial linear and angular momenta are set to zero, but nothing prevents
us from assigning any finite value to them. At each subsequent time step,
the simulation engine computes the net force and torque acting on each
body in the scene, and numerically solves equations (B.2) and (B.3) for
these values.
It is important to recognize that, independent of the numerical method
being used,_ the simulation engine will always be required to compute the
net torque and net force acting on each body at the time interval being con-
sidered. Simple numerical methods usually require just one computation at
the beginning of each time step. However, as will be shown in Section B.3,
there are numerical methods that require computing the net force and net
276 Appendix B. Numerical Solution of ODEs of Motion

torque acting on the body not only at the beginning of the time interval, but
also at some intermediate time values along the current time step. These
methods usually combine such intermediate information to obtain the ap-
proximate solution for the entire time step. In these cases, the simulation
engine needs to temporarily position the bodies at these intermediate time
values before it can compute the net torque and net force acting on them.
It is also clear from equation (B.4) that the choice of time step h directly
affects the efficiency and stability of the numerical method being used. Too
big a step, and the approximate solution may no longer resemble the exact
solution; too short a step, and the efficiency can be unnecessarily dragged to
unbearable levels. This is true for all methods presented in this appendix,
and the problem of estimating the error and determining the right time
step h to be used in order to keep the error below a threshold value is
discussed in detail in Section B.4. For now, let's consider each integration
method assuming that the time step h is adequate to keep the numerical
error under control.

B.2 Euler Method


The Euler method is by far the simplest, and least accurate, of all methods
presented in this appendix. Nonetheless, it is important to understand it
because other methods are constructed on top of the basic ideas presented
here.

B.2.1 Explicit Euler


The explicit Euler method, also known as the forward Euler method, ap-
proximates the Taylor series expansion up to its first order, that is, it
approximates the infinite sum given in equation (B.4) by a straight line.
The approximate solution Y(ti + h) is then obtained from

Y(ti) + h d~~ti) + O(h2)


Y(ti) + h Jy(ti' Y) + O(h2) , (B.5)

with O(h2) representing the order of the error obtained from truncating
equation (B.4) at its second term. Figure B.1 illustrates the basic idea
behind the explicit Euler method. The slope of the curve is computed once
at time ti, and is assumed to be constant for the entire time step (remember
that this is a straight-line approximation!).
The explicit Euler method can be used to numerically integrate our ODEs
of motion given in equations (B.2) and (B.3) for any body that is being
moved in the scene, as follows. We have the initial time to and the time
B.2 Euler Method 277

yet) Approximate
solution

FIGURE B.l. The exact solution is approximated by a straight line segment. The
slope of the line is determined at time ti and is assumed to be constant over the
entire time step h.

step h being used. We know the body's linear and angular positions and
momenta at time to, namely

x(to) )
- ( R(to)
Y(to) = ~(to) , (B.6)
H(to)
where

mv(to) ,
I(to) w(to) .
According to equation (B.5), the time derivative of the dynamic state of
the body is computed once at time to. This computation consists of first
determining the net force F(to) and net torque f'(to) acting on the center
of mass of the body at time to, and then substituting this information into
equation (B.3) to get

d5\to) = ( w(t0t;i(to) ) . (B.7)


dt F(to)
f'(to)
Therefore, the numerical solution using the explicit Euler method is given
by

x(to) + hv(to) )
Y( h) = Y( ) h dY(to) = ( R(to) + hw(to~ R(to)
to + to + dt mv(to) + hF(to) .
I(to) w(to) + h f'(to)
278 Appendix B. Numerical Solution of ODEs of Motion

B.2.2 Implicit Euler


Depending on the type of external forces acting on the body, the net torque
and net force computations can sometimes introduce a linear, or even a non-
linear, relation between the accelerations and the positions and velocities of
the bodies in the scene. This dependence introduces linear (or non-linear)
coefficients in the ODEs of motion that can considerably complicate their
numerical integration. For example, if two bodies are connected by a spring,
the net torque and net force acting on them will have a contribution from
the spring force, which in turn depends on the relative displacement of
the bodies. The same spring can be pulling the bodies together in one
time step, and pushing the bodies apart in another, subsequent, time step.
In this case, the position dependence of the spring force introduces linear
coefficients on the ODEs of motion.
In the more general case where there is dependence between the net force,
and positions and velocities of the body, equation (B. 1) can be rewritten
as

dx(t)
-(cx(t))t v(t)
dt
dL(t)
-(cL(t))t F(t)
dt
(B.8)
dR(t)
-(CR(t»t Q(t) R(t)
dt
dii(t)
-(CH(t))t T'(t) ,
dt
where (C'x(t))t, (cL(t))t, (CR(t))t and (CH(t))t are positive variables that can
be either linear or non-linear. In the following paragraphs, we shall restrict
our discussion to the case where all C are linear coefficients with a constant
value in the time interval being considered3 . All interaction forces covered
in this book fall into this category.
A practical issue that is of special concern when such coefficients exist
is the numerical stability of the solution method being applied. Clearly,
the numerical stability of equations (B.8) is closely related to the time
step h being used. If the time step is too big, the numerical solution may
significantly differ from the exact solution, and, as the integration evolves,
may no longer follow the exact solution. In extreme cases, the numerical
integration becomes unstable, oscillating with increasing amplitudes and
moving further away from the exact solution.

3They may have different constant values for different time intervals, but their value
is constant within the same time interval.
B.2 Euler Method 279

The maximum time step h that can be used in the numerical integra-
tion of equations (B.8), still producing a stable result, is directly related
to the magnitudes of the coefficients c( t). If their magnitudes differ by a
significant degree (Le., one is orders of magnitude greater than the oth-
ers), the maximum time step h will be limited by the inverse of the largest
magnitude value. Notice that this limitation is for purposes of stability
rather than accuracy. As will be explained in more detail in Section B.4,
even though the numerical error analysis may indicate that we can safely
increase the current time step h being used, the stability analysis may say
that we should not increase the time step if we want to keep the numerical
integration stable. Since the maximum time step h is limited by the inverse
of the largest magnitude value, there may be cases when the maximum
time step h needed to be used to guarantee numerical stability is so small
that efficiency is severely impaired, and the simulation seems to be not
moving forward in time anymore. When situations like that occur, we say
that equations (B.8) are stiff.
The implicit Euler method, also known as the backwards Euler method,
is generally used when the ODEs of motion form a set of stiff equations.
This method gives us a way of using larger time steps h when we have stiff
equations, at the expense of being less accurate; this is a good trade-off
considering that we were not moving forward using the smaller time steps
anyway. Therefore, in the implicit Euler method, we care more for stability
than accuracy4. The basic idea is to use a similar Euler approximation
technique to compute Y(to + h) as in equation (B.5). The difference here
is that, instead of computing the time derivative at the beginning of the
time interval, we compute it at the end of the time interval, that is

Y(ti + h) = Y(t i ) + h dY(d/ h) (B.g)


From equations (B.8), we know that

dY(ti + h) __ (~ )t y~(.
dt - Cy t, + h) ,
where

Substituting this information into equation (B.9), we have

(B.IO)
which we can solve for Y(ti + h). Even though the derivation of equa-
tion (B.IO) considered only the single-variable case, we can in fact combine

4Stability analysis of this method indicates that the numerical solution is stable for
all time-step sizes.
280 Appendix B. Numerical Solution of ODEs of Motion

all linear and angular equations associated with a rigid body into a linear
system of the form

(B.ll)
where C is the positive definite coefficient matrix. In practice, the linear
system in equation (B.ll) is often sparse, depending on the type of force
interactions between the bodies in the scene. This means that, instead of
using a general O(n 3 ) linear equation solver to determine the solution of a
n dimensional system, we can take advantage of specialized sparse-matrix
solvers that can compute a solution for equation (B.ll) in O(n).

B.3 Runge-Kutta Method


The Runge-Kutta method extends the basic idea of the explicit Euler
method of computing the time derivative at the beginning of the time
interval by computing intermediate values of the time derivatives through-
out the time interval, and combining these values to match the Taylor
series expansion up to some truncation term. The coefficients (or weights)
of each of the terms being combined are carefully chosen to cancel out as
many low-order derivative terms of the infinite sum in equation (B.4) as
possible, leaving the higher-order derivatives not canceled out as part of
the truncation error. The number of intermediate values used depends on
the order of the Runge-Kutta method being applied.

B.3.1 Second- Order Runge-K utta Method


The second-order Runge-Kutta method, also known as midpoint method,
combines the information of two "Euler like" steps to approximate the
Taylor series expansion up to its third term. The approximate solution
Y (ti + h) is then determined from

k1 hfy(t i , Y) , (B.12)

k2 h - k1
+ "2' y + 2) ,
h Jy (ti (B.13)

Y(to + h) Y(to) + k2 + O(h3) . (B.14)

Figure B.2 illustrates the basic idea behind this method. The time deriv-
ative is evaluated once at time to to get a first estimative of the slope of
the curve. This estimative is used to determine the midpoint of the curve
at time t = (to + h/2). Another time derivative is then evaluated to deter-
mine the slope of the curve at the midpoint, which is then used as a linear
B.3 Runge-Kutta Method 281

approximation of the slope of the curve for the entire time step, as is illus-
trated in Figure B.2(b). The numerical integration of the ODEs of motion
using the second-order Runge-Kutta method can be determined from the
following procedure.

I
ji(t) ji(t)

hj(t"y) ~~~~---
ji(t,) - ji(t,) _
I ji(t,+h) -
I
ti ti + h/2 t, +h

(a) (b)

FIGURE B.2. (a) A Euler-like step is computed using the information at time ti to
determine the first estimative fy(to,i/) of the slope of the curve. The result is then
used to compute the slope ofthe curve at its midpoint, i.e. fy(to + h/2, ii+ 1.1 /2).
(b) The slope of the midpoint approximates the slope of the curve for the entire
time step. Notice that the straight line approximating the curve is parallel to the
tangent to the curve at the midpoint shown in (a), that is, has the same slope as
fy(to + h/2,ii+ 1.1/2).

As in the explicit Euler method, we have the initial time to and the time
step h. We also know the body's linear and angular positions and momenta
at time to, namely

( R(to)
x(to) )
Y(to) = (B.15)
L(to)
H(to)

where

L(to) mv(to) ,
(B.16)
H(to) I(to) w(to) .

Again, we can compute the net force F(to) and net torque f(to) acting
on the body at time to. Substituting these values into equation (B.12), we
can compute the k1 's for the linear and angular positions and momenta
of the body. Using the function-style notation for the time derivatives, we
have:
282 Appendix B. Numerical Solution of ODEs of Motion

(B.I7)

Now, according to equation (B.I3), we need to use these estimates to


evaluate the linear and angular accelerations of the body at the midpoint.
We need to compute:

h fx(to + h/2, x + kix / 2) )


k2 = ( h fR(tO + h/2, I!; + ~lR/ 2) . (B.I8)
hJL(to + h/2,L + klL /2)
h fB(to + h/2, ii + kiB /2)
In plain English, equation (B.I8) says that, at the midpoint, the body
will be positioned at (x+k lx /2), oriented by (R+ki R/2), with linear and
angular momenta given by (£ + kiL/ 2) and (ii + klH /2), respectively. In
other words, the second arguments of the f functions in equation (B.I8)
are in fact the initial conditions at the midpoint, namely:

x(to + h/2)) ( x(to) + (h/2) v(to) )


Y( !!.) = ( I!;(to + h/2) = R(t~) + (h/2) w(t0 R(to)
to + 2 L(to + h/2) L(to) + (h/2) F(to) .
ii(to + h/2) H(to) + (h/2) f'(to)
We still need to determine the net force and net torque acting on the
body at the midpoint. This can be done by first positioning the body at
x(to+h/2) with orientation R(to+h/2), then setting its linear and angular
momenta to £(to + h/2) and ii(to + h/2), respectively. Now that the body
is correctly positioned and oriented at the midpoint, we can compute the
net force F(to + h/2) and net torque f'(to + h/2) acting on it. Substitut-
ing this information into equation (B.I8) and expanding the function-style
notation, we have:

hv(to + h/2) ) ( h l(t o,!h/2) )


- hw(to + h/2) R(to + h/2) h H(to+h/2)
k2 = ( - = I(to+h/2) (B.I9)
hF(to + h/2) hF(t + h/2)
h f'(to + h/2) h f'(t: + h/2)

We can then substitute equations (B.I5) and (B.I9) back into equa-
tion (B.I4) to obtain the approximate linear and angular positions and
momenta of the body using the second-order Runge-Kutta method.
B.3 Runge-Kutta Method 283

B.3.2 Forth-Order Runge-Kutta Method


The forth-order Runge-Kutta method combines the information of four
"Euler like" steps to approximate the Taylor-series expansion up to its
fifth term. The approximate solution Y(to + h) is then determined from:

kl hJy(to, Y) , (B.20)
h - kl
k2 h Jy (to + "2' y + 2) , (B.21)

h - k2
k; "2' y + 2) ,
h Jy (to + (B.22)

k~ hJy(to + h, Y + k3) , (B.23)

Y(to + h) Y(to) + kl + k2 + k3 + k4 +O(h5). (B.24)


6 3 3 6
Figure B.3 illustrates how this method extends the second-order Runge-
Kutta method by computing one more time derivative at the mid-point,
and another time derivative at the endpoint of the time interval being
considered. The (1/3) and (1/6) coefficients used in equation (B.24) were
chosen to cancel out the lower order time derivative terms, making the
approximate solution differ by O(h5) from the exact solution.

&
ji(t} kz ji(t} Approximate

Exact
kl
k4
ji(t/ }
_ ~ _ ..... i solution
y(t, +h} " I I
I
ti ti +h ti ti +h

(a) (b)

FIGURE B.3. (a) Four time derivatives are computed: one at the beginning, two
at the middle, and one at the end of the time interval. The label of the points
indicate which k was used to compute it. (b) The combination of all intermediate
values results in a linear approximation that differs only by O(h5) from the exact
solution.

The computation of the time derivatives at each of the three intermedi-


ate values requires positioning, orienting and setting the dynamic state of
the body according to the second arguments of the f functions in equa-
tions (B.20) to (B.24). Only then we can compute the net force and torque
acting on the body at the time interval being considered.
The time-derivative vectors kl and k2 are computed the same way as the
second-order Runge-Kutta method. We can continue applying the same
284 Appendix B. Numerical Solution of ODEs of Motion

techniques we used for computing k2 to obtain the time-derivative vectors


k3 and k4 given in equations (B.22) and (B.23) , respectively. Let's first
consider the computation of k3, namely:

h Jx(to + h/2, x + k2X/ 2) )


k3 = ( h JR(to + h/2, I!: + ~2R/ 2) . (B.25)
h h(to + h/2, L + k2L/ 2)
h JH(to + h/2, ii + k2H /2)
Equation (B.25) says that, at time t = (to + h/2), the body will be
positioned at (x+k2x /2), oriented by (R+k2R/2), with linear and angular
momenta given by (i + k2L/ 2) and (ii + k2H /2), respectively. In other
words, the second arguments of the J functions in equation (B.25) are the
initial conditions at time t = (to + h/2), namely5:

x*(to + h/2)) (X(t O) + (h/2) l(t o;;,h/2) )


Y*(to + h/2) = ( I!:*(to + h/2) = R(to) + (h/2) f(~~o:/:!i} .
~*(to + h/2) i(to) + (h/2) F(to + h/2)
H*(to + h/2) ii(to) + (h/2) T(tO + h/2)

The net force F*(to + h/2) and net torque T*(to + h/2) are computed
after the body is correctly positioned at X*(to + h/2) with orientation
R*(to + h/2), and its linear and angular momenta are set to i*(to + h/2)
and ii*(to + h/2), respectively. Substituting this information into equa-
tion (B.25) and expanding the function-style notation we get:

hV*(to + h/2) ) ( h l*(t(~h/2) )


- hw*(to + h/2)R*(to + h/2) h 11* (to+h/2)
k3 = ( - = I*(to+h/2) , (B.26)
hF*(to+h/2) hF*(t +h/2)
hT*(to + h/2) hT*(t~ + h/2)
where
I*(to + h/2) = R*(to + h/2) Ib (R*(to + h/2))-1 .
The time-derivative vector:

hJx(to+h,x+k3x/2) )
k4 = ( h JR(tO + h, I!: + ~3R/ 2) (B.27)
hh(to + h,L + k3L/2)
h JH(to + h, ii + k3H /2)

5The superscript * is used to differentiate the k3 time-derivative estimate from the


k2 estimate, since both refer to the same time t = (to + h/2).
B.4 Using Adaptive Time-Step Sizes to Speed Computations 285

is computed by first setting the dynamic state of the body to:

x(to + h)) (X(t o) + h L·(t~h/2)


Y(to + h) = ( ~(to + h) =
I:,(to + h)
_R(to) + h_1: t:o:~
L(to) + hF*(to + h/2)
; ,
)

H(to + h) H(to) + hf*(to + h/2)

then determining the net force F(to + h) and net torque r(to + h) acting
on the body at time t = (t + h), and lastly substituting this information
into equation (B.27) to obtain:

hv(to + h) ) ( h L(to+h) )
- ( hw(to +- h) R(to + h) h Ii t::+h
k4 = = I to+h (B.28)
hF(to+h) hF(t +h)
hr(to + h) hr(t: + h)

By combining all k's computed in equations (B.17), (B.19), (B.6) and


(B.28) into equation (B.24), we have the approximate linear and angular
positions and momenta of the body using the forth-order Runge-Kutta
method.

B.4 Using Adaptive Time-Step Sizes to Speed


Computations
As mentioned earlier, the choice of the time step h directly affects the
efficiency and stability of the numerical method being used. If the time step
h is too big, then the approximate solution may significantly differ from
the exact solution, and the numerical integration is meaningless. On the
other hand, if the time step h is too small, then the approximate solution
may follow more closely the exact solution, but at the expense of moving
forward slowly in time, possibly slower than necessary. The best choice of
h depends on the equations being solved, and on their initial conditions.
It is clear that, as the system evolves, the initial conditions for each time
step change, and so the choice of h to be used.
Ideally, we should be able to pick the right time step h depending on
the system being solved at each time step. The right time step would be
one allowing the numerical integrator to move forward in time as fast as it
can, still keeping the error difference between the approximate and exact
solutions less than a desired threshold value. We should be able to increase
or decrease the value of the time step at run-time if the error is smaller or
larger than the maximum-allowed threshold value, respectively.
286 Appendix B. Numerical Solution of ODEs of Motion

We already know from the previous sections that the error between the
approximate and exact solutions for both explicit Euler and Runge-Kutta
methods can always be expressed as being proportional to a power of h,
What we still need to know is how to compute this error and take advantage
of this relation with h to adaptively adjust its value as the simulation
evolves.
One technique commonly used to estimate the truncation error is called
step doubling. As its name implies, the idea is to compute the linear and
angular positions and momenta using the step size h, and then compute
them again using two steps of size (h/2). Even though the final time step
size is h in both cases, the result obtained using the two steps of size (h/2)
is more accurate than that using the single step size h. Their difference can
therefore be used as an estimate of the truncation error, which in turn is
proportional to a power of h.
To illustrate this idea, let Y(to+h) and Y(to+h/2+h/2) be the approxi-
mate values computed through the numerical integration of equation (B.l),
using one time step h and two time steps (h/2), respectively. The difference
between these value is given by

6y == Y(to + h/2 + h/2) - Y(to + h) .


We already know this difference is proportional to a power of h, that is

(B.29)
where the value of p depends on the numerical method being applied. Ta-
ble B.l shows the values of p for the numerical methods presented in this
appendix.

Integration method I Value of p I


Explicit Euler 2
Implicit Euler N/A
Second-Order Runge-Kutta 3
Fourth-Order Runge-Kutta 5

TABLE B.l. The value of p to be used depending on the numerical method


applied.

So far, we have computed the difference 6y(to+h), and have determined


its relation with the time step h being used. Now, we need to ascertain how
to use this information to adjust the time step h so that the error will be
less than a desired threshold value.
Let 6d be the desired (user-definable) threshold value, and let hd be its
associated time step, that is, the time step that should be used to give an
error equal to 6d, we know that
B.5 Suggested Readings 287

16dl ~ h~ . (B.30)
Since equations (B.29) and (B.30) refer to the same ODEs, their constant
of proportionality is the same. Therefore, if we divide one by the other we
can cancel out their constant of proportionality, obtaining

We have the difference 6 y , the time step h being used, and the desired
threshold error value 6d. Solving for the unknown hd, gives

(B.31)

Equation (B.31) shows how we can adjust the time step h using the step-
doubling technique. If the computed error 6 y is greater than the desired
threshold error value 6d, then 16d/6yl < 1 and hd will be less than h,
that is, the current time step h should be decreased to hd. In this case, the
integrator needs to "undo" its computations and start all over again for the
new (reduced) time-step value. On the other hand, if the computed error
6 y is smaller than the desired threshold error value 6d, then 16d/6yl > 1
and hd will be greater than h, that is, the next time step h should be
increased to hd.
In practice, because reducing the value of h is such an expensive operation
(we need to redo all computations for the new value), it is important to
exercise caution when we have room to increase the value of h. Keep in
mind that equation (B.31) gives an estimate of how much we can increase
or decrease the time step h depending on the error difference found. If we
have room to increase, but increase too much, then in the next time step
we may find the error is greater than the threshold error value, and we shall
be forced to reduce the time step, undo the current operation and start the
computations allover again. So, the gain of increasing the time step to move
faster in time immediately turns out to be a considerable loss. Therefore,
it is strongly advisable to increase the time step only by a percentage of
the actual value computed using equation (B.31). For instance, instead of
increasing h to hd, we could increase it to (0.8hd), leaving a 20% safety
margin.

B.5 Suggested Readings


There are several other numerical methods in the literature that are ap-
plicable to our ODEs of motion, but are not so popular as the Euler and
Runge-Kutta methods covered in this appendix. For example, Press et
288 Appendix B. Numerical Solution of ODEs of Motion

al. [PTVF96] present other methods such as the Bulirsch-Stoer and the
fifth-order Runge-Kutta that are as effective as those presented here. In
the case of the fifth-order Runge-Kutta method, the estimation of the trun-
cation error can be done without using step doubling. This comes from
the fact that the fifth-order Runge-Kutta has an embedded fourth-order
Runge-Kutta on it, such that it can use the same time step to evaluate
the results of two Runge-Kutta methods and compare them to estimate
the integration error. Sharp et al. [SV94] present a general formulation for
determining pairs of embedded Runge-Kutta integrators.
A more in-depth explanation of the implicit Euler method, and how the
coefficients relate to the time step being used, can also be found in Press
et al. [PTVF96], as well as in Baraff and Witkin's SIGGRAPH 98 course
notes [BW98b].
Appendix C
Quaternions

C.l Introduction
Quaternions are mathematical structures from algebraic geometry that are
widely used in computer graphics as an alternate way of representing 3D
rotations of objects and their orientation in a scene. Quaternions use a
four-dimensional notation to represent 3 x 3 rotation matrices that is more
efficient to manipulate, and more robust with respect to numerical round-
off errors observed when combining rotation matrices.
The four-dimensional space of quaternions is composed of a real axis,
I,
and three orthogonal axes i, k known as principal imaginaries. We can
think of the principal imaginary axis as an extension of complex numbers,
since they have the same basic complex number characteristic of satisfying

?l
Z =J"12 = k-2 = -1.

Being four-dimensional structures, quaternions can be represented as a


quadruplet of real numbers, namely

q=s+xi+yI+zk=s+v, (C.l)
consisting of a real part s and a pure imaginary part v given by

v= ~ - - -
( X) =xi+yj+zk.
290 Appendix C. Quaternions

C.2 Basic Quaternion Operations


Quaternions can be combined and manipulated in a way similar to complex
numbers, where the real and imaginary parts are dealt with separately.
Given two quaternions q1 = 81 + VI and q2 = 82 + V2, the following basic
rules define the most common set of operations used with quaternions.

C.2.1 Addition
The addition of two quaternions is similar to the addition of two complex
numbers, and is given by

q1 + q2 = (81 + 82) + (VI + V2) ,


where (81 + 82) is the real part of the result (notice that all summands are
scalar) and (vI + V2) is the imaginary part of the result (notice that all
summands are vectors). The result of the addition is a quaternion.

C. 2. 2 Dot product
The dot product of two quaternions is equivalent to the addition of the dot
products of their real (scalar) and imaginary (vector) parts, namely

q1 . q2 = 81 82 + VI . V2 ,
where VI . V2 is the usual dot product of two vectors1 in IR3. Notice that
the result of a dot product is a scalar.

C.2.3 Multiplication
The multiplication of two quaternions can be computed as if we were mul-
tiplying two complex numbers, with the added complexity of having the
imaginary Ea~t bein~ a vector. In this case, the multiplication of the imag-
inary axes i, j and k obeys the following basic rules:

Ii = -k, kI = -i, ik
~

-j
ki = +I, iJ = +k, I k +i (C.2)
iJk -1.
We can alternatively visualize the multiplication of one imaginary axis
by another as a 3D rotation (see Figure C.l(a)). For example, the multipli-
cation on the right by k can be visualized by applying the right-hand rule
for rotating axis i and I in Figure C.l(b).

1 Unless otherwise stated, whenever we mention IRn , we are referring to the n-


dimensional Euclidean space and its associated properties.
,I
C.2 Basic Quaternion Operations 291

tI
I
Jf-l I
J-(0,1,0)
i

l - (1,0,0)
f = (0,0,1)
-~
i k =-j
-j

(a) (b)

FIGURE C.l. (a) The three orthogonal principal imaginary axes viewed as a
canonical basis of a 3D Euclidean space; (b) Multiplication on the right by f
causes a clockwise 90 degree rotation in four-dimensional space around the f
axis, rotating the i axis into the -I axis (from if = -I in (C.2)), and rotating
the I axis into the i axis (from If
= i in (C.2)). This can also be verified by
applying the right-hand rule for rotating vectors represented in the right-hand
coordinate system.

In order to compute an algebraic expression for the multiplication of


two quaternions, we have to expand their imaginary parts and use equa-
tion (C.2) to compute the multiplication ofthe imaginary axes among them-
selves, that is

qlq2 (81 + Vl)(82 + V2)


(81 + Vlx i + Vly J + VIz k)( 82 + V2x i + V2y J + V2z k)
(81 8 2 - Vlx V2x - Vly V2y - VIz V2z) +

81 (V2x i + V2y J + V2z k) + 82 (Vlx i + Vly J + VIz k) +

(Vly V2z - VIz V2y) i + (VIz V2x - Vlx V2z) J +

(Vlx V2y - Vly V2x) k

(8182 - Vl . V2) + (81 V2 + 82 Vl + Vl x V2) .

Notice that the multiplication of quaternions is not commutative. This


should not come as a surprise, since multiplication of quaternions is equiv-
alent to a 3D rotation, which itself does not enjoy the commutative property
with respect to the multiplication operation.

G.2.4 Conjugate
The conjugate operation is exactly the same as its counterpart in complex
number theory. We just need to negate the imaginary part to obtain the
conjugate of a quaternion, that is
292 Appendix C. Quaternions

(It = 81 + vi = 81 - vi . (C.3)
Another basic property of the conjugate operation is that the conjugate
of the multiplication of two quaternions is equivalent to the multiplication
of the conjugate of each quaternion, that is

qi q"2 (81 - Vi)(82 - V2)


(8182 - vi . V2) + (-81 V2 - 82 vi + (-vi) x (-V2))
(8182 - vi· V2) - (81 V2 + 82 vi +V2 x vi)

q1q2·

C.2.5 Module
The module, also known as magnitude, is computed as the dot product
between the quaternion and its conjugate, and is given by

Iq1 12 = q1 . /[1 = /[1· q1 = 8~ + vi· vi = 8~ + v~x + V~y + v~z .


The module of the multiplication of two quaternions is the same as the
multiplication of the modules of each quaternion, since

Iq1 q21 2 = (q1 q2)(q1 q2) = (q1 q2)(q"2 /[t)


q1 (q2 1f2) /[1 = q1 Iq21 2 1[1
Iq21 2 q1 /[1 = Iq1 121 q21 2 •

C.2.6 Inverse
The inverse of a quaternion can be directly derived from the expression
used to compute its module, resulting in

(C.4)

C.3 Unit Quaternions


Another commonly used representation for a quaternion q = 8 + V is to
write it as q = 8 + a ii, where the imaginary part ii is a unitary vector (Le.,
Iiii = 1.) We can compute a and ii from v as follows:
C.4 Rotation-Matrix Representation Using Unit Quaternions 293

A quaternion with zero real part (Le., s = 0) is called a pure quaternion.


Any arbitrary vector if E IR3 can be represented a.<; a pure quaternion:

q=O+if (C.5)
using the notation in (C.l). A quaternion with module equal to one is
called a unit quaternion, also known as unit-magnitude quaternion. A pure
unit quaternion is then a quaternion with zero real part and module equal
to one. Since any arbitrary vector in IR3 can be represented as a pure
quaternion, any unitary vector in IR3 (Le., any normalized vector) can be
represented as a pure unit quaternion.
The family of all unit quaternions (Le., all q such that Iq I = 1) form
an hyper sphere of radius 1 in the four-dimensional space of quaternions.
Because a unit quaternion q always satisfies the condition I q I = 1, from
equation (C.4), we can directly conclude that:

if -
q-1 =iQT2=q, (C.6)

that is, the inverse of a unit quaternion is equal to its conjugate, which in
turn can be computed by negating its imaginary part (see equation (C.3)).

C.4 Rotation-Matrix Representation Using Unit


Quaternions
Unit quaternions play an important role in computer graphics because they
can be used as an equivalent representation of 3 x 3 rotation matrices. In this
section, we shall briefly go over all transformations required to switch back
and forth between unit quaternions and rotation-matrix representations for
right-handed coordinate systems.
The 3 x 3 rotation-matrix representation of a rotation of an angle of ()
degrees about the unit-magnitude axis i1 that passes through the origin is
given by:

t u~ + cos () tux u y + Uz sin () tux Uz - u y sin () )


tux u y - Uz sin () t u~ + cos () t uy U z + U x sin () ,
tUxuz+uysin() tuy Uz - Ux sin() tu~ + cos()
(C.7)
where u x , u y and U z are the components of the unit-magnitude vector i1
and t = (1 - cos ()). This rotation can, in turn, be represented by the unit
quaternion

(C.8)
294 Appendix C. Quaternions

Conversely, given a unit quaternion q = 8 + il, the rotation axis U and


the rotation angle () represented by the quaternion can be computed as

cos () = 2 82 - 1
(C.9)
sin()=28~

and

il
u= ---;:==
J1- 8 2 •
(C.lO)

If we are using the 3 x 3 matrix representation, the rotation axis u and


rotation angle () can be determined from:

Rxx + Ryy + Rzz - 1


cos () = ---.;;.:..---- (C.ll)
2
and

Ryz - R zy
Ux
2 sin ()
Rzx - Rxz
uy (C.12)
2 sin ()
Rxy - Ryx
Uz
2 sin ()
with the constraint that sin () -I O. If this constraint is not met, then the
rotation axis is undetermined.
Lastly, given a unit quaternion q = 8 + il, its equivalent 3 x 3 rota-
tion matrix representation can be directly computed by substituting equa-
tions (C.9) and (C.lO) into equation (C.7). The matrix representation of
the unit quaternion is then:

82 + v; -! Vx Vy - 8 Vz Vx V z + 8 Vy )
R = 2( Vx Vy + 8 V z 82 + V~ - ~ Vy Vz - 8 Vx , (C.13)
Vx V z - 8 Vy Vy V z + 8 Vx 82 + v; - !
where vx , Vy and V z are the components of the imaginary part il, of the unit
quaternion q.
At this point, we can easily switch back and forth between the quater-
nion and the 3 x 3 matrix representation of a rotation of () degrees about
the unit-magnitude axis u using equations (C.7) to (C.13). The only re-
maining question is how to rotate an arbitrary vector p E IR3 using these
representations. If we are using the 3 x 3 matrix representation, then we
can rotate p simply by computing
C.5 Advantages of Using Unit Quaternions 295

p-;' = Rp, (C.14)


where R is the rotation matrix and p-;' is the rotated vector.
If we are using the quaternion representation, the vector p E IR3 can be
represented by the pure quaternion qp = 0 + P (see equation (C.5)), and
the rotation can then be computed as a quaternion multiplication given by

qqpij= (8 + a)(O + p) (8 - a)
o+ ((8 2 - a· a) p + 2 (p. a) a + 28 (a x P)) (C.15)
o+p-;' ,
where qPr is the pure quaternion representing the rotated vector p-;'.

C.5 Advantages of Using Unit Quaternions


There are several advantages of using quaternion representation instead of
the 3 x 3 matrix representation for rotations. Here we will focus on the
most important ones.
The immediate advantage is that quaternions encode rotations by four
real numbers, whereas the representation of these transformations as 3 x 3
matrices requires nine. This may save significant space for complex scenes
with a large number of objects being simulated.
Besides the extra space needed, another problem of requiring more para-
meters to encode rotation matrices is that they are also prone to "drifting"
when multiplied by one another. The drifting is caused by the fact that the
"sin" and "cos" computations for a rotation round an arbitrary axis intro-
duce round-off errors into the nine elements needed to encode the 3 x 3
rotation matrix. When multiplied by another rotation matrix, the result
matrix may no longer be a rotation matrix. The round-off errors can be
such that the determinant of the result matrix differs from one by a small
amount. If the determinant is not equal to one, then the result matrix is no
longer orthogonal, and therefore not a rotation matrix. Subsequent mul-
tiplications by other rotation matrices will rapidly increase the error to a
noticeable level, such that the object being "rotated" will in fact be rotated
and distorted or arbitrarily scaled when rendered in the scene.
A common way of solving the drifting problem for the matrix represen-
tation of rotations is to use the Gram-Schmidt orthogonalization algorithm
for keeping the result matrix orthogonal. The idea is to every so often check
whether the determinant of the result matrix differs from one by an amount
greater than a tolerance level, and if so apply the algorithm to decompose
the result matrix into an orthogonal matrix times an upper triangular ma-
trix. This decomposition is known as the QR decomposition. The result
296 Appendix C. Quaternions

matrix can then be substituted for the orthogonal matrix, and the upper
triangular matrix can be used to estimate the round-off error introduced so
far. The practical problem of using this scheme to correct inevitable round-
off errors when combining rotation matrices is that it is time consuming,
and may not be appropriate for use in simulation engines with stringent
operational requirements.

FIGURE C.2. The hyper sphere of radii 1 in the four-dimensional space of quater-
nions. The intermediate interpolated quaternions qil' ... , qi n lie on the smallest
great hyper arc of the great hyper circle that contains ql and q2 (the quaternions
being interpolated).

With the unit quaternion representation, the drifting problem ansmg


from the "sin" and "cos" computations and the round-off errors introduced
when two unit quaternions are multiplied still exists. In these cases, the re-
sult quaternion may no longer have module equal to one, and therefore no
longer represents a rotation matrix. However, with the quaternion repre-
sentation, the drift problem can be easily fixed by re-normalizing the result
quaternion. If we think of the unit quaternion as being constrained to the
surface of a four-dimensional hyper sphere of radius one, then the drift
can be visualized as the quaternion being moved in or out of the surface
owing to round-off errors. The re-normalization is equivalent to projecting
the quaternion back to another location on the surface close to the correct
location the quaternion was supposed to be if drift had not occured.
Lastly, one of the main reasons most graphics packages use quaternions
is the ability to easily interpolate between unit quaternions representing
an object orientation in two consecutive animation frames. Again, if we
think of the unit quaternion as being constrained to the surface of a four-
dimensional hyper sphere of radius one, the intermediate interpolated unit
quaternions will lie on the smallest great hyper arc that connects the unit
quaternions being interpolated (see Figure C.2).
The same is not true if we are using rotation matrix representation. It is
usually very hard to interpolate rotations between two orientations using
C.6 Suggested Readings 297

the rotation matrix representation, and still get a smooth transition (Le.,
one without jerkiness) between the orientations as the scene is animated.

C.6 Suggested Readings


Quaternions were originally developed as a way of rotating a 3D vector by
multiplying it by another 3D vector. The method of specifying rotations
and orientations of coordinate systems via unit quaternions was formally
introduced to the computer graphics industry by Shoemake [Sh085]. There
you can find a more detailed explanation of why the rotation of a vector
p E IR3 by the unit quaternion q can be computed using equation (C.15),
as well as the derivation of a more sophisticated method to interpolate a
set of quaternions using Bezier curves. For readers interested in quater-
nion visualization techniques, we strongly recommend the work of Hart et
al. [HFK94]' wherein is presented an alternate exponential notation for
representing unit quaternions.
The derivation of equation (C.7), that is, the determination of the 3 x 3
rotation-matrix representation given the angle and axis of rotation, can
be found in Craig [Cra89], Pique [Piq90] and in several other books in the
fields of mechanics, robotics or computer graphics. An in-depth explanation
of general 3D transformations, and how to convert between right-handed
and left-handed coordinate systems, is given in Foley et al. [FvDFH96].
Lastly, the Gram-Schmidt algorithm used for correcting the drifting
problem observed when multiplying several rotation matrices can be found
in Strang [Str91], Golub et al. [GL96] and Horn et al. [HJ91].
Appendix D
Rigid-Body Mass Properties

D.l Introduction
The way rigid bodies interact with each other in a dynamic simulation de-
pends a great deal on their mass distribution. As was shown in Appendix B,
the rigid body's total mass, center of mass and inertia tensor directly affect
the computation of the net force and net torque acting on it, which in turn
are used to solve the differential equations of motion. These quantities,
namely total mass, center of mass and inertia tensor, are commonly known
as the body's mass properties, and depend on the rigid body's shape and
density.
Several algorithms have been proposed so far in the computer graphics
and simulation and modeling literature to compute the mass properties of
a given rigid-body object. They usually fall into one of the two high-level
classes of algorithms. The first class of algorithms is frequently used in
computer solid modeling. Algorithms of this class decompose the original
solid-modeling representation of the object into small cells, and compute
the approximate value of the object's mass properties by summing the mass
properties of each cell. The degree to which the approximate value matches
the exact value depends on the granularity of the cell decomposition. How-
ever, independent of how fine-grained the decomposition is, the mass prop-
erties computed using this class of algorithms are always an approximation
of their exact value because of inevitable mismatches between the object's
volume and the volume occupied by the cells in the decomposition.
300 Appendix D. Rigid-Body Mass Properties

The second class of algorithms assumes the boundary representation of


the object is given, that is, the object's polygonal faces, vertices and their
neighboring information, and compute the object's mass properties directly
from it. Some of these algorithms are specifically designed for the case in
which the object's faces are triangles. In this case, the triangular faces are
connected to the origin of the coordinate system, forming several tetra-
hedra. The mass properties of the object are computed by combining the
mass properties of each tetrahedron. The drawback to using this method
is that some of the tetrahedra can be thin ahd tall, introducing numerical
errors into the computations that can degrade the final result.
In this appendix, we present Mirtich's algorithm for computing the ex-
act values of the mass properties of rigid body objects from their boundary
representation. The objects are assumed to be composed by a set of ho-
mogeneous polyhedra, each with its own constant density value. The mass
properties are computed by incrementally simplifying the initial volume
integrals to surface integrals over the faces of the object, then to surface
integrals over the faces projected to one of the coordinate planes, and fi-
nally to line integrals along the edges of each projected face, which can then
be computed directly from its vertices. Despite its complex derivation, the
algorithm presented here is surprisingly fast, varying linearly with respect
to the total number of faces, edges and vertices of the object.

D.2 Mirtich's Algorithm


The computation of the mass properties involves computing the center
of mass, total mass and inertia tensor of the object, from the center of
mass, total mass and inertia tensor of each of its homogeneous polyhedra.
Assuming the object is represented by np homogeneous polyhedra, its total
mass can be directly determined from
np

M=LPiVi, (D.l)
i=l
where Pi and Vi are the density and volume of polyhedron i, respectively.
The density values are assumed to be given, so that the volume of each
polyhedron can be computed from its shape as

(D.2)

Assuming, for the time being, that we know how to compute the volume
integral in (D.2), we can determine the volume of each polyhedron, and use
this information in (D.l) to compute the total mass of the object. Knowing
the total mass of the object, we can compute the coordinates of its center
of mass C as
D.2 Mirtich's Algorithm 301

In p { In p {

M Lill
i=l v;
xdM= M L Pi ill xdV
i=l Vi
1 np { 1 np {

M Lill ydM= M L Pi ill ydV (D.3)


i=l Vi i=l Vi

In equations (D.3), the homogeneity assumption of the polyhedra is used


to convert the mass integrals into volume integrals, since dM = Pi dV for
each polyhedron i.
Having derived formulas to compute the total mass and center of mass
of the object, the remaining mass property that needs to be determined is
the inertia tensor. The inertia tensor is a 3 x 3 matrix that contains the
moments and products of inertia about the center of mass of the object. In
other words, it express how the mass of the object is distributed relative
to its center of mass.
The computation of the inertia tensor involves determining the nine el-
ements of its 3 x 3 matrix representation, given by

Ixx
1= ( -Iyx
-IXZ)
-Iyz (D.4)
-Izx I zz
where lxx, Iyy and Izz are the moments of inertia about axes x, y and
z, respectively, and I",y, I y"" Ix", I"x, I"y and Iyz are the products of
inertia between the axes. A well known property of inertia tensors found in
the mechanical engineering literature is that the inertia tensor I is a real
symmetric matrix, that is

Ixy = Iyx I zy = I yz ,

so we only need to worry about six out of the nine elements in D.4. Another
useful property of inertia tensors is that it is always possible to find a body-
frame coordinate system in which all products of inertia are zero. In this
case, I is diagonal and we just need to keep track of its three diagonal
elements.
It is also important to notice that, if the mass distribution of the object
doesn't change over time, its inertia tensor relative to its body frame is con-
stant. However, it is constant only in the body-frame coordinate system,
but not in the world-frame coordinate system because, as the simulation
evolves, the object changes position and orientation and its mass distrib-
ution relative to the world frame changes as well. If I is the inertia tensor
302 Appendix D. Rigid-Body Mass Properties

relative to the body frame, and R is the rotation that takes the body frame
to the world frame, then the inertia tensor IW relative to the world frame
is given by

(D.5)
The moments and products of inertia of the object relative to the world
frame can be individually determined from the following set of equations.

t; Pi i.
np

I;:y = (z2 + x 2) dV

t; Pi i.
np

I~ (x 2 + y2) dV

(D.6)

L Pi l
np

xydV
i=l Vi

t; Pi i/
np

ZdV

We can use the parallel axis theorem from mechanical engineering to


compute the inertia tensor relative to a body frame parallel to the world
frame, but with its origin translated to the object's center of mass. The
new moments and products of inertia for this new frame set forth below.

Ixx r:x - M (C~ + C;)


Iyy = I;:y - M (C; + C;)
I zz I~ - M(C; +C~)
(D.7)
Ixy = Iyx r:y -MCxCy
Iyz = I zy = I;:z - MCyCz
Izx = Ixz = I-:x - MCzCx
Equations (D.7) give us a way of computing the constant inertia tensor
relative to a body frame that is parallel to the world frame, but with its
origin at the object's center of mass.
D.2 Mirtich's Algorithm 303

A closer look at equations (D.2), (D.3), (D.6) and (D.7), quickly reveals
that, in order to compute the object's mass properties, we need to be able
to evaluate the following volume integrals defined over each polyhedron of
the object

Tx
h
XdV Tx 2 = hx 2 dV

Ty Ty2 = hy2dV
h YdV
Tz h zdV Tz2 = hz 2 dV (D.S)

Tl
h dV
Txy = hxydV

Tyz
h YZdV
Tzx = hzxdV

The basic idea to solve the volume integrals in (D.S) is to gradually


reduce their complexity from volume integrals to surface integrals, then
from surface integrals to projected surface integrals, then from projected
surface integrals to line integrals, and lastly to evaluate the line integrals
from the object's vertex coordinates. These reductions are achieved using
well known theorems from advanced calculus.

D.2.1 Volume-Integral to Surface-Integral Reduction


The very first step is to reduce the volume integrals in (D.S) to surface
integrals over the faces of the object. The volume-to-surface reduction is
achieved through the use of the divergence theorem. The divergence theo-
rem states that, given a bounded volume V in space and its outward normal
(Le., the normal that points from the inside to the outside of V), then for
any continuous vector field F defined on V, we have

{"V.FdV= { F.ndA, (D.9)


Jv Jav
where av is the boundary of V and "V is the divergence operator given by

(D.lO)

Equation (D.9) explicitly shows the way to convert the volume integrals
to surface integrals. The volume integrals in (D.S) can be reduced to surface
integrals by choosing a continuous force field for each of them. A guess can
certainly be used, but we prefer one that simplifies the surface-integral
304 Appendix D. lligid-Body Mass Properties

computation. For example, let's examine what would be a suitable choice


of force field for the volume integral

Tx = Iv xdV.
We have to find a force field F that satisfies
~ of of of
V'·F=-+-+-=x.
ax ay az
There are many force fields that we can choose from for this given case,
but a suitable guess would be one that makes the right-hand side of equa-
tion (D.9) as straightforward as possible to compute. In this context, we
shall pick a force field that turns the dot product of the right-hand side of
equation (D.9) into a simple scalar multiplication, or

F = (~2, 0, 0) t .

Substituting this into equation (D.9) gives

Tx = 1
v
xdV = 1
8V
F·ndA = L /, (nx2x2) dA,
fE8V f
(D.ll)

where the surface integrals are computed for each face of the object. Be-
cause in our case each polygonal face has constant normal, we can pull the
normal component out of the integral in (D.ll), further simplifying the
expression to

Tx = L n; { x 2 dA .
fE8V Jf
The same procedure can be applied for all volume integrals in (D.8),
and the result is summarized in Table D.l. This table shows the appropri-
ate force-field choice and the equivalent surface integral for each volume
integral in (D.8).
Having computed the surface integral associated with each volume inte-
gral in (D.8), we are ready to proceed to the next step of the integration,
which consists of reducing the surface integrals to line integrals. However,
before we do that, we shall "standardize" this reduction by first projecting
each face of the polyhedron onto one of the coordinate planes.

D.2.2 Surface-Integral to Projected-Surface-Integral Reduction


The surface to projected-surface reduction is achieved by projecting each
face ofthe polyhedron onto one of the coordinate planes xy, yz or zx. The
D.2 Mirtich's Algorithm 305

Index Volume Force Equivalent


i Integral Ti Field F\ Surface Integral
1 JvldV (x, 0, O)t Lnx i! XdA
L n; hx 2 dA
!E8V

x fvxdV (X2
2,0,0 )t
!E8V !
y JvydV (0, Jt..2,0 )t L n; h! y2 dA
L ~z h
!E8V

z Jv zdV
( Z2)t
0,0'2 z 2 dA

L nx hx 3 dA
!E8V !
x2 Jv x 2 dV (X3,0,0 )t
3

!E8V3 !
y2 Jv y 2 dV (0, If.
3,0 )t L ny hy3dA
L n hz 3 dA
!EW 3 !
z2 Jv z2dV 3Y
(0 , 0 , z3 z

L ~x h
!EW 3 !
2
xy JvxydV (£1l
2 ' 0 , O)t x 2ydA
!E8V !
yz JvyzdV
2

2 ' O)t
(0 , 1L..=. L n; hy2ZdA
L ~z hz2 x dA
!E8V !
zx JvzxdV (0,0, Z~X)t
!E8V !

TABLE D.l. Volume- to surface-integral reduction for each volume integral


in (D.8). Even though there are many possible choices of force fields that can
be used, the chosen ones significantly simplify the surface-integral computations.

choice of the coordinate plane to which the face will be projected depends
on the relative orientation of the face with respect to the coordinate plane,
that is, it depends on the values of the components nx,ny
and z of the n
face normal.
The surface integral over the face f can be related to the surface integral
over its projection fp as follows. Let the plane equation of face f E av be
given by

nx if + ny Y+ n z+ d = 0 ,
z

where the scalar constant d can be obtained from


d=-n·p
for any point p E f. Then, the surface integral over the face f can be
computed from the surface integral over the projected face fp as
306 Appendix D. Rigid-Body Mass Properties

( g(a,{3,-y) dA =
.If
_111
n"l
J,
fv
g(a,{3,h(a,{3)) da d{J, (D.l2)

where g(a,{3,-y) is any polynomial function of a, (3 and -y, and h(a,{3) is


given by

1
h(a, (3) = --(nc.t a + n,e (3 + d) . (D.13)
n"l

The use of a, {3 and -y instead of x, y and z in equations (D.12) and (D.13)


emphasizes the fact that the face-projection plane is selected at run-time
depending on the choice that maximizes n"l' that is, the choice that maxi-
mizes the area of the projected face (see figure D.l). Possible combination
values for (a, (3,-y) are (x,y,z), (y,z,x) and (z,x,y).

x
FIGURE D.l. At run-time, the largest component of the face normal is selected
as nl' and the 0, /3 and "I axes are mapped to the x, y and z axes according to this
selection. For the cubic object shown here, the largest component of the normal
n of face f is n z , and therefore "I is associated with z given the combination
(0,/3,"1) = (x,y,z).

Independent of the combination used, the computation of the surface


integrals in Table D.l can always be reduced to the computation of surface
integrals of the form:

i adA, i a 2 dA, i a 3 dA, i a 2 {3dA

i{3dA, i{32 dA , i{33 dA , i {32 -ydA (D.14)

i -ydA, i -y2 dA, i -y3 dA, i -y2 adA.


D.2 Mirtich's Algorithm 307

This convenient representation is possible because the surface integrals


in Table D.l have terms of the form a, a 2, a 3 and a 2 f3, for any of the three
possible combination values of (a, f3, "(). Since the actual combination value
can only be determined at run-time, we shall compute the projected surface
integrals of each face as a function of a, f3 and "(. This we do by substituting
equations (D.12) and (D.13) into each surface integral in (D.14).
The surface integrals for each face of the object as a function of its
projected surface integral are then given by:

h adA
(D.15)

h a 2 dA (D.16)

j a 3 dA (D.17)

j a 2 f3dA (D.18)

jf3 dA (D.19)

h f32 dA (D.20)

h f33dA (D.2l)

jf3 2 "(dA (D.22)

j "(dA (D.23)

j "(2dA

(D.24)
1
--1-1-
n, 11,3 (no P03 + 3no n(3P02(3 + 3no n(3 Po (32 +
3 2 2

n~ P(33 + 3dn~ P02 + 6dno n(3 Po(3 + 3dn~ P(32 +


3 d 2 no Po + 3 d2 11(3 P(3 + d3 PI) , (D.25)
1
-1-1- 2 (no P03 + 2 no 11(3 P02(3 + n(3 Po(32 +
2 2
11, n,

2dno P02 + 2dn(3 Po(3 + d2 Po), (D.26)

where the projected surface integral Pou(3v is computed as


308 Appendix D. Rigid-Body Mass Properties

Pa"i3" = /, aU f3v dA . (D.27)


Ip
Having determined the surface integrals as a function of the projected
surface integrals, we can then proceed to the next step, which consists of
reducing the projected surface integrals to line integrals along each edge of
the projected face.

D.2.3 Projected-Surface-Integral to Line-Integral Reduction


The projected surface integral is reduced to a line integral using the Green's
theorem. The Green's theorem can be envisage as the 2D case of the di-
vergence theorem presented in Section D.2.1. It states that, given a planar
surface /p, a continuous force field if defined over /p, and the outward nor-
mal m along the boundary 8/p of /p, the surface integral is then equivalent
to the line integral

{ t::,.. if dA = 1 if· mds , (D.28)


IIp Jal p
where the circular line integral traverses counterclockwise the boundary of
/p (see Figure D.2). Again, we need to choose a suitable force field if such
that the right-hand side of equation (D.28) is simplified as much as possible
for the following line integral computations.

I~.
fI

ip

(a., fl.)
1-------1
Aa.
a
FIGURE D.2. The projected surface integral is reduced to a line integral over
the edges of the projected face fp. The line integral traverses each edge e E fp in
a counterclockwise direction.

The selection process is identical to that described in Section D.2.1. We


shall pick a force field if that turns the dot product of the right-hand side
of equation (D.28) into a simple scalar multiplication. We shall also break
the line integral into smaller pieces along each edge of the projected face,
D.2 Mirtich's Algorithm 309

since each edge has a constant outward normal that can be extracted from
the integration. Table D.2 shows the selected force fields for each projected
surface integral that appears in equations (D.15) to (D.26).

Index Proj. Surf. Force Equivalent


i Integral Pi Field Il Line Integral

0:
kiO: dA
(022,0)t Si gn2(n)') f6j3e
e=l 0
11 0:2(LeA) dA

ne 11
0: 2 k i0:2dA (,;3,0)t sign;n-Y)L6j3e 0:3(LeA) dA

11
e-1 0

0:3 (~4 ,O)t g


Si n4(n)') f6j3e 0:4(LeA) dA
k i 0: 3dA

11
e=l 0

13 (0, ~2)t - si gn2(n-y) f60: e j32(LeA) dA


ki 13 dA
e=l 0

g ne
- si n3(n-y) L60:e 11 j33(LeA) d/\
132 k,j32 dA (0, ~3)t

11
e=1 0

13 3 k,j33 dA (0, ~4)t - Si gn4(n-y) f60: e j34(LeA) dA


e=1 0
ne 11
0:13 k i O:j3dA (O~,8,O)t sign;n)') L6j3e 0:2(LeA) j3(LeA) dA

11
e=1 0

0: 2 13 k,0:2j3dA (0~i3, O)t Signt)') f6j3e 0:3(LeA) j3(LeA) dA

11
e-1 0

0: 132 g
si n3(n-y) f6j3e o:(LeA) j33(LeA) dA
hi 0: 13 2 dA (0, °t)t
e=1 0

TABLE D.2. The line integrals along each edge of the projected face fp in terms of
the 0: and f3 components selected at run-time. The change of variable ds = Led>",
with Le being the length of edge e, is used to simplify the integral to vary from
o to 1.
At this point, we have successfully reduced the volume integrals to line
integrals over each edge of each projected face of each polyhedron that
composes the object. Now, we need to address the last remaining part of
the algorithm, which is to compute the line integrals given in Table D.2 as
a function of the vertex coordinates of each edge.

D.2.4 Computing the Line Integrals from the Vertex


Coordinates
The line integrals given in Table D.2 are all of the form
310 Appendix D. Rigid-Body Mass Properties

11 aP(LeA) /3q (LeA) dA ,

where Le is the length of the edge e being considered in the integration,


and 0 ::; p ::; 4 and 0 ::; q ::; 4 are the coefficients of a and /3, respectively.
Evaluating the line integrals from the vertex coordinates consists of com-
puting the following expression for each edge being integrated:

{1
J"
o
a"(L,A)!l" (L,A) dA ~ f- E E (~).(
P ~
(' + J)
q

pq i=O j=O P q
)

":+1 ~-; 1i!+1 fJ!-; ,


i+j
where kpq = (p + q + 1) and

( ~) i!(:~i)!'
Table D.3 shows the vertex-based computation for each line integral in
Table D.2. We use the vertex coordinates to compute the line integrals,
and substitute the result into Table D.2 to compute the projected surface
integrals. The surface integrals are computed from the projected surface
integrals using equations D.15 to D.26, and their values are substituted back
into Table D.1 to compute all volume integrals. Finally, the mass properties
are evaluated from the volume integrals using equations (D.2), (D.3), (D.6)
and (D.7).

D.3 Suggested Readings


The algorithm presented in this appendix was developed by Mirtich [Mir96a,
Mir96b]. Despite its complex derivation and endless expressions relating
volume to surface integrals, surface to line integrals, and line to vertex
computations, the implementation is fairly straightforward. All volume in-
tegrals can be computed in a single pass through the polyhedrons' faces,
edges and vertices, resulting in a fast practical algorithm.
A comprehensive survey of the various types of algorithms used to com-
pute the mass properties of objects can be found in Lee et al. [LR82a].
The approximate cell-decomposition methods mentioned in the introduc-
tion can also be found in Lee et al. [LR82a, LR82b]. The other boundary-
representation method specially designed for polyhedra with triangular
faces was developed by Lien et al. [LK84].
Lastly, the derivation and analysis of the inertia tensor formulas, as well
as the parallel-axis theorem, can be found in Beer et al [BJ77a], Alonso et
al. [AF67], and many other mechanical engineering books that deal with
the dynamics of mechanical parts.
D.3 Suggested Readings 311

Line Equivalent
Integral Vertex-Based Computation
2
10 Q!2(Le>') d>'
1
'3
1L i
Q!e+l 2-i
Q!e
i-O
3
10 Q!3(Le>.) d>'
1
4"1 L Q!e+l
i 3-i
Q!e
i-O
4
10 Q!4(L e>.) d>'
1
"51 L Q!e+l
i 4-i
Q!e
i-O
2
10 (32(Le>') d>'
1
!L,8.1
3 e+l ,82-.1
e
.1=0
3
10 (33(Le>') d>'
1
!4 L{3.1e+l ,83-.1
e
.1=0
4
10 (34(Le>') d>'
1
!5 L{3.ie+l ,B4-
e
i
.1=0
2
10 Q!2(Le>') (3(Le>') d>'
1
1 ({3e+l L e
12 Z I) + Q!e+l
i Q!e2-i +
i=O
2
(3e L(3 - Z.) Q!e+l
i Q!e2-i )
i-O
3
10 1Q!3(L e>.) (3(Le>') d>' 1 ({3e+l L e
20 Z I) + Q!e+l
i Q!e3-i +
i=O
3
{3e L (4 - Z.) Q!e+l
i Q!e3-i )
i-O
3
10 Q!(Le>.) (33(Le>') d>'
1
210 (Q!e+1L(j + 1) {3~+1 (3;-i+
.1=0
3
Q!eL(4-j){3~+1{3:-.1 )
.1=0

TABLE D.3. Vertex-based computation of each line integral in Table D.2.


Appendix E
Useful Time Derivatives

E.1 Introduction
In this appendix we shall present a detailed description of how the time
derivatives of a normal vector, a rotation matrix and a quaternion are
computed. These time derivatives are used extensively in Chapters 4 and 5
to describe the dynamic equations of a rigid body.

E.2 Computing the Time Derivative of a Vector


Attached to a Rigid Body
The time derivative of a vector attached to a rigid body is used as a aux-
iliary result to most of the following sections in this appendix. Let points
ih(t) and P2(t) of a rigid body B define a general vector p(t) given by

(E.1)

that is, the general vector p(t) is attached to the rigid body, so that its
linear and angular velocities can be computed as a function of the rigid
body's linear and angular velocities. The time derivative of the general
vector p( t) is then

dp(t) d P1 (t) d iJ2(t)


----- (E.2)
dt dt dt
314 Appendix E. Useful Time Derivatives

Assume that at time instant t the rigid body is moving with a linear
velocity v(t) and an angular velocity Q(t). Since PI and fh are points on
the rigid body, the time derivatives of their positions is directly obtained
as:

d PI (t)
dt
= v(t) + Q(t) x PI
(E.3)
dfh(t)
dt
= v(t) + Q(t) x fh
Substituting equations (E.3) into (E.2), we have

djJ(t)
~ = W-(t) - - W-(t) X P2
X PI - = W-(t) X (- -)
Pi - P2 •

Using equation (E.1) we immediately have that the time derivative of a


general vector attached to a rigid body is computed as:

d~t) = Q(t) x jJ(t)

E.3 Computing the Time Derivative of a


Contact-Normal Vector
Whenever particles or rigid bodies are in contact, the determination of the
contact force necessary to prevent their interpenetration requires the com-
putation of the time derivative of their contact normal. This computation is
done slightly differently depending on whether we have a particle-particle,
particle-rigid body or rigid body-rigid body contact.

E.3.1 Particle-Particle Contact


In the particle-particle case, the contact-normal direction is defined as the
vector connecting the contacting particles 0 1 and O2 , that is

The time derivative of the normal vector direction is obtained as

dii(t) dpl(t) dfh(t)


-----
dt dt dt
VI - V2 (E.4)
E.3 Computing the Time Derivative of a Contact-Normal Vector 315

where fit and fh are the velocities of particles 0 1 and O2 , respectively. The
actual derivative of the normal vector is obtained by normalizing equa-
tion (E.4), that is

dii(t) (ih - V2)


dt IVI - v21 .

E.3.2 Rigid Body-Rigid Body Contact


There are two possible ways the contact-normal direction can be computed
for a rigid body-rigid body contact. If the contact is between a vertex or an
edge ofrigid body Bl with a face of rigid body B 2, then the contact-normal
direction is given by the face-normal direction, that is

ii(t) = it(t) x I)(t) , (E.5)


where it(t) and I)(t) are two edges of the face used to compute the face
normal. However, if the contact is between an edge of Bl with an edge of
B 2 , then the contact-normal direction is given by

(E.6)
where el(t) is the edge of Bl and e2(t) is the edge of B 2.
Let's start by examining the time derivative of equation (E.6), namely

dii(t) _ del(t) .... () .... () de2(t)


dt - dt x e2 t + el t x dt . (E.7)

If we think of edge el(t) as a general vector attached to rigid body B 1 ,


then using the results of Section E.2 we obtain

(E.8)

where Wl(t) is the angular velocity of rigid body B 1 • Conversely, we have

(E.9)

where W2(t) is the angular velocity of rigid body B 2. Substituting equa-


tions (E.8) and (E.9) into equation (E.7) we get

(E. 10)

Using the general cross-product relation

it x (I) x if) = -(b x if) x it


316 Appendix E. Useful Time Derivatives

in the first cross-product term of equation (E.1O), we obtain

Using yet another general cross-product relation

ax (6 x C) = (a . C) b - (a . b) c, (E.12)
we can substitute both cross-product terms of equation (E.ll) by

d ii(t)
(el (t) . e2 (t ) ) W2 (t) - (el (t) . W2 (t )) e2 (t) -
dt
«e2(t)· el(t))wl(t) - (e2(t)· Wl(t)) el(t)) .

Merging similar terms, we have that the time derivative of the contact-
normal direction for edge-edge contact is given by

d~~t) = (el(t).e2(t)) (W2(t)-Wl(t))+(e2(t)·wl(t)) el(t)-(el(t)·wl(t)) e2(t) .


(E.13)
The derivations for vertex-face contact, represented by equation (E.5),
are almost the same as the derivations for edge-edge contact, represented
by equation (E.5), that is

d~~t) = (a(t) . b(t)) (Wb(t) - wa(t)) + (b(t) . wa(t)) a(t) -


(a(t) . wa(t)) b(t) .
(E.14)
The only difference is that, since the normal in the vertex-face contact
is computed as the cross-product of two edges belonging to the same face
(Le., the same rigid body), their angular velocities are the same. In other
words

(E.15)
where w(t) is the angular velocity of the rigid body the face belongs to.
Substituting equation (E.15) into equation (E.14) we get

dii(t)
(a(t) . b(t)) (w(t) - w(t)) + (b(t) . w(t)) a(t) - (a(t) . w(t)) b(t))
dt
(b(t) . w(t)) a(t) - (a(t) . w(t)) b(t) . (E.16)

Using the general cross-product relation described in equation (E.12) we


obtain
E.4 Computing the Time Derivative of the Tangent Plane 317

dii(t) ~
---;It = w(t) (ii(t) x b(t)) = w(t) x ii(t) . (E.17)
which is compatible with the expression obtained for the time derivative of
a general vector attached to a rigid body.
The actual time derivative of the contact normal for both situations
is then obtained by normalizing equations (E.13) and (E.17), that is, by
computing

E.4 COlllputing the Time Derivative of the


Tangent Plane
Following the convention described in Section A.6 of Appendix A, the tan-
gent plane direction f( t) is directly obtained from the normal vector di-
rection ii( t) = (nx (t), ny (t), nz(t)) by setting to zero its component with
the smallest absolute value, swapping the remaining two components and
multiplying one of them by -1. We use an auxiliary vector ii as follows.

1. If Inxl < Inyl and Inxl < Inzl, then set the auxiliary vector ii to

(E.18)

2. If Inyl < Inxl and Inyl < Inzl, then set the auxiliary vector ii to

(E.19)

3. If Inzl < Inxl and Inzl < Inzl, then set the auxiliary vector ii to:
ii= (-ny,nx,O). (E.20)

The tangent vector f is then set to

The time derivative of the tangent vector f is computed as a function of


the time derivative of the auxiliar vector, namely

d f (d ii)
dt = dt / Idt
d ii I
'
where:
318 Appendix E. Useful Time Derivatives

1. If ii = (0, -n z , ny), then

dii =
dt
(0' _dnz(t)
dt'dt
dny(t))

2. If ii = (-n z , 0, n x ), then

dii = (_ dnz(t) 0 dnx(t))


dt dt" dt

3. If ii = (-ny, n x , 0), then

dii = (_ dny(t) dnx(t) 0)


dt dt'dt'

The tangent-plane direction k(t) is computed as the cross-product of fi(t)


and itt), that is

Therefore, its time derivative can be obtained as


dk dfi _ _ dt
-=-xt+nx-
dt dt dt
after the result is normalized.

E.5 Computing the Time Derivative of a Rotation


Matrix
A rotation matrix R(t) can be viewed as a transformation between a coor-
dinate frame 1 :Fl and the canonical coordinate frame :Fo, with the origin of
:Fl being coincident with the origin of :Fo. Let:F1 be defined by the coordi-
nate vectors Xli fh and ZlI and let the canonical vectors be Xo = (1,0, O)t,
Yo = (0,1, O)t and zo = (0,0, l)t. Then, a point PI in the coordinate frame
:Fl is transformed to a point Po in the canonical frame :Fo by applying the
rotation matrix

Po = R(t) PI .

Viewed as a "change of basis" transformation, it is natural to describe


the rotation matrix R(t) using its column-vector representation:

1In the rigid-body case, the coordinate frame:F1 is the body frame.
E.5 Computing the Time Derivative of a Rotation Matrix 319

R(t) ~( iW) C;(t) c'a(t) ) , (E.2!)

where the column vectors Cl, C2 and C3 represent the coordinate axes Xl,
ill and Zl expressed in canonical-frame coordinates.
The time derivative of the rotation matrix is then computed as

~;t) ~ ( di!t(t)( dt dC;(t)( dt di!a(t)( dt ) . (E.22)

Let iJ(t) be the angular velocity of frame Fl expressed in canonical-frame


coordinates. Using the results obtained in Section E.2, we have that the
time derivative of each column vector can be obtained as

dCl(t)
dt
dC2(t)
(E.23)
dt
dC3(t)
iJ(t) x C3(t) .
dt
Substituting equations (E.23) into (E.22), we have

d~t(t) ~ ( w(t) x ,,(t) w(t) x C;(t) w(t) x C;(t) )

Using the matrix-vector representation of a cross-product as described


in Section A.7, we get

d~t(t) ~ ( w(t)" (t) w(t) C;(t) w(t) ;;,(t) ) , (E.24)

where iJ = (wx,wy,w z ) and

w(t) = ( ~z
-Wy

Equation (E.24) can then be written as

d~;t) ~ w(t) ( cW) C;(t) C;(t)) .


320 Appendix E. Useful Time Derivatives

Thus, the time derivative of a rotation matrix R( t) is given by

dR(t) = wet) R(t) . (E.25)


dt

E.6 Computing the Time Derivative of a Unit


Quaternion
The time derivative of a unit quaternion q = 8 + V will be computed using
the results already obtained for the time derivative of a rotation matrix.
Recall from Appendix C that the rotation-matrix representation of a unit
quaternion is given by

+ v; - ~ + 8 Vy
+ v; -!
82 Vx Vy - 8 Vz Vx V z )
R = 2 ( Vx Vy + 8 Vz 82 Vy V z - 8 Vx , (E.26)
221
V x V z -8Vy V y V z +8Vx 8 +Vz - 2
where V x , Vy and V z are the components of the imaginary part v of the unit
quaternion q. The time derivative of this rotation matrix is then 2

dR Vx Vy + Vx Vy - S V z - 8 V z
2 (8S + VyVy )
dt
Vy V z + Vy V z + S Vx + 8 Vx

(E.27)

As mentioned in Section E.5, the rotation matrix R(t) can be viewed


as a transformation between the body frame and the canonical frame. Let
w( t) be the angular velocity of the body frame expressed in canonical-frame
coordinates. Using equation (E.25), we have that the time deriyative of the
rotation matrix is computed as

dR(t) = wet) R(t) , (E.28)


dt

wet) = (
~z (E.29)
-wy
Right multiplying both sides of equation (E.28) by R-l(t) = Rt(t) gives

2To simplify the notation, we shall use a to represent the time derivative ~~.
E.6 Computing the Time Derivative of a Unit Quaternion 321

-( ) _ dR(t) Rt( ) (E.30)


w t - dt t.
Substituting equations (E.26), (E.27) and (E.29) into equation (E.30) ,
we obtain a linear system that can be solved for w x , wyand W z as follows.
Inspecting equation (E.29), we have that Wx is obtained by multiplying
the third row of dR(t)/ dt by the second column of Rt(t), that is

4
(V x V z + V z Vx - Vy 8- S v y )( Vx Vy + V z 8) +
. • . . 2 2 1
(VyVz+vzVy+Vx8+8Vx)(8 +VY - 2)+
2(S8 +vzvz)(vyv z -Vx 8).

Grouping the terms with common derivatives we get

· ( Vx Vy Vz
Vx + 8 (2 1)) +
V z + 8 2 + Vy2 - 2
4

Vy (v z (v; - ~) - Vx Vy v z) +
V· z ( Vy (2
Vx + Vy2 + V z2 + 8 2 - 21) + Vy V z2 - Vx Vz 8 ) +
S(8VyVZ-Vx(82+~)). (E.31)

Since q = 8 + V is a unit quaternion, it must satisfy

+ v Y2 + v z2 + 8 2
V x2 1 (E.32)
Vx Vx + Vy Vy + Vz Vz + S 8 O. (E.33)

Using equation (E.32) into (E.31) we have

l-v;
· (v x V y V z +8 V z +8 +vY -
Vx (~ 21)) +
4
Vy (v z (v; -~) - vxvyvz ) +
1

· (
V z Vy Vx
(' 2
+ Vy2'"+ V z2 + 8 2' -21 ) + Vy V z2 - Vx V z 8
)
+
S (8 Vy Vz - Vx (8 2 + ~))

Vx (Vx Vy Vz + 8 (~ - v;)) +
322 Appendix E. Useful Time Derivatives

'Vy (vz (v; -~) - vxvyvz ) +

Vz (vy (~ + v;) + vy v; - Vx V z s) +
s(svyv z -Vx (S2 + ~)).
Regrouping the terms and using equation (E.33) we have

-V y Vy -Vz Vz -Vx V;r -8 S


~ ~
( Vx Vx + s s ) Vy Vz - (Vy Vy + Vz v z ) Vx s +
4
· s (1"2
Vx - Vx2) . Vz (2
+ Vy Vy -"21) +

V· z Vy ( "21 + Vz2) -
. ( "21
sVx + s 2)
s. vz . vy . vx .
-v x - - vY +-vz - - s
2 2 2 2'
that is

Wx = 2 s Vx - 2 Vz Vy + 2 Vy Vz - 2 Vx s. (E.34)
Inspecting equation (E.29) one more time, we have that Wy is obtained
by multiplying the first row of dR(t)/ dt by the third column ofRt(t), that
is

W; 2(s S + Vx v x ) (v z Vx - Vy s) +
(v y Vx + Vx Vy - Vz s - sV z ) (v z Vy + Vx s) +

( Vz Vx + Vx

Vz + Vy
.
s + sVy s + Vz2 -"21) .
.)( 2

Doing groupings and substitutions similar to those we employed when


computing wx , we obtain

Wy = 2 Vz Vx + 2 s Vy - 2 Vx Vz - 2 Vy s. (E.35)
Finally, inspecting equation (E.29) one last time, we have that W z is
obtained by multiplying the second row of dR(t)/ dt by the first column
of Rt(t), that is

· . . . 2 2 1
(vxVy+VyVx+vzs+svz)(s +vx -"2)+
4
2(ss + VyVy)(v x Vy - sV z ) +
(v z Vy + Vy Vz - Vx s - S vx)(v x Vz + Vy s) .
E.7 Suggested Readings 323

Again, doing groupings and substitutions similar to those we employed


when computing wx , we obtain

(E.36)
Equations (E.34), (E.35) and (E.36) form a linear system:

(E.37)
Vz

where equation (E.33) was used in the last row to make the matrix square.
Because the determinant of this matrix is -1, the matrix is always invert-
ible. Inverting the system in equation (E.37), we obtain

(E.38)

which gives the time derivative of the unit quaternion as a function of the
angular-velocity components.

E.7 Suggested Readings


Most of the derivations in this appendix were either directly obtained, or
inspired, from Baraff et al [BW98a] and Mirtich's [Mir96b] work. The main
difference in the derivations presented here from their work is in the com-
putation of the time derivative of a unit quaternion. Mirtich assumed the
angular velocity of a rigid body is expressed in the body-frame coordinates,
instead of being given in the canonical-frame coordinates as used in this
book. For that reason, the results obtained in Section E.6 are different from
Mirtich's final equations.
Baraff et al., on the other hand, presented a totally different approach
to compute the time derivative of a unit quaternion. They represented the
angular velocity Q(t) as a rotation about the (Q(t)j IQ(t)l) axis with mag-
nitude IQ(t)l. A unit quaternion q(t) can then be built from this rotation
axis and rotation angle as

() _ (IQ(t)lt) " (IQ(t)lt) Q(t)


qt-cos 2 +sm 2 IQ(t)l"

The time derivative of the quaternion is then, after some manipulation,


given by
324 Appendix E. Useful Time Derivdtives

dq(t) 1
----;It = 2 qw(t) q(t) ,
where qw(t) = 0 + w(t) is the pure quaternion representing the angular
velocity.
Lastly, the general cross-product relations were obtained from Gard-
shteyn et al. [GR80j.
Appendix F
Convex Decomposition of 3D
Polyhedra

F.1 Introduction
Most algorithms presented in this book are specially tailored for convex
objects. The assumption that the objects being manipulated are convex
guarantees faster solutions and much more efficient implementations that
take full advantage of the nice properties of convex polyhedra. Nevertheless,
most interesting dynamic-simulation scenarios contain at least one non-
convex object, making it necessary to pre-process non-convex objects into
a set of convex polyhedra before applying most of the algorithms described
in this book.
The general convex decomposition problem of partitioning a non-convex
3D polyhedron into a minimum number of convex parts is a rather com-
plex one, known to be NP-hard. There is a significant amount of work
in the computational-geometry literature establishing worst-case bounds
on the time complexity of convex decomposition algorithms, as well as
lower bounds on the total number of convex polyhedra found in the de-
composition. However, in the context of dynamic simulations, we are more
concerned with the quality of the convex decomposition than the actual
number of convex parts it comprises. We want a convex decomposition of
"good" quality, tolerant to numerical round-off errors that may be intro-
duced during the computations. We want a convex partition that is suit-
able for computing hierarchical decompositions of the object (such as those
presented in Chapter 2), for checking geometrical intersections between ob-
326 Appendix F. Convex Decomposition of 3D Polyhedra

jects to detect the existence of collisions, and for accurately computing the
normal vector at the collision point between two objects.
In this appendix, we shall present a simplified version of Joe's algorithm,
a convex-decomposition algorithm developed in the context of mesh gen-
eration for finite element analysis of complex 3D shapes. The algorithm
decomposes non-convex 3D polyhedra into a "good" quality set of con-
vex parts. By "good" quality we mean that the algorithm avoids long and
skinny convex parts, as well as unnecessarily short edges and narrow sub-
regions in the convex decomposition. In the case of finite-element analysis,
this means that the tetrahedral mesh created from the convex decomposi-
tion contains tetrahedra of about the same size and shape. In the context
of dynamic simulation, this means that the convex decomposition can be
effectively used to produce high-quality hierarchical decompositions of the
non-convex object.
There are a few restrictions, though, to the type of 3D polyhedra the
algorithm can handle. The original algorithm is restricted to decomposing
simple non-convex polyhedra, that is, polyhedra that satisfy the following
five conditions.

1. The polyhedron has no interior holes.

2. The faces of the polyhedron may have holes. These holes can either
stop somewhere inside the polyhedron, or go through the polyhedron
from one face to another.

3. The polyhedron is not self-intersecting.

4. Each edge is incident on exactly two faces.

5. The faces surrounding each vertex form a simple circuit.

The last condition states that, for each vertex of the non-convex polyhe-
dron, if we construct a double linked-list of neighbor faces in which a face
is linked to another if they share a common edge that has the given vertex
as one of its extreme points, then all faces are reachable from any other
face in the list. This condition is necessary to avoid special cases wherein
the polyhedron can be separated into two parts that share only a single
vertex (see Figure F.1).
The simplified version presented in this appendix restricts even further
the simple-polyhedron assumption stated in the original algorithm. Besides
being simple, the polyhedra being decomposed must also satisfy the follow-
ing two conditions.

6. The faces of the polyhedron have no holes.

7. The faces are convex polygons.


F.2 Joe's Algorithm 327

FIGURE F.1. An example of a special case that is not handled by the algorithm:
a polyhedron made of two tetrahedra connected by a single vertex Vo.

Even though condition 6 limits the polyhedron faces to be simple poly-


gons themselves, this does not prevent the non-convex polyhedron from
having exterior holes. Figure F.2 shows the difference between a face hav-
ing a hole, and the polyhedron itself having an exterior hole. Exterior holes
are allowed, provided that they don't go through the interior of any face.

(a) (b)

FIGURE F.2. (a) The face has an interior hole that stops somewhere inside the
polyhedron; (b) The faces have no interior holes. Nonetheless, the polyhedron
itself has an exterior hole with the same depth as (a).

These extra assumptions have no effect on the main body of Joe's algo-
rithm itself. However, they will be useful to restrict the types of non-convex
polyhedra that can be handled, simplify the occurrence of special cases, and
reduce the complexity of a software implementation. An example of special
cases that are avoided in the simplified version is the creation of double-
occuring faces after the non-convex polyhedron is split by a cut plane (see
Figure F.3).

F.2 Joe's Algorithm


The algorithm that computes the convex decomposition of a 3D polyhedron
that satisfies conditions 1 to 7 above is simple to state, but much more
complicated to implement. The basic idea is to go through the list of edges
of the polyhedron and compute the dihedral angle associated with each
edge (see Section 2.2.4 of Chapter 2). The dihedral angle is the internal
328 Appendix F. Convex Decomposition of 3D Polyhedra

I
J-
/
/
/
/

FIGURE F.3. Double-occuring faces may appear in the original Joe's algorithm,
where faces are allowed to have internal holes. In this case, the cut face Ie
sub-divides the original non-convex polyhedron in a simply connected polyhe-
dron with face Ie occuring twice.

angle formed by the faces that share the edge. If the dihedral angle is less
than or equal to 7f, then the polyhedron is convex at the edge. Otherwise,
the polyhedron is non-convex at the edge, and the edge is said to be a reflex
edge. It is clear that the polyhedron will be non-convex if and only if it has
at least one reflex edge.
Having determined all reflex edges of the non-convex polyhedron, the
algorithm proceeds by recursively resolving each reflex edge. The process
of resolving reflex edges consists of splitting their dihedral angle into sub-
angles less than or equal to IT. The way the dihedral angle is split depends
on the conditions that need to be met to obtain a "good" quality convex
partition. In our case, we want to avoid small dihedral angles, short edges
and narrow subregions when resolving a reflex edge. In other words, the
selection of a cut plane that split the dihedral angle of a reflex edge is a
process of accepting (or rejecting) cut-plane candidates that are computed
from a set of conditions that need to be satisfied to obtain our "good"
quality convex partition.
Once a cut plane that satisfies the conditions is obtained, a cut face asso-
ciated with the cut plane is traced. The cut face is computed by intersecting
the cut plane with the faces of the polyhedron, such that the interior of
the cut face lies in the interior of the polyhedron. This procedure will usu-
ally split the polyhedron into two polyhedra, and the convex-decomposition
algorithm is recursively applied for each of the two polyhedra l until the al-
gorithm terminates either with a valid convex decomposition, or with one
or more reflex edges that could not be resolved for the given conditions.

IThis is true provided the cut face turns out to be a simple polygon. However, there
are cases where the cut face can be either a multiply connected polygon with the reflex
edge lying on the outer boundary or the inner boundary of a hole, or a simply connected,
but non-simple, polygon.
F.2 Joe's Algorithm 329

F.2.1 Determining Candidate Cut Planes


Candidate cut planes are determined for each reflex edge being resolved,
according to the set of conditions that we want to meet.

8. Sufficiently large dihedral angles.

9. Not too narrow subregions.

10. Edges with reasonable length.

In order to quantify conditions 8 to 10, we use the following variables.

11. The minimum acceptable internal dihedral angle, denoted by Oacc.

12. The minimum acceptable relative distance between the cut plane and
other vertices of the polyhedron not on the plane, denoted by d acc .
Notice that the actual distance depends on the size of the polyhedron
being decomposed and is computed as d i = d acc ei, where ei is the
average length of the edges of polyhedron Pi.

The minimum acceptable dihedral angle variable in 11 is used to address


condition 8 in avoiding long and skinny convex parts, whereas the minimum
acceptable relative distance variable in 12 is used to address conditions 9
and 10 in avoiding both short edges and narrow convex regions.
Another important variable to be considered is the total number of can-
didate cut planes nc considered for each reflex edge. This variable is used
to limit the amount of execution time spent trying to resolve each reflex
edge, and restrict the set of candidate cut planes to those that are most
likely to be accepted. Therefore, for each reflex edge, up to nc candidate
cut planes are computed and tested against the desired conditions 8 to 10.
The actual list of candidate cut planes is constructed for each reflex edge
as follows. Let er be a reflex edge of the non-convex polyhedron Pi. Let
faces It and 12 be incident on edge e r , and let Oe > 7r be its associated
dihedral angle.
Naturally, the first two choices of candidate cut planes are those forming
a dihedral angle of 0 = Oe - 7r with faces It and 12, respectively (see
Figure F.4). These choices are added to the list of candidate cut planes
only if their dihedral angle 0 satisfies the minimum acceptable dihedral
angle condition 11, that is, only if

o ~ Oacc . (F.1)
The next choices of candidate cut planes are those that contain the reflex
edge er and another polyhedron edge sharing a vertex with er . Again,
these choices will be added to the list of candidate cut planes only if their
corresponding dihedral angles satisfy equation (F.l).
330 Appendix F. Convex Decomposition of 3D Polyhedra

\
\
\
\
\
\
.......... \
.......... \
.... ........ ....~ .....
.....
.....

FIGURE F.4. First two choices of candidate cut planes that form an angle of
8e - 11' with each of the faces II and fa incident on the reflex edge er • The
angles 81 and 82 must be tested against the minimum dihedral angle condition
of equation (F.l) before they can be added to the list of candidate cut planes.

If the list of candidate cut planes obtained so far has not yet achieved
the limit of nc cut planes, then we continue choosing candidate cut planes
that bisect the internal dihedral angle ()e forming angles () with face ft,
that satisfy equation (F.1) and are of the form

()=P()e,

with p E {0.25, 0.5, 0.75,0.375, 0.625}. The actual number of candidate cut
planes added in this last step depends on the value of ()e, and on the number
of candidate cut planes selected.
Having determined the list of candidate cut planes for the reflex edge
er , we are ready to compute a cut face associated with each candidate cut
plane. As each edge of the cut face is being traced, conditions 8 to 10 are
constantly checked to verify whether the candidate cut plane should be
rejected.
A candidate cut plane is rejected if one of the following occurs.
13. The minimum dihedral-angle condition is not satisfied. In this case,
we have found an edge of the cut face that forms an internal dihedral
angle () that does not satisfy equation (F.1).
14. The minimum acceptable relative-distance condition is not satisfied.
In this case, there exists at least one vertex of the polyhedron that
does not lie on the cut plane and is distant from the plane by an
amount less than or equal to the minimum acceptable distance d =
dace e, where e is the average length of the edges of the polyhedron.

15. The cut face is not a simple polygon, that is, it contains one or more
holes.
F.2 Joe's Algorithm 331

If none of the candidate cut planes in the list satisfies the above cri-
teria, then the reflex edge Cr cannot be resolved at this time, and the
algorithm proceeds to another reflex edge, leaving the unresolved one to
be addressed again later. The rationale behind this strategy is that, after
resolving other reflex edges, the sub-polyhedron containing the reflex edge
Cr may be smaller and easier to decompose, or the reflex edge er may have
been subdivided by other cut faces into two or more reflex sub-edges of less
complexity.

F.2.2 Computing the Cut Face Associated with a Cut Plane


The most complicated part of the algorithm is undoubtedly computing the
edges of the cut face associated with a candidate cut plane. The idea is to
intersect the cut plane with the faces of the polyhedron being decomposed
and construct the cut face from the intersection edges, such that the cut
face lies in the interior of the polyhedron.
Starting with the reflex edge en we trace the cut face, one edge at a
time, moving along the direction corresponding to the normal vector of the
cut plane, such that the interior of the polyhedron being cut is to the left
of the boundary of the cut face. In most cases, this direction is counter-
clockwise, but it can be clockwise as well, and we should keep track of the
relative direction of the faces in each sub-polyhedra as they are cut by the
cut planes.
One advantage of tracing the cut face one edge at a time is that the
internal dihedral angle of each new edge can be immediately computed
and tested using equation (F.l). The candidate cut plane is rejected if the
internal dihedral angle of the new edge is less than the minimum acceptable
value. Also, as new edges of the cut face are traced, if a duplicate vertex
other than the first vertex is found, then the cut face is at least simply
connected, and the candidate cut plane is rejected as well.
The cut face associated with a candidate cut plane is determined as
follows. Let P be the non-convex polyhedron to which we are applying the
convex decomposition algorithm. Let Ie be the cut face associated with
the cut plane Q passing through er , and let vo, Vb ... , Vi be the cut-face
vertices traced so far. Assume that the last-computed edge (Vi-l,Vi) of the
cut face Ie lies on face Ik E P. The next vertex Vi+l of the cut face is
computed according to one of the following two possible situations.
In the first situation considered, the last-computed vertex Vi lies in the
interior of an edge Ck E P (see Figure F.5).
In this case, the direction dnext of the next edge (Vi, Vi+ d of the cut face
Ie is unique, and can be determined from the cross-product of the normal
vector na of the cut plane Q, and the normal vector nf of the polyhedron
face Ii (the other face incident on er ). Since the next vertex Vi+ 1 of the cut
face Ie lies on an edge of the polyhedron face Ii, and we know the direction
332 Appendix F. Convex Decomposition of 3D Polyhedra

V·1-1
I I
I I
I I
_.J....... I
--.... I
I ---- .... ............ I
L-- ........ J
a
FIGURE F.5. Case when the last-computed vertex Vi lies in the interior of a
polyhedron edge ek. Here, there is only one way to compute the direction of the
next edge (Vi,Vi+!) of the cut face Ie.

dnext of the edge (Vi, Vi+l), the next vertex Vi+l can be found as the first
intersection of the ray (Vi + t dnext), for t > 0, with the edges of Ii that are
also intersected by the cut plane2 •
In the second possible situation, the last-computed vertex Vi is a vertex
of an edge ek E P (see Figure F.6).
Hence, the direction dnext of the next edge (Vi,Vi+t) of the cut face Ie
may not be unique. In fact, if the polyhedron being decomposed has faces
coplanar to the cut plane a that contain the last edge (Vi-I, Vi) of the
cut face Ie, then any edge of these faces can be the next edge. Therefore,
the next vertex Vi+l may either lie in the interior of an edge of Ii (see
Figure F.6), or be a vertex of the polyhedron P (see Figure F.7).
The way to resolve this ambiguity is to remember that, by construction,
we are always keeping the interior of the polyhedron P to the left of the cut
face Ie, that is, to the left of the directed sub-chain (Vi-I, Vi, Vi+l) defining
the two consecutive edges (Vi-I. Vi) and (Vi, Vi+t) of Ie. Because of this,
the direction we should pick to determine the next vertex Vi+! from the set
of candidate directions must be the one that minimizes the interior angle
at vertex Vi. If the direction that minimizes the interior angle at vertex Vi
coincides with the direction of an edge of Ii, then the next vertex Vi+l is
the other vertex of the edge. Otherwise, the next vertex Vi+l lies in the
interior of an edge of Ii and can be computed as before.

2In our simplified version of the algorithm, the faces of the polyhedron are assumed
to be convex, and therefore there is only one edge of the convex face /j that intersects
the cut plane Q.
F.2 Joe's Algorithm 333

FIGURE F .6. If the polyhedron being decomposed has no coplanar faces with the
cut plane 0 that contain the last edge (Vi-I, Vi)' then the direction that minimizes
the internal angle at Vi is unique. In this case, the procedure used to compute
the next vertex ViH is identical to that illustrated in Figure F.5.

FIGURE F.7. The polyhedron face 1m is coplanar with the cut plane o. In this
case, there are two possible directions to compute the next edge (Vi,vHI), one
coincident with edge em of 1m, namely (Vi, (ViHh), and another along the interior
offace /;, namely (Vi, (vi+Ih). The internal angle at Vi for each of the choices is
3; and ~, respectively. The selected direction should minimize the internal angle
at Vi, making (ViHh our choice for the next vertex Vi+I.
334 Appendix F. Convex Decomposition of 3D Polyhedra

After determining all edges of the cut face fe, we still need to carry out
two more tests before accepting fe as a valid cut face that meets all desired
conditions 8 to 10.
The first test consists of checking whether the cut face is oriented counter-
clockwise with respect to the normal vector of the cut plane. The orien-
tation can be determined by summing the exterior angles at each vertex
of the cut face. By construction, the correct orientation of the cut face
should be counter-clockwise with respect to the normal vector of the cut
plane, since the interior of the polyhedron P is always kept to the left
of the edges of the cut face, as they are discovered. However, if the cut
face is multiply connected, then the orientation will be clockwise instead of
counter-clockwise. In this case, the cut plane associated with this cut face
is rejected.
The second test consists of checking whether the cut face has interior
holes. This is done as follows. Initially, we consider the set of edges of the
polyhedron P that intersect the cut plane 0:. From this set, we remove any
edge that contains a vertex of the cut face, either in its interior or as a
vertex of the edge itself. Finally, for each edge left in the set, we compute
its intersection with the cut plane 0:. If the intersection point lies inside the
cut face, then the cut face has holes and its associated cut plane is rejected.

F. 2. 3 Termination Conditions
It is clear that there may be cases where one or more reflex edges cannot
be successfully resolved for the given minimum internal-dihedral-angle and
relative-distance values. A workaround for these cases is to reduce the min-
imum acceptable values and execute the algorithm one more time, not on
the original non-convex polyhedron, but on the convex decomposition of
the polyhedron found so far.
Even though this strategy considerably improves the chances of resolving
all reflex edges, there may be still cases wherein some reflex edges may not
be resolved. For these cases, a more sophisticated algorithm must be used,
such as one that extends the original Joe's algorithm to allow the creation
of simply connected or multiply connected cut faces.

F.3 Suggested Readings


The algorithm presented in this appendix is part of a tetrahedral mesh-
generation algorithm for convex and non-convex polyhedra developed by
Joe [Joe94, Joe91]. The original algorithm is itself a modification of Chazel-
Ie's algorithm [Cha84], which resolves each reflex edge by a cut face without
taking into account the quality of the convex partition produced. Bajaj et
F.3 Suggested Readings 335

at. [BD92] developed an extension to Chazelle's algorithm capable of han-


dling internal holes on the non-convex polyhedra.
As far as triangulating the faces of the resulting convex decomposition,
several algorithms can be used depending on the faces being convex or
non-convex polygons. If the faces are convex, then we suggest computing
the Delaunay triangulation of each face using the algorithm presented in
Joe [Joe86]. Otherwise, we suggest using more sophisticated triangulation
algorithms for convex and non-convex polygons, such as those described in
Joe [J886] and Keil [Kei96].
Appendix G
The Linear-Complementarity Problem

G.1 Introduction
As explained in Chapters 3 and 4, there exists a linear relation between
the relative acceleration iii between two contacting bodies and the contact
force Fi at contact point Gi , expressed by

iii = C·;)n)
(ai)t
(ai)k (
(aii)n
(aCHl)i)n
(aiCHl»)t
(aCi+l)(Hl»)t
(aiCH2»)k
(aCi+l)(H2»)k
)
CF;ln) + e'ln) =
(aCH2)i)n (aCH2)(Hl»)t (aCH2)(H2»)k

(Fi)t (bi)t Ai Fi + hi , (G.1)


(Fi)k (bi)k

where the index n indicates the component along the contact-normal direc-
tion, and the indexes t and k indicate the components along the contact-
tangent plane (Le., the plane passing through the contact point with normal
vector parallel to the contact normal). The coefficients of matrix Ai and
vector hi are computed from the mass properties and relative geometrical
displacement of the contacting objects at contact Gi . For example, coef-
ficient (aii)n relates the normal contact-force component (Fi)n with the
normal relative-acceleration component (ai)n at contact Gi . Analogously,
coefficients (aiCHl»)t and (aiCH2»)k relate the force components (Fi)t and
338 Appendix C. The Linear-Complementarity Problem

(Fih with the acceleration l components (ai)t and (ai)t along the tangent
plane. As for vector bi , it can be shown that it is a vector in the column
z
space of Ai, that is, there exists a non-zero vector such that bi = AiZ. As
we shall see later in this appendix, the fact that b lies in the column space
of Ai turns out to be a fundamental result to the analysis of the existence
of valid contact forces, since it guarantees that a solution to the system of
equations always exists for frictionless contacts.
In the case of multiple simultaneous contacts, the accelerations and con-
tact forces at each individual contact point are merged into a system-wide
acceleration and contact-force vector

(G.2)

with m being the total number of simultaneous contacts. In the context of


simultaneous contacts, equation (G.1) is replaced by

a AF+b

1
Al2 Al3
bl
( Au
Al2t A22 A 23 m
A20l
b2
t A' b3
Al3 t A 23 A33
~~~ F+
,(G.3)
t t
AlOlt A20l A30l AOlOl bm

where each sub-matrix Aij is a 3 x 3 matrix of the same form as matrix


Ai in equation (G.1). For instance, sub-matrix A 23 relates the contact
force F3 = ((F3 )n, (F3 )t, (F3 )kY of contact G3 with the acceleration a2 =
((a2)n, (a2)t, (a2)k)t of contact G2.
According to the contact-force derivations presented in Chapters 3 and 4,
the contact force at each contact point Gi is said to be valid if it satisfies
the non-interpenetration conditions (also referred to as normal conditions)
at Gi , namely

(Fi)n(ai)n 0
(ai)n > 0 (G.4)
(Fi)n > 0,

1 Unless otherwise stated, the term acceleration used in this appendix means the
relative acceleration between the contacting bodies at a contact point.
G.2 Dantzig's Algorithm: The Frictionless Case 339

that is, either the contact-force or the acceleration components along the
contact normal can be greater than zero, but never both of them simulta-
neously.
The actual derivation of equation (G.4), as well as how the coefficients
of matrix A and vector b are computed for a given contact configuration,
were already covered in detail in Chapters 3 and 4. Here, we shall focus on
how the system of equations is actually solved.
It happens that the formulation presented in equations (G.4) and (G.3)
fits the well known Linear Complementarity Problem (LCP) formulation
of linear programming theory. The approach indicated depends on whether
friction is being considered. There are three possible cases to be addressed:
frictionless contacts, contacts with static friction only, and the more general
case of contacts with dynamic friction. In the following sections, we shall
present approaches to the LCP problem associated with each of these three
possible cases.

G.2 Dantzig's Algorithm: The Frictionless Case


Dantzig's algorithm works by incrementally computing intermediate solu-
tions for instances of the problem defined by equations (G.4) and (G.3),
where each instance takes into account one more contact point than the
previous instance. At instance i, the algorithm computes the contact force
for the ith contact point without violating the non-interpenetration con-
ditions for the (i - 1) contact points already resolved at instance (i - 1).
Assuming we have m simultaneous contact points, the solution of the LCP
problem is immediately obtained after solving each of the m instances.
In the frictionless case, the direction of the contact force is the same as the
direction of the contact normal, that is, the contact force has no tangential
components. Therefore, the system of equations is formulated using only
the normal components of the contact-force and acceleration vectors given
in equation (G.2). In other words, for each frictionless contact Gi we have

and the system-wide vectors representing the accelerations and contact


forces can then be written using the shorthand format

11 = ((al)n, ... , (ai)n, ... , (am)n)t


F ((Ft}n, ... , (Fi)n, ... , (Fm)n)t ,
omitting the tangential components. This significantly simplifies the com-
putation of matrix Ai and vector bi associated with contact Gi , since there
340 Appendix G. The Linear-Complementarity Problem

is no need to compute the coefficients related to the tangential components.


Therefore, for the frictionless case, Ai and vector bi are reduced to

Ai ((aii)n)
b ((bi)n) ,

that is, they become scalars.


According to equation (G.4), a solution is achieved whenever either the
contact force or the relative acceleration along the contact normal of each
contact point is zero. As shown in Figure G.1, a positive relative normal
acceleration (ai)n > 0 indicates that the contacting bodies are moving away
from each other at contact point C i , and the contact is about to break. In
this situation, the contact force (Fi)n in equation (G.4) should be set to
zero to enforce

If the normal acceleration (ai)n is zero (see Figure G.2), contact between
the bodies is maintained, and any non-negative contact force (Fi)n can be
used in equation (G.4). The problem arises when the normal acceleration
(ai)n is negative, as shown in Figure G.3. Here, the bodies are accelerating
towards each other at the contact point, indicating that they are about to
interpenetrate. A sufficiently powerful positive contact force (Fi)n should
then be applied to make the negative normal acceleration become zero.
Clearly, the contact points we need to worry about are those having nega-
tive normal acceleration.

(a,). > 0

t = t/ t = t/ +l1t,

FIGURE G.l. The relative-acceleration component (ai)n along the con-


tact-normal direction is positive and the contact force Ji is zero (contact is about
to break at t = (ti + 6ti)'
G.2 Dantzig's Algorithm: The Frictionless Case 341

FIGURE G.2. The relative-acceleration component (ai)n along the con-


tact-normal direction is zero, and the contact force can be any non-negative
value (bodies remain in contact).

(a,). < 0

FIGURE G.3. The relative-acceleration component (ai)n along the con-


tact-normal direction is negative, and the contact force should be large enough
to reduce it to zero to prevent interpenetration.
342 Appendix G. The Linear-Complementarity Problem

As mentioned before, the main idea of Dantzig's algorithm is to assure the


non-interpenetration conditions at each new contact point while maintain-
ing these conditions at the contact points already resolved. For example,
at the first instance, the algorithm ignores all contact points save one 2 •
This has the same effect as setting all contact forces to zero, and solving
equations (G.4) and (G.3) for just one contact point, that is, solving

(adn = «all)n (Fdn + (bdn) > 0


(FI}n (al)n = (Fdn «al1)n (Fdn + (b1)n) o (G.5)
(Fl)n > O.
For this contact point, the algorithm checks whether the normal accelera-
tion (al)n is positive, zero or negative, and makes the necessary adjustment
to the contact force (Fl)n in the latter case so as to prevent interpenetration
of the contacting bodies at the contact point. At the end of the first in-
stance of the algorithm, the contact-force vector will have the intermediate
value

with

(FI}n ~ 0.

At the second instance, the algorithm computes the contact force (F2 )n
so that the normal acceleration (a2)n is non-negative. This should be done
without violating the non-interpenetration conditions along the normal di-
rection of the contact point already resolved on the first instance. So, at
the second instance, equations (G.4) and (G.3) are reduced to:

It is clear from the above equation that, as we change (F2 )n, the values
of (a2)n and (at}n change as well, thus requiring an update .6.(Fl)n to the
contact force (F1)n in order to enforce the non-interpenetration conditions
of equation (G.5).

2The order in which the contact points are resolved is irrelevant.


G.2 Dantzig's Algorithm: The Frictionless Case 343

In general, at instance m, an increase of 6(Fm)n on the contact force


(Fm)n requires an update 6(Fdn on the values of the contact forces (Fi)n
for all i E {I, ... , (m -I)} already computed at instance (m -1). This up-
date is absolutely essential to the maintenance of the non-interpenetration
conditions at these contact points. In the following paragraphs, we shall ex-
amine in more detail how the non-interpenetration conditions are actually
maintained.
Let 6F and 6a be the increment to the force and acceleration vectors
computed at instance m, that is

6F = (6(Fdn' 6(F2 )n, . .. ,6(Fm)n)t


6a (6(al)n, 6(a2)n, . .. , 6(am )n) .
The updated force and acceleration vectors are then given by

(G.6)
anew = a + 6a .
Substituting equation (G.3) into (G.6) we get

6a anew - a
(A Fnew + b) - (AF + b)
(A (F + 6F) + b) - (A F + b)
A6F. (G.7)
So, as we increase (Fm)n by 6(Fm)n, some (ai)n'S and (Fj)n's will in-
crease or decrease according to equation (G.7), depending on the values of
the coefficients of matrix A. Clearly, the problem arises when the adjust-
ments associated with contact point Cm violate the non-interpenetration
conditions for one or more contact points Ci with i E {I, 2, ... , (m - I)}.
As stated in equation (G.4), the non-interpenetration conditions are
achieved at the contact point Ci whenever the collision force (Fi)n is zero
and (ai)n > 0 (Le., we need to maintain the condition (Fi)n = 0), or the
relative acceleration (ai)n is zero and (Fi)n ;::: 0 (Le., we need to maintain
the condition (ai)n = 0). Therefore, there are only two ways the non-
interpenetration conditions at contact point Ci can be violated.

1. If (Fi)n = 0 and an increase in (Fm)n by 6(Fm)n forces (ai)n to


assume a negative value.
2. If (ai)n = 0 and an increase in (Fm)n by 6(Fm)n forces (Fi)n to
assume a negative value.
344 Appendix C. The Linear-Complementarity Problem

If the nOll-interpenetration conditions at contact point C i were achieved


with (Fi)n = 0, then we need to check whether condition (1) is valid after
each increase in (Fm)n. On the other hand, if the non-interpenetration
conditions were achieved with (ai)n = 0, then we need to check whether
condition (2) is valid. In other words, we need to keep track of which case
the contact point falls into (either zero contact force or zero acceleration)
before we can decide the condition in need of verification. This can be
efficiently implemented as follows.
At the beginning of instance m, we sub-divide the contact points into
two groups. The first group, called ZA (zero acceleration), contains the
indexes of all contact points Ci with i < m that have (ai)n = O. Because
instance (m - 1) was already resolved, the contact force for each contact
point in ZA is guaranteed to have (Fi)n ~ 0, that is

The second group, called ZF (zero force), contains the indexes of all
contact points C i with i < m that have (Fi)n = O. Again, since instance
(m - 1) was already resolved, the normal acceleration for these contact
points is guaranteed to be (ai)n > 0, that is

As we increase (Fm)n by .6.(Fm)n, the algorithm tries to keep (ai)n = 0


for all i E ZA, and to keep (Fj)n = 0 for all j E ZF, while updating the
contact forces and normal accelerations using equation (G.7). The idea is
then to set .6.(ai)n = 0 for all i E ZA, such that (ai)n remains the same,
then set .6.(Fj)n = 0 for all j E ZF, such that (Fj)n remains the same,
and lastly solve equation (G.7) for the unknowns .6.(Fi)n for i E ZA. If
while solving equation (G.7) we detect that some (Fi)n with i E ZA has
decreased to zero, then we temporarily stop the computations and move
contact point C i from ZA to ZF. By so doing, we prevent (Fi)n from
decreasing even further and end up assuming a negative value. On the
other hand, if we detect that some (ai)n with i E ZF has decreased to
zero, then we temporarily stop the computations and move contact point
Ci from ZF to ZA to prevent (ai)n from assuming a negative value. In both
cases, equation (G.7) is re-arranged according to the index update of the
contact points in both ZA and ZF groups, and the computation continues
until we have increased (Fm)n enough to make (am)n = O. Figure G.4
shows a finite-state machine representation of the possible group changes
that contact point C i can make while solving equation (G. 7).
Let's examine in more detail how equation (G.7) is actually solved for
the unknowns .6.(Fi)n for i E ZA. Because the order in which the contact
points arc numbered is irrelevant, let's assume that ZA = {I, 2, ... , k} and
G.2 Dantzig's Algorithm: The Frictionless Case 345

FIGURE GA. At any instant during the solution of equation (G.7), a contact
point Ci can be in one of two states, namely ZA and ZF. The arrows show the
direction of the possible movements, together with the condition that needs to
be satisfied to trigger the movement.

ZF = {(k + 1), (k + 2), ... , (m - I)}, and that we have (am)n < 03 . The
matrix A and increment vector L,F can then be partitioned such that the
first k columns correspond to contact points in ZA, and the remaining
columns to contact points in ZF. By so doing, we have

A~( A12t ~l
Au A12
A22 V2 ) (G.8)
Vi ~ c
and

L,F =
(
x
0
L,(Fm)n
). (G.9)

where Au E IR kxk and A22 E IR(m-l-k)x(m-l-k) are square symmetric


matrices, ih E IRk and'lh E IR(m-l-k) are vectors, c is a scalar and x E IRk
is the unknown contact-force increment we want to determine. Substituting
equations (G.8) and (G.9) into equation (G.7), we obtain

(G.lO)

We can then rearrange L,iJ, in the same way we did for L,F, that is

3If (am)n :::: 0, then we can immediately solve instance m by setting (Fm)n = O.
346 Appendix G. The Linear-Complementarity Problem

(G.ll)

where (5 E ffikxk. Combining equations (G.lO) and (G.ll), we have

that is, we need to solve the linear system

(G.12)
for the unknown contact force increment x. Since we don't know in advance
which increment 6(Fm)n should be used in order to increase (am)n to zero,
we initially solve for

and then adjust the solution by computing the smallest positive scalar s
such that, when we increase F by s~F, we have either (am)n = 0, or some
contact point moved between ZA and ZF. In other words, the scalar s
is used to limit how much we can increase (Fm)n without violating the
non-interpenetration conditions for the remaining contact points.
There are three situations to consider when computing the scalar s. If
~(am)n > 0, then the normal acceleration at contact point Cm is increas-
ing. Because we want to increase (am)n < 0 up to the point at which it
becomes zero, then the maximum allowed step size s that does not make
(am)n > 0 is

(am)n
s= - . (G.13)
~(am)n

The second situation occurs whenever ~(Fi)n < 0 for i E ZA, that is,
the contact force at contact point Ci is decreasing. Because we want to
enforce (Fi)n 2: 0 for i E ZA, the maximum allowed step size s that does
not make (Fi)n negative is

(Fi)n w· ZA . h A( ) (G.14)
S :::; - 6(Fi)n ' v Z E WIt L.:1 Fi n <0.
The third and last situation occurs when we have ~(ai)n < 0 for i E ZF,
that is, the normal acceleration at contact point Ci is decreasing. Because
we want to enforce that (ai)n > 0 for i E ZA, the maximum allowed step
size s that does not make (ai)n negative is

(G.15)
G.2 Dantzig's Algorithm: The Frictionless Case 347

The goal is to select the smallest s satisfying equations (G.13), (G.14)


and (G.15). Having determined s, we update F and a by

Fnew F + (s 6F) ,
anew = a + (s 6a) .

If the smallest s was obtained from equation (G.13), then (am)n = 0


after the update, and the non-interpenetration conditions at contact point
Cm are satisfied. In this case, contact point Cm is moved into Z A and the
mth instance of the algorithm is completed.
However, if the smallest s was obtained from equation (G.14), then there
exists a contact point Ci with i E ZA that had its force (Fdn decreased to
zero before we could reach (am)n = O. In this case, we need to move index i
from ZA to ZF to prevent the force from becoming negative. The partition
of matrix A is then updated to account for the contact point moved, and
the algorithm loops back to continue increasing (Fm)n until (am)n = o.
A similar update happens if the smallest s was obtained from equa-
tion (G.15). In this case, there exists a contact point Ci with i E ZF
that had its acceleration (ai)n decreased to zero before we could reach
(am)n = O. This makes it necessary to move index i from ZF to ZA to
prevent the acceleration from becoming negative. Again, the partition of
matrix A is rearranged to account for the contact point moved, and the
algorithm loops back to continue increasing (Fm)n until (am)n = O.

G.2.1 Termination Conditions


There are two critical assumptions in the frictionless algorithm described in
the previous section that have the potential of being invalid, meaning they
can compromise the existence of a solution. The first critical assumption is
the existence of a solution x to the linear system defined by equation (G.12)
with 6(Fm)n = 1, that is, the existence of a solution to

Anx= -ih . (G.16)


Fortunately, it can be shown that the vector ih is always in the column
space of All for all possible combinations of indexes in Z A and Z F. There-
fore, the linear system in equation (G.16) is well conditioned and a solution
x is guaranteed to always exist.
The second critical assumption is that an increase in (Fm)n will also
cause an increase in (am)n by a positive amount, such that (am)n will
eventually reach the desired zero value. If we substitute (s 6F) back into
equation (G.lO), we have that (am)n increases by
348 Appendix G. The Linear-Complementarity Problem

In this case, it can be shown that, if A is positive definite, then both


((ih)t if + c) and step size s are always positive. This in turn means that
(am)n will always increase by a positive amount at the end of each step,
that is, the algorithm is guaranteed to terminate after a finite number of
steps.
The interested reader is referred to Section GA for pointers to the liter-
ature containing formal proofs of these assumptions.

G.3 Baraff's Algorithm: Coping with Friction


Baraff's extension to Dantzig's algorithm addresses the friction problem
in much the same way as the normal conditions were addressed in the
frictionless case. Again, the idea is to incrementally compute intermediate
solutions for instances of the problem defined by equations (G.4) and (G.3),
where each instance takes into account one more contact point than the
previous instance. At instance i, the algorithm computes the contact force
for the ith contact point without violating the normal and friction condi-
tions for the (i - 1) contact points already resolved at instance (i - 1). The
actual friction conditions to be satisfied at each contact point depend on
the contact's being static or dynamic.
Respecting friction, the contact force will have a normal component and
a tangential component, the latter owing to the friction force acting at
the contact point. Clearly, the relation between the normal and tangential
contact-force components depends on the contact model adopted.
In this book, we use the Coulomb friction model to relate the tan-
gential and normal contact-force components. More specifically, we use a
directional-friction model to compute the tangential contact-force compo-
nents 4 . Let Fi be the contact force associated with contact Gi , that is

Using the directional-friction model, the contact-force components on


the tangent plane are obtained from the contact-force component along
the normal direction using

(Fi)t J1,t (Fi)n


(Fi)k J1,k (Fi)n ,

where J1,t and J1,k are the coefficients of friction along the tangent-plane
directions t and k.

4This is the same model used in Chapters 3 and 4.


G.3 Baraff's Algorithm: Coping with Friction 349

It is important to notice that the directional-friction model is a gener-


alization of the widely used model of relating the tangential and normal
contact-force components using just one omnidirectional coefficient of fric-
tion J.L, as in

(G.17)
In equation (G.17), the term (Fi)tk refers to the net contact-force com-
ponent on the tangent plane given by

For example, if friction is isotropic, that is, independent of direction, we


can write

J.Lt = J.L cos¢


J.Lk = J.L sin¢

for some angle ¢, and so

V(Fi); + (Fi)~
J J.L2 (Fi); cos ¢2 + J.L2 (Fi); sin ¢2
J.L (Fi)n ,

which is the same result obtained using the omnidirectional friction model
of equation (G.17). The main advantage of using the directional-friction
model is that the non-linear equation

that needs to be enforced when the contacting bodies are not sliding at
the contact point (i.e., static friction) can be substituted for two linear
equations

I (Fi)t I < J.Lt (Fi)n


I (Fi)k I < J.Lk (Fi)n ,
which are equivalent to the non-linear equation if friction is isotropic, and,
most important, can be independently resolved.
The way the normal and tangential contact-force components are related
in the Coulomb friction model depends on the contact's being static or
dynamic. A contact is said to be static if the net relative velocity along
350 Appendix G. The Linear-Complementarity Problem

its tangent plane is zero, or less than a threshold value. Otherwise, the
contact is said to be dynamic. In either case, the system-wide contact-force
and relative-acceleration-vector components for m simultaneous contacts
are expressed as

((adn, (al)t, (al)k, ... , (am)n, (am)t, (am)k)t (G.18)


((F1)n, (Fdt, (F1)k,"" (Fm)n, (Fm)t, (Fm)k)t , (G.19)

that is, the tangential contact-force components are no longer omitted, as in


the frictionless case (see equation (G.5)). Therefore, the frictional contact-
force computation requires solving the following system (which is the same
as that shown in equation (G.3), but repeated here for convenience):

a=AF+b=
( Al2t
An
AlSt
A12
A22
A 2S
t
A lS
A 2S
Ass
A,~ 1
A 2rn

~~~ F+
b1
b2
b3

Alrnt A 2rn
t t
Asrn Arnrn bm
(G.20)
where a and F are given by equations (G.18) and (G.19), and each sub-
matrix Aij is a 3 x 3 matrix relating the relative acceleration at contact
e
ei with the contact force at contact j . Clearly from equation (G.20), an
increment of

to the contact-force components will cause a variation of

to the acceleration components obtained from

6a = A6F. (G.21)
The problem is that, depending on the values of the coefficients of ma-
trix A, an increment of 6(Fm)n to the normal contact-force component
of contact em at the mth iteration can increase or decrease the contact-
force and acceleration components of other contacts already resolved in
one of the previous iterations. Not only that, an increment of 6(Fm)t or
6(Fm)k to the tangential-force components of contact em can not only af-
fect the normal and friction conditions already established for the previous
(m - 1) contacts, but can also increase or decrease the normal components
(Fm)n and (am)n associated with contact em. Another important issue is
that, because we are adopting the Coulomb friction model, the tangential
G.3 Baraff's Algorithm: Coping with Friction 351

contact-force components and their increments are computed as a function


of the normal-force component and its increment. This in turn, requires
that we first resolve the normal conditions at contact Cm , and only then
resolve the friction conditions while enforcing the normal conditions just
obtained.
Therefore, enforcing the normal and friction conditions at the mth itera-
tion is a two-step process. We need to first resolve the normal conditions at
contact Cm, assuming 6(Fm)t and 6(Fm)k are zero, while maintaining the
normal and friction conditions for the previous (m - 1) contact points. We
need then to adjust 6(Fm)t and 6(Fm)k to assure the friction conditions
along the tangent-plane directions f and k, while maintaining the normal
and friction conditions for the previous (m - 1) contact points, as well as
the normal condition for contact Cm. At the end of the mth iteration, we
have assured both normal and friction conditions for all m contacts.
In the following sections, we shall apply this solution scheme to both
static and dynamic friction, and study the termination conditions for each
case.

G.3.1 Static-Friction Conditions


In the static-friction case, the relation between the normal and tangential
contact-force components depends on the value of the relative tangential
acceleration. Let iii and Pi be, respectively, the relative acceleration and
contact force at contact Ci , that is

iii = ((ai)n, (ai)n, (ai)n) ,


Pi = ((Fi)n, (Fi)n, (Fi)n) .
If the relative tangential acceleration is zero, then the tangential compo-
nents of the contact force are constrained within a range proportional to the
value of the normal component. Since we are using the directional-friction
model, this condition translates into assuring

(G.22)

as opposed to assuring the commonly used condition

that arises when the anisotropic-friction model is considered. Notice that


the coefficients J..Lt and J..Lk in equation (G.22) are the static-friction coeffi-
cients along the tangent-plane directions f and k, respectively.
352 Appendix G. The Linear-Complementarity Problem

If on the other hand the relative tangential acceleration is not zero, then
the tangent components of the contact force will have maximum magnitude

1 (Fi)t 1 J-tt (Fi)n, if (ai)t of- 0


1 (Fi)k 1 J-tk (Fi)n, if (ai)k of- 0
and opposite direction with respect to the relative tangential acceleration,
that is, the contact force and relative acceleration must have opposite signs:

(Fi)t (ai)t < 0


(Fi)k (ai)k < O.
Therefore, the static friction conditions that need to be assured at each
contact point C i are

(Fi)t 1 < J-tt (Fi)n


1

(ai)tCFi)t < 0 (G.23)


(ai)t (J-tt (Fi)n - 1 (Fi)t I) 0

and

I (Fi)k I ~ J-tk(Fi)n
(ai)k(Fi)k < 0 (G.24)
(ai)k(J-tk(Fi)n - 1 (Fi)k I) 0

The last condition in equations (G.23) and (G.24) assures that (Fi)t
and (Fi)k will have maximum magnitude J-tt(Fi)n and J-tk(Fi)n whenever
(ai)t of- 0 and (ai)k of- 0, respectively.
As mentioned, the way the static-friction conditions are assured is very
similar to that used to assure the normal conditions. In the frictionless case,
we created two groups of indexes, namely ZA and ZF, and used them to
partition the contact-force and acceleration vectors 6F and 6ii such that
the first rows are filled in with contact points with index in ZA, the next
rows are filled in with contact points with index in Z F, and the last row
is filled in with 6(Fm)n and 6(a m )n associated with contact Cm. The
partition results in

(G.25)

where F and ii are related by


G.3 Baraff's Algorithm: Coping with Friction 353

6a = A 6F . (G.26)
We then made 6(Fm)n = 1 and solved a sub-system of equation (G.26)
of the form

Aux= -ih

for X, that is, for the force increments 6(Fi)n with i E ZA (see Section G.2
for details on how this sub-system is constructed from equation (G.26)).
x
We substitute and 6(Fm)n = 1 back into equation (G.25) to obtain all
components of 6F, and use equation (G.26) again to obtain all components
of 6a. Finally, we compute the minimum scalar s to be used in

a = a + s 6a
F F+s6F

such that, either the normal conditions are met to contact em,
or a change
in the index sets ZA or ZF is required, in which case we need to loop back
and re-partition vectors /::,.F and 6a according to the updated groups and
solve the updated system.
Following the same principles used to resolve the normal conditions for
the frictionless case, we shall create eight groups to manage the indexes
of the contact points. The first two groups are identical to the frictionless
case, namely groups ZAn (zero normal acceleration) and ZFn (zero normal
contact force). These groups are used to assure the normal conditions for
static contacts.
The next three groups are ZA t , MaxFt and MinFt . They are used to
classify the contact points with respect to their static-friction conditions
r.
along the tangent-plane direction The ZA t (zero acceleration) group is
used to keep track of the contact points that have zero tangential acceler-
ation along f, that is

(G.27)

whereas the MaxFt (maximum friction fo,rce) and MinFt (minimum fric-
tion force) groups are used to keep track of the contact points that have
non-zero tangential acceleration along f, that is

MaxFt = {(I:::; i < m) : (ai)t < 0 and (Fi)t = JLt (Fi)n}


(G.28)
MinFt {(I :::; i < m) : (ai)t > 0 and (Fi)t = -JLt (Fi)n} .
354 Appendix G. The Linear-Complementarity Problem

Notice that, by construction, the contact-force components (Fi)n are


always non-negative. The last three groups are ZAk, MaxFk and MinFk.
They are used to classify the contact points with re~ect to their static-
friction conditions along the tangent-plane direction k. Their descriptions
are analogous to those given to groups ZA t , MaxFt and MinFt , that is:

{(I ~ i < m) : (ai)k = 0 and I (Fi)k I ~ J.Lk (Fi)n}


{(I ~ i < m) : (ai)k < 0 and (Fi)k = J.Lk (Fi)n}
{(I ~ i < m) : (ai)k > 0 and (Fi)k = -J.Lk (Fi)n} .
(G.29)

Let's examine how these eight groups are used at the mth iteration to
assure the normal and static-friction conditions for all other (m -1) contact
points already resolved at iteration (m - 1). At any point in the algorithm,
the index i of each contact point Ci appears in three out of the eight
groups above described. More specifically, we assure the normal conditions
at contact Ci with i ~ m by setting:

• i E ZAn if (ai)n = 0 and (Fi)n ~ 0, or

• i E ZFn if (!i)n = 0 and (ai)n ~ o.


We assure the static-friction conditions along the tangent-plane direction
f by setting:
• i E ZAt if (ai)t = 0 and -J.Lt(Fi)n ~ (Fi)t ~ J.Lt(Fi)m or
• i E MinFt if (Fi)t = -J.Lt (Fi)n and (ai)t > 0, or
• i E MaxFt if (Fi)t = J.Lt (Fi)n and (aih < o.
Finally, we assure the static-friction conditions along the tangent-plane
direction k by setting:

• i E ZAk if (ai)k = 0 and -J.Lt(Fi)n ~ (Fi)k ~ J.Lt(Fi)n, or

• i E MinFk if (Fi)k = -J.Lt (Fi)n and (ai)k > 0, or

• i E MaxFk if (Fi)k = J.Lt (Fi)n and (ai)k < o.


The first step at the mth iteration is to assure the normal conditions at
Cm. This can be done by partitioning the vectors /:).F and /:)'i1 such that
the first rows are filled in with contact points with index in ZAn, the next
rows are filled in with contact points with index in ZFn , and the last row
is filled in with /:).Fm and /:)'i1m associated with contact Cm. The partition
results in
C.3 Baraff's Algorithm: Coping with Friction 355

6F = ( 6<l)n 1
6(Fm)t
6ii = ( 6<tn 1
6(a m )t
(G.30)

6(Fmh 6(a m )k
where F and ii are related by equation (G.26). Notice that x and if in
equation (G.30) are of the form:

x (6(Fdn, 6(Fdt, 6(Fdk, ... , 6(Fj)n, 6(Fj)t, 6(Fj)k)t


if (6(aj+l)n, 6(aj+dt, 6(aj+dk, ... ,
6(a m_I)n, 6(a m-dt,6(a m-lh)t ,

assuming ZAn = {I, 2, ... ,j} and ZFn = {(j + 1), (j + 2), ... , (m - I)}.
Because we are assuring the normal conditions first, we set

6(Fi)t = 6(Fih 0 Vi
6(ai)t = 6(ai)k 0 Vi
6(Fm)n 1
6(Fm)t 0
6(Fm)k 0

and solve a sub-system of the form of equation (G.30) for x, that is, for
the force increments 6(Fi)n with i E ZAn. The matrix An and vector ih
defining the sub-system are constructed exactly as described in Section G.2.
Having computed x, we substitute its value back into 6F and use equa-
tion (G.26) again to obtain all components of 6ii. Lastly, we compute the
minimum scalar s to be used in

ii ii + s 6ii
F F+s6F
such that, either the normal conditions are met to contact em, or a change
in the index sets ZAn or ZFn is required, in which case we need to loop
back and re-partition vectors 6F and 6ii according to the updated groups
and solve the updated system. The scalar s is determined as follows.

(G.31)
356 Appendix C. The Linear-Complementarity Problem

(G.32)

• As long as (am)n < 0, we want to force it to zero in order to satisfy


the normal conditions at contact em. m
So, if 6(a )n > 0, then

s < _ (am)n (G.33)


- 6(a m )n
If the minimum scalar s comes from equation (G.33), then the normal
conditions are established at contact point em.
If it comes from equa-
tion (G.32), then we need to move its associated index i from ZFn to ZAn.
Lastly, if the scalar s comes from equation (G.31), then we need to move
its associated index i from ZAn to ZFn. Notice that, in both cases where
the index sets are modified, we need to loop back and re-partition the force
and acceleration vectors until equation (G.33) is satisfied.
Having resolved the normal conditions at contact em,
the next step
consists of resolving its static-friction conditions. If the normal contact-
force component (Fm)n obtained after assuring the normal conditions at
contact em is zero, then the static-friction conditions are satisfied by setting
(Fm)t = (Fm)k = 0, and we are done with the mth iteration. Also, if
m E ZAn, that is if (am)n = 0 after the normal conditions are assured,
then setting (Fm)t = (Fm)k = 0 also assures the static friction conditions
because

(Fm)t = 0 < I1t (Fm)n


(Fm)k = 0 < 11k (Fm)n .
If none of the above conditions is satisfied, then, whenever (am)t or
(am)k are negative, we resolve the static-friction conditions by applying
a solution method identical to that used for the normal conditions. The
solution method consists of solving equation (G.26) by first partitioning
it in a way that the first rows correspond to zero-acceleration increments,
and the next rows correspond to zero-force increments. The partition is
computed after setting:

6(Fi)t I1t 6(Fi)n, Vi E MaxFt


f:::..(Fi)t -l1t f:::..(Fi)n, Vi E MinFt
f:::..(Fi)k 11k f:::..(Fi)n, Vi E MaxFk
f:::..(Fi)k -11k f:::..(Fi)n, Vi E MinFk (G.34)
f:::..(ai)t 0, Vi E ZA t
G.3 Baraff's Algorithm: Coping with Friction 357

~(ai)k 0, Vi E ZAk
~(Fm)n = 1.

The components ~(Fm)t and ~(Fm)k are set according to the following 5 :

...............
1

ILt ~(Fm)n = ILt, if (am)t < 0


...............
1

-ILt ~(Fm)n = -ILt, if (am)t > 0


(G.35)
...............
1

~(Fm)k = ILk ~(Fm)n = ILk, if (am)k < 0


...............
1

~(Fm)k = -ILk ~(Fm)n = -ILk, if (am)k >0.


After the assignments described by equations (G.34) and (G.35) are com-
pleted, we partition the original system such that:

• The first rows are filled with the rows of the original system that have
zero acceleration.
• The next rows are filled with the rows of the original system that
have zero force.
• The last three rows correspond to the normal and tangential equa-
tions defined by contact em.
Notice that the original system given by equation (G.26) is laid out such
that each contact corresponds to three consecutive rows of the system, one
for the normal and two for the tangential contact directions. This may no
longer be the case after the above-mentioned partition is carried out. In
other words, the system to be solved is partitioned, not with respect to the
contact points in the sense that their three corresponding equations are
always kept together (Le., laid out consecutively in the system), but with
respect to which rows have zero force or acceleration assigned to them. The
partition result is shown in equation (G.30).
Another fact worth mentioning is that, when ~(Fi)t = ±ILt ~(Fi)t and
i fj. ZFn (Le., ~(Fi)n f- 0), then we need to merge this row with the row
corresponding to 6(Fi)n. We then do a substitution of variable

5Notice that, if (amh = 0, then we the static-friction condition is immediately satis-


fied by setting (Fmh = o. The same applies to (Fm)k if (am)k = O.
358 Appendix G. The Linear-Complementarity Problem

to solve the system for 6(qi)n and use its value to compute 6(Fi)n and
6(Fik The same applies for 6(Fi )k.
Having partitioned the system according to equation (G.30), we solve for
the sub-system containing the rows associated with zero-acceleration incre-
ments. This will give us the complete vector 6F, which can be substituted
back again into equation (G.26) to compute 60,. Lastly, we compute the
minimum scalar 8 to be used in

0, = 0, + 860,
F F+86F
such that, either the static-friction conditions are met for contact em, or a
change in the index sets is required, in which case we need to loop back and
re-partition vectors 6F and 60, according to the updated groups and solve
the updated system. The minimum scalar 8 ~ 0 is determined as follows

(G.36)

(G.37)

• If i E ZAt and 6(ai)t =f. 0, then we set

8=0 (G.38)

• If i E MaxFt and 6(ai)t < 0, then

(G.39)

• If i E MinFt and 6(ai)t > 0, then

(GAO)

• If i E ZAk and 6(ai)k =f. 0, then we set

8=0 (GAl)
G.3 Baraff's Algorithm: Coping with Friction 359

s < _ (ai)k (G.42)


- 6(ai)k
• If i E MinFk and 6(ai)k > 0, then

(G.43)

• If i = m, then,

- If (am)t > 0 and 6(a m )t < 0, then


(amh
s::; (G.44)
6(am )t
- If (am)t < 0 and 6(am )t > 0, then

s < _ (am)t (G.45)


- 6(am )t
- If (am)t = 0 and 6(Fmh -# 0, then
< (JLt(Fm)n - (Fm)t) (G.46)
s - 6(Fm)t
- If (am)k > 0 and 6(a m )k < 0, then
s < _ (am)k (G.47)
- 6(a m )k
- If (am)k < 0 and 6(am)k > 0, then
s < _ (am)k (G.48)
- 6(a m)k
- If (am)k = 0 and 6(Fm)k -# 0, then
s < (J.J.k(Fm)n - (Fm)k)
(G.49)
- 6(Fm)k
If the minimum s comes from one of equations (G.44) to (G.49), then
the static-friction conditions are met at least in one of the tangent direc-
tions. We can carry out a quick test to determine whether they are met
on both directions, and if so the mth iteration is completed. However, if
the minimum s comes from any other equation, then we need to update
the groups accordingly and loop back to re-partition the system and solve
it again. There are several cases to be considered when carrying out the
update.
360 Appendix G. The Linear-Complementarity Problem

(aJ, > 0 (aJ, < 0

~~-~

FIGURE G.5. At any instant during the solution of equation (G.26), a contact
point Ci can appear in three out of eight possible states. The arrows show the
direction of the possible movements, together with the condition that needs to
be satisfied to trigger the movement.
G.3 Baraff's Algorithm: Coping with Friction 361

• If minimum s comes from equation (G.36), then move its associated


index i from ZAn to ZFn.
• If minimum s comes from equation (G.37), then move its associated
index i from ZFn to ZAn.
• If minimum s comes from equation (G.38), then move its associated
index i from ZAt to MaxFt if 6(ai)t < 0, or MinFt otherwise.
• If minimum s comes from equation (G.39), then move its associated
index i from M axFt to Z At.
• If minimum s comes from equation (G.40), then move its associated
index i from MinFt to ZA t .
• If minimum s comes from equation (G.4l), then move its associated
index i from ZA k to MaxFk if 6(ai)k < 0, or MinFk otherwise.
• If minimum s comes from equation (G.42), then move its associated
index i from MaxFk to ZAk.
• If minimum s comes from equation (G.43), then move its associated
index i from MinFk to ZA k .

Figure G.5 illustrates the possible state transitions between group in-
dexes.

C.3.2 Dynamic Friction


Dynamic friction occurs whenever the relative tangential velocity at contact
Ci differs from zero. In this case, the magnitude of the tangential contact-
force components are always maximum, that is

(G.50)

The sign in equations (G.50) is chosen such that the contact force is
pointing in the opposite direction of the tangential velocity, that is

- sign ((Vr)i . f)

where (Vr)i represents the relative tangential velocity at contact point i.


Since the magnitude of the dynamic contact-force components is fixed
and linearly proportional to the normal contact-force component, we can
362 Appendix G. The Linear-Complementarity Problem

merge the three rows associated with contact C i in equation (G.26) and
make the following substitution of variable

solve the system for 6(Qi)n, and use its value to compute 6(Fi )n, 6(Fih
and 6(Fi )k. In other words, we can use the same algorithm proposed in
Section G.3.1 for the static-friction case to enforce the dynamic-friction
conditions at contact Cm.
At the m-iteration, we make the variable substitution and compute the
appropriate 6F that enforces the normal conditions at all contact points,
including Cm. Having done so, the tangential contact-force components
are computed using equations (G.50). Lastly, index m is assigned to the
following groups.

• If (am)n = 0, then add m to ZAn.

• If (Fm)n = 0, then add m to ZFn.


• If (am)t = 0, then add m to ZAt .
• If (am)t =1= 0, then add m to MaxFt if sign (Fm)t > 0, or to MinFt
otherwise.

• If (am)k = 0, then add m to ZAk.


• If (am)k =1= 0, then add m to MaxFk if sign (Fmh > 0, or to MinFk
otherwise.

C.3.3 Termination Conditions


Most of the termination-condition properties discussed for the frictionless
case are still valid for the static-friction case, save the one that guarantees

°
the existence of a positive scalar s. It can be shown that, for the frictionless
case, the existence of a positive scalar s > guarantees that the algorithm
will always progress and will eventually terminate. However, in the static-
friction case, there can be situations wherein the scalar s is zero.
Consider the case wherein the contact point Ci is initially assigned to
ZAn, and (Fi)n decreases to zero after some steps s6(Fi )n' In this case, the
algorithm temporarily stops and moves index i from ZAn to ZFn , and ad-
justs the corresponding columns of matrix A. The algorithm then proceeds
to the next iteration, and we may find that (ai)n immediately assumes a
negative value. Again, the algorithm temporarily stops and moves index
i from ZFn to ZAn, and adjusts the corresponding columns of matrix A.
Clearly, the algorithm is locked in an infinite loop with index i moving back
and forth groups ZAn and ZFn.
G.4 Suggested Readings 363

Steps of size zero, such as the one just described, can be detected during
program execution by keeping track of the group the index i just came
from in the previous step, if any. If the group the index i is moving to is
the same as the group it came from in the previous step, then the contact Ci
is oscillating. The way to deal with this is to temporarily give up trying to
assure both normal and static conditions at contact Ci . This has the effect
of postponing the assurance of such conditions at Ci to a later time during
the algorithm's execution. The rationale behind this strategy is that, when
the algorithm comes back to contact Ci , more contacts have been assured
and the conditions that created the loop may no longer be the current
conditions of the problem. Unfortunately, the bottom line is that it can't
be proved whether the algorithm will always terminate when static friction
is considered.
In the dynamic-friction case, the situation gets even worse because the
system matrix A is no longer symmetric, and is possibly indefinite. In this
context, several properties that were used to guarantee the existence of
a solution in the frictionless case no longer apply. Here, it is possible to
have a situation in which, either the normal force component (Fi)n, or
the tangential force components (Fi)t and (Fi)k, will indefinitely increase
without driving (ai)n, (ai)t or (ai)k to zero. Another possible situation is
that increasing the contact force components may not necessarily trigger
a change in the index set of the groups ZAn, ZFn , ZAt , MaxFt , MinFt,
ZAk, MaxFk or MinFk.
As for implementation, these cases correspond to finding an unbounded
scalar6 S = 00. The way to deal with this is to treat as collisions all con-
tacts C i that are generating an unbounded scalar s, and apply the multiple-
collision techniques presented in Chapters 3 and 4 to resolve them. In sum-
mary, we resolve all contact first, and treat the remaining contacts that are
generating unbounded scalars s as collisions.

G.4 Suggested Readings


The determination of the existence of a solution for a general LCP problem
is known to be NP-hard, whereas finding the solution itself is a NP-complete
problem. However, there are some special cases of the coefficient matrix A
in which the LCP problem becomes convex, that is, the existence and actual
computation of a solution can be done in polynomial time, with worst-case
exponential time complexity. Such cases are addressed in detail in Cottle
et al. [CPS92].

6Before computing s, we initialize it to 00, such that we can detect at the end of the
iteration whether s = 00.
364 Appendix G. The Linear-Complementarity Problem

In the context of frictionless contact-force computations, the matrix A


is symmetric and positive semi-definite (PSD), and the vector b lies in the
column space of A. Fortunately, this is one of the cases when a polynomial
time algorithm can be used, such as Dantzig's algorithm described in Cottle
et al. [CD68]. Barafi' [Bar94, Bar93] presented a modification of Dantzig's
pivot-based method to cope with both static and dynamic friction. In the
latter case, the matrix A is not symmetric and possibly indefinite, and a
solution mayor may not be found. If a solution is not found, then Baraff's
algorithm is capable of detecting such a situation, and indicates the contacts
that should be dealt with as collisions in order to resolve the inconsistencies.
Other inconsistencies may also occur whenever vector b does not lie in
the column space of A. Such situations can happen when the contact geom-
etry represents an unsatisfiable combination of kinematic constraints of the
system. A more sophisticated implementation could use this to check for
inconsistencies on user-definable configurations where some objects are at-
tached to others by joints. Since in most cases users have the freedom to
attach joints to whichever objects they deem appropriate, inconsistencies
may arise from an inattentive selection of joint attachments.
Usually, the linear system defined by equation (G.16) can be solved us-
ing standard Gaussian elimination techniques readily available from several
books on linear algebra and matrix theory, such as Strang [Str91], Golub
et al. [GL96] and Horn et al. [HJ91]. However, efficacy can be boosted if we
use techniques that take into account the fact that consecutive invocations
of the linear system differ by a few rows and columns from the previous
invocation. Such techniques would incrementally update the LU decompo-
sition of matrix A already computed in the previous step, as opposed to
computing the decomposition from scratch. This has the effect of reducing
the computational cost from O(n 3 ) to O(n 2 ). Gill et al. [GMSW87] discuss
in detail an incremental factorization technique that maintains LU factors
for general sparse matrices.
Another commonly used formulation of the contact-force computation
states the problem as a quadratic programming problem (QP), that is

mjn(p A f - bt f) subjected to { ~f??"o b } .

L6tstedt [L6t84] originally proposed this approach based on a simplifica-


tion of the Coulomb friction model used to avoid the non-linear constraint:

In this case, the LCP problem is transformed into a LQP optimization


problem. Gill et al. [GM78] and Lawson et al. [LH74] present some numer-
ically stable techniques that can be used to solve the LQP problem.
Finally, the proof of the termination conditions discussed in Sections G .2.1
and G.3.3 can be found in Baraff [Bar94].
Appendix H
Software Implementation

The implementation of a rigid-body and particle-systems dynamic simu-


lator requires a considerable amount of work to design the system archi-
tecture and write the code. A high-level architectural specification of the
dynamic-simulation engine discussed in this book would, at a minimum,
include the following features.

• Load and Save rigid-body boundary descriptions from common graph-


ics files formats.
• Keep an internal representation of the objects to quickly carry out
several commonly used operations, such as:

- Given a face, retrieve all its edges and vertices.


- Given an edge, retrieve its vertices and the faces that have the
edge in common.
Given a vertex, retrieve all edges and faces that contain the
vertex.

Preferably, the internal data structures for vertices, edges and faces
should be redundant to carry out the above operations in constant
time.

• Decompose all non-convex polyhedra being simulated into a set of


convex parts.

• Decompose all polygonal faces of each polyhedra into triangles.


366 Appendix H. Software Implementation

• Compute hierarchical representations for all objects being simulated.


• Compute the cell decomposition of the simulated world.

• Implement a set of numerical integrators, including integrators using


implicit and explicit methods.

• Implement the collision-detection framework to process collisions.

• Implement the collision-response framework to repond to collisions.


This includes separating contacts from collisons.

The dynamic-simulation engine could also support more advanced fea-


tures, such as:

• Dealing with the dynamics and interactions of articulated systems,


supporting one or more types of joints.

• Providing an iteractive user interface to let users design their own


articulated bodies.

For each of the above-mentioned features, there are currently available


several commercial and open-source-code 1 software packages. The diver-
sity and robustness of such software packages is constantly improving, as
new modules are developed to support new capabilities, or remedy known
limitations. In this book, we have decided to support a Web site specially
devoted to software developers interested in the hands-on experience of
implementing a dynamic-simulation engine for rigid-body and particle sys-
tems. The URL of the Web site is:
http://hometown.aol.com/ animationengine
There you will find links to other related Web sites, categorized accord-
ing to the list given at the beginning of this appendix. By so doing, the
interested reader can obtain entire simulation systems, or separate mod-
ules that can be assembled to form a custom-tailored system, or build a
simulation engine from scratch using the techniques covered in detail in
this book.

1 Usually free for use on non-commercial applications.


References

[AF67) Marcelo Alonso and Edward J. Finn. Fundamental University


Physics. Addison-Wesley, 1967.

[Arv90) James Arvo. A simple method for box-sphere intersection


testing. Graphics Gems, 1:335-339, 1990.
[Bar89) David Baraff. Analytical methods for dynamic simulation of
non-penetrating rigid bodies. Computer Graphics (Proceed-
ings SIGGRAPH), 23:223-232, 1989.
[Bar90) David Baraff. Curved surfaces and coherence for non-
penetrating rigid body simulations. Computer Graphics
(Proceedings SIGGRAPH), 24:19-28, 1990.
[Bar91) David Baraff. Coping with friction for non-penetrating rigid
body simulation. Computer Graphics (Proceedings SIG-
GRAPH), 25:31-40, 1991.
[Bar92) David Baraff. Dynamic Simulation of Non-Penetrating Rigid
Bodies. PhD thesis, Cornell University, 1992.

[Bar93) David Baraff. Issues in computing contact forces for non-


penetrating rigid bodies. Algorithmica, 10:292-352, 1993.

[Bar94) David Baraff. Fast contact force computation for non-


penetrating rigid bodies. Computer Graphics (Proceedings
SIGGRAPH), 28:24-29, 1994.
368 References

[Bar96] David Baraff. Linear-time dynamics using lagrange multipli-


ers. Computer Graphics (Proceedings SIGGRAPH), 30:137-
146, 1996.

[Bau72] J. Baumgarte. Stabilization of constraints and integrals of


motion in dynamical systems. Computer Methods in Applied
Mechanics, pages 1-36, 1972.

[BB88] R. Barzel and A. H. Barr. A modeling system based on


dynamic constraints. Computer Graphics (Proceedings SIG-
GRAPH), 22:179-188, 1988.

[BD92] Chanderjit L. Bajaj and Tarnal K. Dey. Convex decompo-


sition of polyhedra and robustness. SIAM Journal on Com-
puting, 21(2):339-364, April 1992.

[BHW94] David Breen, Donald H. House, and Michael J. Wonzny.


Predicting the drape of woven cloth using interacting parti-
cles. Computer Graphics (Proceedings SIGGRAPH), 28:24-
29, 1994.

[BJ77a] Ferdinand P. Beer and E. Russell Johnston. Vector Mechan-


ics for Engineers: Volume 1 - Statics. McGraw-Hill, 1977.

[BJ77b] Ferdinand P. Beer and E. Russell Johnston. Vector Mechan-


ics for Engineers: Volume 2 - Dynamics. McGraw-Hill, 1977.
[Bra91] Raymond M. Brach, editor. Mechanical Impact Dynamics:
Rigid Body Collisions. John Wiley & Sons, 1991.

[BW97] David Baraff and Andrew Witkin. Partitioned dynamics.


Technical Report CMU-RJ-TR-97-33, The Robotics Institute
at Carnegie Mellon University, 1997.

[BW98a] David Baraff and Andrew Witkin. Physically based model-


ing. SIGGRAPH Course Notes, 13, 1998.

[BW98b] David Baraff and Andrew Witkin. Physically based model-


ing. SIGGRAPH Course Notes, 13, 1998.

[BW99] David Baraff and Andrew Witkin. Large steps in cloth


simulation. Computer Graphics (Proceedings SIG GRA PH),
33:43-54, 1999.

[Cam97] S. Cameron. Enhancing GJK: Computing minimum and pen-


etration distances between convex polyhedra. Proceedings
IEEE International Conference on Robotics and Automation,
pages 3112-3117, 1997.
References 369

[CD68] Richard W. Cottle and George B. Dantzig. Complementary


pivot theory of mathematical programming. Linear Algebra
and Its Applications, 1:103-125, 1968.

[Cha84] Bernard Chazelle. Convex partitions of polyhedra: A lower


bound and worst-case optimal algorithm. SIAM Journal on
Computing, 13(3):488-507, August 1984.

[CKS98] Swen Campagna, Leif Kobbelt, and Hans-Peter Seidel. Di-


rected edges: A scalable representation for triangle meshes.
Journal of Graphics Tools, 3(4):1-11, 1998.

[CPS92] Richard W. Cottle, Jong-Shi Pang, and Richard E. Stone.


The Linear Complementarity Problem. Academic Press,
1992.

[Cra89] John J. Craig. Introduction to Robotics, Mechanics and Con-


trol. Addison-Wesley, 1989.

[CYND92] Michel Carignan, Yang Ying, Magnenat T. Nadia, and Thal-


mann Daniel. Dressing animated synthetic actors with com-
plex deformable clothes. Computer Graphics (Proceedings
SIG GRA PH), 26:99-104, 1992.

[dBvKOS97] Mark de Berg, Marc van Kreveld, Mark Overmars, and


O. Schwartskopf. Computational Geometry: Algorithms and
Applications. Springer-Verlag, 1997.

[DER86] 1. S. Duff, A. M. Erisman, and J. K. Reid. Direct Methods


for Sparse Matrices. Oxford University Press, 1986.

[DJAK87] Terzopoulos Demetri, Platt John, Barr Alan, and Fleischer


Kurt. Elastically deformable models. Computer Graphics
(Proceedings SIGGRAPH), 21:205-214, 1987.

[Ede87] Herbert Edelsbrunner. Algorithms in Combinatorial Geome-


try. Springer-Verlag, 1987.

[Fea83] R. Featherstone. The calculation of robot dynamics using


articulated-body inertias. International Journal of Robotics
Research, 2:13-30, 1983.

[Fea87] R. Featherstone, editor. Robot Dynamics Algorithms.


Kluwer, 1987.

[FM96] Nick Foster and Dimitris Metaxas. Realistic animation of


liquids. Proceedings Graphics Interface, pages 204-212, 1996.
370 References

[FM97] Nick Foster and Dimitris Metaxas. Modeling the motion of


a hot, turbulent gas. Computer Gmphics (Proceedings SIG-
GRAPH), 31:181-188, 1997.

[FS96] Daan Frenkel and Berend Smit. Understanding Molecular


Simulation from Algorithms to Applications. Academic Press,
1996.

[FvDFH96] James D. Foley, Andries van Dam, Steven K. Feiner, and


John F. Hughes. Computer Gmphics Principles and Pmctice.
Addison-Wesley, 1996.

[GJK88] Elmer G. Gilbert, Daniel W. Johnson, and S. Sathiya Keerthi.


A fast procedure for computing the distance between complex
objects in three-dimensional space. IEEE Journal of Robotics
and Automation, 4(2):193-203, 1988.

[GL96] Gene H. Golub and Charles F. Van Loan. Matrix Computa-


tions. The Johns Hopkins University Press, Baltimore, 1996.

[Gla90] Andrew Glassner. Useful 3D geometry. Gmphics Gems,


1:297-300, 1990.

[Gla94] Georg Glaeser. Fast Algorithms for 3D-Gmphics. Springer-


Verlag, 1994.

[GLM96] S. Gottschalk, M. C. Lin, and D. Manocha. Obbtree: A hier-


archical structure for rapid interference detection. Computer
Gmphics (Proceedings SIGGRAPH), 30:171-180,1996.

[GM78] Philip E. Gill and Walter Murray. Numerically stable meth-


ods for quadratic programming. Journal of Mathematical
Progmmming, 14:349-372, 1978.

[GMSW87] Philip E. Gill, Walter Murray, Michael A. Saunders, and Mar-


garet H. Wright. Maintaining lu factors of a general sparse
matrix. Linear Algebm and Its Applications, 88/89:239-270,
1987.

[GoI50] Herbert Goldstein. Classical Mechanics. Addison-Wesley,


1950.

[Got96) S. Gottschalk. The separating axis test. Technical Report


TR-96-24, University of North Carolina, Chapel Hill, 1996.

[GR80) I. S. Gradshteyn and I. M. Ryzhik. Table of Integmls, Series


and Products. AP Academic Press, 1980.
References 371

[Hah88] James K. Hahn. Realistic animation of rigid bodies. Com-


puter Graphic!) (Proceeding!) SIGGRAPH), pages 299-308,
1988.
[HecOOa] Chris Hecker. How to simulate a ponytail, part 1. Game
Developer Magazine, pages 34-42, March 2000.
[HecOOb] Chris Hecker. How to simulate a ponytail, part 2. Game
Developer Magazine, pages 42-53, April 2000.

[He197] Martin Held. ERIT: A collection of efficient and reliable in-


tersection tests. Journal of Graphic!) Tools, 2(4):25-44, 1997.

[HFK94] John C. Hart, George K. Francis, and Louis H. Kauffman. Vi-


sualizing quaternion rotation. ACM Transactions on Graph-
ics, 13(3):256-276, July 1994.

[HJ91] Roger A. Horn and Charles R. Johnson. Matrix Analysis.


Cambridge University Press, 1991.

[HM99] John F. Hughes and Tomas Moller. Building an orthonormal


basis from a unit vector. Journal of Graphics Tools,4(4):33-
35, 1999.
[Hub96] Philip M. Hubbard. Approximating polyhedra with spheres
for time-critical collision detection. ACM Transaction on
Graphics, 15(3):179-210, July 1996.
[Joe86] Barry Joe. Delaunay triangular meshes in convex polygons.
SIAM Journal of Scientific and Statistic Computing, 7:514-
539, 1986.
[Joe91] Barry Joe. Delaunay versus max-min solid angle triangula-
tions for three-dimensional mesh generation. International
Journal for Numerical Methods in Engineering, 31:987-997,
1991.
[Joe94] Barry Joe. Tetrahedral mesh generation in polyhedral regions
based on convex polyhedron decompositions. International
Journal for Numerical Methods in Engineering, 37:693-713,
1994.
[JS86] Barry Joe and R. B. Simpson. Triangular meshes for regions
of complicated shape. International Journal for Numerical
Methods in Engineering, 23:751-778, 1986.
[Kei96] Mark Keil. Handbook of Computational Geometry, chapter
entitled Polygon Decomposition. Elsevier Science Publishing,
1996.
372 References

[KeI86] J. B. Keller. Impact with friction. Transactions of the ASME


Journal of Applied Mechanics, 53:1-4, 1986.

[KPTB99] Evaggelia-Aggeliki Karabassi, Georgios Papaioannou, Theo-


haris Theoharis, and Alexander Boehm. Intersection test for
collision detection in particle systems. Journal of Gmphics
Tools, 4(1):25-37, 1999.

[KSK97] Katsuaki Kawachi, Hiromasa Suzuki, and Fumihiko Kimura.


Simulation of rigid body motion with impulsive friction force.
Proceedings IEEE International Symposium on Assembly and
Task Planning, pages 182-187, 1997.

[LH74] C.L. Lawson and R. J. Hanson. Solving Least Squares Prob-


lems. Prentice-Hall, 1974.

[LK84] Sheue-Ling Lien and James T. Kajiya. A symbolic method


for calculating the integral properties of arbitrary noncon-
vex plyhedra. IEEE Computer Gmphics and Applications,
4(10):34-41, October 1984.
[Lot84] Per Lotstedt. Numerical simulation of time-dependent con-
tact friction problems in rigid-body mechanics. SIAM Jour-
nal of Scientific Statistical Computing, 5(2):370-393, June
1984.
[LR82a] Yong Tsui Lee and Aristides A. G. Requicha. Algorithms for
computing the volume and other integral properties of solids:
Known methods and open issues. Communications of the
ACM, 25(9):635-641, September 1982.
[LR82b] Yong Tsui Lee and Aristides A. G. Requicha. Algorithms for
computing the volume and other integral properties of solids:
A family of algorithms based on representation conversion
and cellular approximation. Communications of the ACM,
25(9):642-650, September 1982.
[Mir96a] Brian V. Mirtich. Fast and accurate computation of polyhe-
dral mass properties. Journal of Gmphics Tools, 1(2):31-50,
1996.
[Mir96b] Brian V. Mirtich. Impulse-based Dynamic Simulation of
Rigid Body Systems. PhD thesis, University of California,
Berkeley, 1996.
[Mir97] Brian Mirtich. V-clip: Fast and robust polyhedral collision
detection. Technical Report TR-97-05, MERL: A Mitsubishi
Electric Research Laboratory, 1997.
References 373

[Mir98] Brian Mirtich. Rigid body contact: Collision detection to


force computation. Technical Report TR-98-01, MERL: A
Mitsubishi Electric Research Laboratory, 1998.
[MoI97] Tomas Moller. A fast triangle-triangle intersection test.
Journal of Graphics Tools, 2(2):25-30, 1997.
[OG97] C. J. Ong and Elmer G. Gilbert. The gilbert-johnson-keerthi
distance algorithm: A fast version for incremental motions.
Proceedings IEEE International Conference on Robotics and
Automation, pages 1183-1189, 1997.
[O'R98] Joseph O'Rourke. Computational Geometry in C. Cambridge
University Press, 1998.
[Piq90] Michael E. Pique. Rotation tools. Graphics Gems, 1:465-469,
1990.
[Pro95] Xavier Provot. Deformation constraints in a mass-spring
model to describe rigid cloth behavior. Proceeedings Graphics
Interface, pages 147-155, 1995.
[Pro97] Xavier Provot. Collision and self-collision handling in cloth
model dedicated to design garment:;;. Proceedings Graphics
Interface, pages 177-189, 1997.
[PS85] Franco P. Preparata and Michael Ian Shamos. Computational
Geometry: An Introduction. Springer-Verlag, 1985.
[PTVF96] William H. Press, Saul A. Teukolsky, William T. Vetterling,
and Brian P. Flannery. Numerical Recipes in C: The Art of
SCientific Computing. Cambridge University Press, 1996.
[Ree83] William T. Reeves. Particle systems: A technique for model-
ing a class of fuzzy objects. Computer Graphics (Proceedings
SIG GRA PH), 17:359-376, 1983.
[Rit90] Jack Ritter. An efficient bounding sphere. Graphics Gems,
1:301-303, 1990.
[RJKD92] G. Rodriguez, A. Jain, and K. Kreutz-Delgado. Spatialoper-
ator algebra for multibody system dynamics. Journal of the
Astronautical Sciences, 40:27-50, 1992.
[Sam89] H. Samet. Spatial Data Structures: Quadtree, Octrees and
Other Hierarchical Methods. Addison-Wesley, 1989.
[SF95] Jos Starn and Eugene Fiume. Depicting fire and other
gaseous phenomena using diffusion processes. Computer
Graphics (Proceedings SIGGRAPIl), 29:129-136, 1995.
374 References

[Sha94] Ahmed A. Shabana. Computational Dynamics. John Wiley


& Sons, 1994.
[Sha98] Ahmed A. Shabana. Dynamics of Multibody Systems. Cam-
bridge University Press, 1998.
[Sho85] K. Shoemake. Animating rotation with quaternion curves.
Computer Graphics (Proceedings SIGGRAPH), 19:245-254,
1985.
[Ski97] Steven Skiena. The Algorithm Design Manual. Springer-
Verlag, 1997.
[Sta99] Joe Starn. Stable fluids. Computer Graphics (Proceedings
SIGGRAPH), 33:121-127, 1999.

[Str91] Gilbert Strang. Linear Algebra and its Applications. Acad-


emic Press, 1991.
[SV94] P. W. Sharp and J. H. Verner. Completely imbedded runge-
kutta pairs. SIAM Journal on Numerical Analysis, 31:1169-
1190, 1994.
[Ter87] Demetri Terzopoulos. Elastically deformable models. Com-
puter Graphics (Proceedings SIGGRAPH), 21:205-213, 1987.

[TW98] Grit Thurmer and Charles A. Wuthrich. Computing vertex


normals from polygonal facets. Journal of Graphics Tools,
3(1}:43-46, 1998.
[vdB97] Gino van den Bergen. Efficient collision detection of complex
deformable models using aabb trees. Journal of Graphics
Tools, 2(4}:1-13, 1997.
[vdB99] Gino van den Bergen. A fast robust gjk implementation
for collision detection of convex bodies. Journal of Graph-
ics Tools, 4(2}:7-25, 1999.

[Wil99] Mark L. Wilkins. Computer Simulation of Dynamic Phenom-


ena. Springer Verlag, 1999.
Index

Articulated rigid-body systems computing the collision and


dynamic equations, 247 contact frame, 270
introduction, 245 for articulated rigid bodies,
single or multiple external col- 253
lisons, 258 for particle-particle collisions,
single or multiple external con- 78
tacts, 260 for particle-rigid body colli-
state vector representation, 247 sions,81
Axis-Aligned Bounding Boxes (AABB), Gilbert-Johnson-Keerthi (GJK)
20-21 algorithm, 195
overview, 11
Bisection method, 78, 169
using hierarchical representa-
Bounding Spheres, 25-27
tions, 17
Voronoi Clip algorithm, 174
Closest point between a line and
a line segment, 268 Collision response
Cloth simulation articulated rigid bodies, 256
overview, 146 for a particle-rigid body col-
Collision and contact-frame com- lision, 136
putation, 270 for a particle-rigid body con-
Collision detection tact, 137, 238
between convex rigid bodies, for a single particle-particle
174 collision, 107
between non-convex rigid bod- for a single particle-particle
ies, 172 contact, 120
376 Index

for a single rigid body-rigid Covariance matrix, 23, 25


body collision, 205 Critical coefficient of friction, 113,
for a single rigid body-rigid 212
body contact, 225 Cross-product
for articulated rigid-body col- matrix-vector representation,
lisions, 258 271
for articulated rigid-body con-
tacts, 260 Damped springs
for multiple particle-particle connecting particles, 70
collisions, 115 connecting rigid bodies, 167
for multiple particle-particle Divergence theorem, 303
contacts, 129 Dynamic simulation
for multiple rigid body-rigid overview, 3
body collisions, 218
for multiple rigid body-rigid Euler method
body contacts, 234 explicit, 276
for particle-particle collisions, implicit, 278
106
overview, 12 Force fields
partitioned-matrix represen- constrained, 71
tation, 114, 118,217,222 unconstrained, 73
Constrained force fields
applied to particles, 71 Gilbert-Johnson-Keerthi (GJK) al-
Contact force computation gorithm, 195
contact with friction, 348 Gravitational force
for a particle-rigid body con- applied to particles, 69
tact, 137, 238 applied to rigid bodies, 165
for a single particle-particle Green's theorem, 308
contact, 120
for a single rigid body-rigid Hierarchical representations
body contact, 225 Axis-Aligned Bounding Boxes
for articulated rigid-body con- (AABB),20
tacts, 260 Bounding Spheres (BS), 25
for multiple particle-particle convex hull, 27
contacts, 129 detecting collisions between
for multiple rigid body-rigid different types of, 42
body contacts, 234 different types of, 19
frictionless contact, 339 multi-level grid, 37
Convex decomposition of the simulated world, 32
finding cut planes, 329 Oriented Bounding Boxes (OBB),
introduction, 325 22
Joe's algorithm, 327 overview, 17
termination conditions, 334 uniform grid, 33
tracing cut faces, 331
Convex hull, 27-31 Impulsive-force computation
Index 377

for a particle-rigid body col- volume to surface integral re-


lision, 136 duction, 303
for a single particle-particle Matrix representation
collision, 107 of a single particle-particle col-
for articulated rigid-body col- lision, 114
lisions, 258 of a single rigid body-rigid
for multiple particle-particle body collision, 217
collisions, 115 of multiple particle-particle col-
for multiple rigid body-rigid lisions, 118
body collisions, 218 of multiple rigid body-rigid
partitioned-matrix represen- body collisions, 222
tation, 114, 118,217,222 Mean vector, 23, 24
single rigid body-rigid body Multilevel-grid decomposition, 37-
collision, 205 41
Intersection
box-box, 42 Numerical integration
box-sphere, 51 overview, 10
box-triangle, 52
cylinder-box, 90 Ordinary differential equations
cylinder-cylinder, 87 Euler method, 276
cylinder-sphere, 94 introduction, 273
cylinder-triangle, 97 Runge-Kutta method, 280
plane-line segment, 267 step-doubling technique, 286
point-in-cylinder test, 105 using adaptive time steps, 285
point-in-triangle test, 49 Oriented Bounding Boxes (OBB),
22-25
sphere-line segment, 54
sphere-sphere, 45
Parallel-axis theorem, 302
sphere-triangle, 53
Particle systems
triangle-line segment, 55
collision detection overview,
triangle-triangle, 46
76
detecting particle-particle col-
Linear complementarity, 125,230 lisions, 78
Baraff's algorithm, 348 detecting particle-rigid body
Dantzig's algorithm, 339 collisions, 81
introduction, 337 dynamic equations, 63
interaction forces, 68
Mass properties introduction, 61
computing line integrals, 309 multiple particle-particle col-
Mirtich's algorithm, 300 lisions, 115
of rigid bodies, 299 multiple particle-particle con-
projected surface to line in- tacts, 129
tegral reduction, 308 overview of cloth simulation,
surface to projected surface 146
integral reduction, 304 particle emitter, 138
378 Index

particle-particle collision re- dynamic equations, 156


sponse, 106 interaction forces, 165
particle-rigid body collision, introduction, 155
136 mass properties, 299
particle-rigid body contact, 137 multiple rigid body-rigid body
simulation overview, 65-68 collisions, 218
single particle-particle colli- multiple rigid body-rigid body
sion, 107 contacts, 234
single particle-particle contact, particle-rigid body contact, 238
120 simulation overview, 161-165
state-vector representation, 64 single rigid body-rigid body
user-adjustable parameters, 143 collision, 205
user-definable parameters, 140 single rigid body-rigid body
user-interaction force, 76 contact, 225
using damped springs with, state-vector representation, 160
70 user-interaction force, 167
using gravity with, 69 using damped springs with,
using spatially dependent forces 167
with,71 using gravity with, 165
using viscous drag with, 69 using viscous drag with, 166
Projections Rotation-matrix representation, 293
point on line, 266 time derivative, 318
point on plane, 266 Runge-Kutta method
fourth order, 283
Quaternions second order, 280
addition, 290
advantages over rotation ma- Separating axis
trices, 295 computing for AABB, 43
conjugate, 291 computing for OBB, 44
dot product, 290 Separating-axis theorem, 42
introduction, 289 Simulation engines
inverse, 292 collision detection, 11
module, 292 collision response, 12
multiplication, 290 design principles, 7
representing rotations, 293 interfacing with renderer, 7
time derivative, 320 introduction, 3
unit quaternions, 292 numerical integration, 10
software implementation, 16,
Rigid-body systems 365,366
collision detection, 168, 253 Software packages, 365
collision response, 256 Spherical joints, 246
collison between convex bod- Step doubling, 286
ies, 174
collison between non-convex Time derivative
bodies, 172 of a rotation matrix, 318
Index 379

of a unit quaternion, 320


of a vector attached to a rigid
body, 313
of contact normal vector of
particle-particle contact,
314
of contact normal vector of
rigid body-rigid body con-
tact, 315
of tangent plane of a collision
or contact, 317

Unconstrained force fields


applied to particles, 73
Uniform-grid decomposition, 33-
36
User interaction
with particles, 76
with rigid bodies, 167

Viscous drag
applied to particles, 69
applied to rigid bodies, 166
Voronoi Clip algorithm, 174

You might also like