Murilo G. Coutinho (Auth.) - Dynamic Simulations of Multibody Systems-Springer-Verlag New York (2001)
Murilo G. Coutinho (Auth.) - Dynamic Simulations of Multibody Systems-Springer-Verlag New York (2001)
Murilo G. Coutinho (Auth.) - Dynamic Simulations of Multibody Systems-Springer-Verlag New York (2001)
of
Multibody Systems
Springer Science+Business Media, LLC
Murilo G. Coutinho
Dynamic Simulations
of
Multibody Systems
i Springer
Murilo G. Coutinho
1745 Selby Avenue, #11
Los Angeles, CA 90024
USA
[email protected]
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.
987654 32 1
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
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
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
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
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 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
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. 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
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.
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.
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
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.
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.
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.
2The computation of the convex hull of a vertex set is described in Section 2.2.4.
2.2 Hierarchical Representation of Objects 25
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
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)
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.
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).
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
Having the first face, we proceed as explained and compute all other
convex hull faces of the polyhedron.
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.
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.
....
"
.... ....
.... ,,!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 .... ..-~
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
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).
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)
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
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 ·
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
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)
4=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.15. The cells at level 2 that intersect the object's bounding sphere.
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.
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.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
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.
(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
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.
(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)
CA~-------r-------+----~
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
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
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
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.
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
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.
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.
(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
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
(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
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
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.
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.
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
iJ(t) = djJ(t) .
dt
Its acceleration is then given by
_ ( jJ(t) )
y(t) = L(t) .
aY(t)
= (3.5)
dt
3.2 Particle Dynamics 65
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.
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
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.
)i?f
l
__
...... --~
_
-
Vt
F; =-kA
~ --
--_..... F: -
_
V3
3 -kd v3
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.
(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
(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.
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
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.
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
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.
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
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 <
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
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.
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.
Final
position
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.
(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.
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
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
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.
The top and bottom limiting planes of the cylinder are perpendicular to
Uh, passing through points h2 and hb respectively. Their equations are
"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
where fit is the plane normal (i.e., the triangle normal.) and "Yt is the plane
constant given by
"Yt = VI . fit .
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
I
H I
I
I
I Intersection
I region
. . -_--1--_
I
~ t -,
(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
(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
(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.
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
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.
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)
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
(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
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).
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
and they will lie below the bottom limiting plane of the cylinder if
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.
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
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
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
(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:
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.
Let d ij be the distance from edge Cr, J) to the cylinder's axis. If the
distance from all edges is such that
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.26)
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.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.
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:
(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
J-Ld COS¢
J-Ld sin ¢
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
(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.
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
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
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
~ 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.
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)
5The local-coordinate frame is defined by the collision normal and tangent plane.
3.6 Particle-Particle Collision Response 117
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.
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.
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
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
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.,)
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
[
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.
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)
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)
(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.
or equivalently
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:
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
((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 = 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
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 .~ .
(a11)n 0
(al2)t = 0
(3.83)
(aI3)k 0
+ 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)
(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)
an(t c) > 0
Fn > 0
Ft(AF+b) 0,
130 3. Particle Systems
Cluster Gt
Cluster Gz Cluster G3
where 10
F (Fn' Fb Fd
b ((bdn' (b1)t, (b1)k)t
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
and the matrix A is enlarged to accommodate all contact forces. Its parti-
tioned representation 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)
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
_ 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
(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
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 ·
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).
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.
doing, the reader will have a chance to assimilate the concepts of rigid-body
dynamics necessary to understand the contact-force computations.
(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.
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.
o 0 0
0 00
0000
00 0
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
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.
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.
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
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
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
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
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-
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).
(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.
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
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)
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
where L(t) is the linear momentum of the rigid body computed from
( 4.15)
The time derivative of the inverse of the inertia tensor is then
because (~;t(t) = -w(t). Using equation (4.1) again, we can simplify the
above expression to
rl(t) rl(t)
~ ____ ~A A
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
dY(t)
dt
(4.20)
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.
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.1 Gravity
The force contribution of gravity acting on each rigid body owing to its
attraction to the ground is directly obtained from
FIGURE 4.5. Gravity pulling rigid body Bl with mass ml towards the ground
plane.
F= -kvv,
where v is the linear velocity of the rigid body's center of mass and kv is
the linear drag coefficient.
where wis the angular velocity of the rigid body and kw is the angular drag
coefficient.
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)
(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.
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
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
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.
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
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.
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
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
(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
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.
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)
(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.
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 .
(4.28)
182 4. Rigid-Body Systems
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.
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.
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.
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
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
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.
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.
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).
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
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.
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
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.
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
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.
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.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
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
(see Figure 4.27). However, if the minimum lies on the interval [ih,P4], that
is
• 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.
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.
(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
(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
(4.39)
max{p· xl x E B} .
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
with
n
LAj 1
j=1
Aj > O,Vj E {1,2, ... ,n}.
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
(a) (b)
(c)
FIGURE 4.31. Visualizing a few steps of the GJK algorithm being executed.
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
P= L AjXj,
JEIs
with
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
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
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
~
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)!
Pi+1 = L Aj Xj .
JEI.
(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
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
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.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.
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 angular momentum for each rigid
body along the three axes defining the collision frame, we obtain another
set of six equations:
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
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
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
ltd Pn ,
that needs to be enforced when the rigid bodies are not sliding at the
collision point can be substituted for two linear equations
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
(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
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)
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
where
m= (_1 +~) .
m1 m2
(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
(4.80)
that is
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
that is
gi'
, " "
Pn «A1 )n x rl + (A2)n x f2) . r
~ ______
g~'
~A~ ______ ~
«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
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
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.
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.
15The local-coordinate frame is defined by the collision normal and tangent plane.
220 4. Rigid-Body Systems
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.
~~
~ 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
P12, d-;',2
V1 m1 V1
01 11 W1
V2 m2V2 (4.86)
O2 12 w2
P23, d-;,3
V3 m3 V3
03 Isw3
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
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..
(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.
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
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
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)
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)
(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:
an(tc) > 0
Fn > 0 (4.94)
Fn an(t c) O.
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:
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
((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
(4.103)
(4.104)
dfi(tc)
dt
df(t c)
dt
4.8 Rigid Body-Rigid Body Collision Response 231
~
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 (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
where
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)
ax b -b x a
axb ab
and letting
~
apt
( ml
1 I -
- I 1 -1 Xl
Xl
- ) F~
(4.113)
with
(4.114)
(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 •
> 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
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
and the matrix A is enlarged to accommodate all contact forces. Its parti-
tioned representation is given by
(ai(j+l) )ti
(a(i+l)(j+l) )ti
(a(i+2)(j+l»)ti
(4.117)
4.8 Rigid Body-Rigid Body Collision Response 237
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
Using the fact that the contact force Fj is expressed with respect to the
contact frame Cj as
with
(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.
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.
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
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
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.
(4.120)
(4.121)
(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)
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
_ _ _ (_ _)) 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.
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.
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).
(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
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
-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 )
that is
5.2 Articulated Rigid-Body Dynamics 251
(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.
(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
Doing the same for all other joints, we can group the eight joint equations
into the following linear system:
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.
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 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.
(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
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
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).
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
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
d = Ip- ill·
(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
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.9)
where 0 :::; kp :::; 1 is a scalar to be determined. Alternatively, we can rewrite
equation (A.9) as
(A.lO)
FIGURE A.3. Computing the closest point between a line and a line segment.
(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
d~ = 1c - qi 12 + 1c - P1 12 ,
d~ 1c - q1 12 + 1ii - cl 2 .
( 2l 2)
1C- - PI- 1- 1a- - c-I = d d- d 2
3
. (A.15)
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.
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
( )
0 -a z ay
a= az 0 -ax (A.19)
-a y ax 0
(A.20)
(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).
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 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
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
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.
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
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
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
dY(ti + h) __ (~ )t y~(.
dt - Cy t, + h) ,
where
(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).
k1 hfy(t i , Y) , (B.12)
k2 h - k1
+ "2' y + 2) ,
h Jy (ti (B.13)
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)
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
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)
&
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 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:
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)
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)
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
(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.
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.
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.
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.1 Addition
The addition of two quaternions is similar to the addition of two complex
numbers, and is given by
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).
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.
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
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
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)
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.8)
294 Appendix C. Quaternions
cos () = 2 82 - 1
(C.9)
sin()=28~
and
il
u= ---;:==
J1- 8 2 •
(C.lO)
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
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-;'.
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).
the rotation matrix representation, and still get a smooth transition (Le.,
one without jerkiness) between the orientations as the scene is animated.
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
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 {
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
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
(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
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 .
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.
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 !
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
( g(a,{3,-y) dA =
.If
_111
n"l
J,
fv
g(a,{3,h(a,{3)) da d{J, (D.l2)
1
h(a, (3) = --(nc.t a + n,e (3 + d) . (D.13)
n"l
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).
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)
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
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.
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).
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
11
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
11
e=1 0
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.
{1
J"
o
a"(L,A)!l" (L,A) dA ~ f- E E (~).(
P ~
(' + J)
q
pq i=O j=O P q
)
( ~) 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).
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
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.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
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 •
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
(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
(E.8)
(E.9)
(E. 10)
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
(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)
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
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)
d f (d ii)
dt = dt / Idt
d ii I
'
where:
318 Appendix E. Useful Time Derivatives
dii =
dt
(0' _dnz(t)
dt'dt
dny(t))
2. If ii = (-n z , 0, n x ), then
Po = R(t) PI .
1In the rigid-body case, the coordinate frame:F1 is the body frame.
E.5 Computing the Time Derivative of a Rotation Matrix 319
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
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
w(t) = ( ~z
-Wy
+ 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)
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
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).
· ( 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)
+ v Y2 + v z2 + 8 2
V x2 1 (E.32)
Vx Vx + Vy Vy + Vz Vz + S 8 O. (E.33)
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
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· 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
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
(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.
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.
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.
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.
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.
(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).
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
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.
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.
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.
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
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)
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
(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.
Ai ((aii)n)
b ((bi)n) ,
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,
(a,). < 0
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).
(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.
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
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)
(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)
(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
Fnew F + (s 6F) ,
anew = a + (s 6a) .
where J1,t and J1,k are the coefficients of friction along the tangent-plane
directions t and k.
(G.17)
In equation (G.17), the term (Fi)tk refers to the net contact-force com-
ponent on the tangent plane given by
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
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
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
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
(G.22)
If on the other hand the relative tangential acceleration is not zero, then
the tangent components of the contact force will have maximum magnitude
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)
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
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:
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:
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)
~(ai)k 0, Vi E ZAk
~(Fm)n = 1.
The components ~(Fm)t and ~(Fm)k are set according to the following 5 :
...............
1
• 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
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)
8=0 (G.38)
(G.39)
(GAO)
8=0 (GAl)
G.3 Baraff's Algorithm: Coping with Friction 359
(G.43)
• If i = m, then,
~~-~
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
Figure G.5 illustrates the possible state transitions between group in-
dexes.
(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)
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.
°
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.
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
Preferably, the internal data structures for vertices, edges and faces
should be redundant to carry out the above operations in constant
time.
Viscous drag
applied to particles, 69
applied to rigid bodies, 166
Voronoi Clip algorithm, 174