Collision Detection and Response For Computer Animation
Collision Detection and Response For Computer Animation
289
SIGGRAPH '88, Atlanta, August 1-5, 1988
2.1. Collision Detection for Flexible Surfaces f = (P2y- Coy) + t(V2y- roy)
Surfaces are modeled as a grid of points connected to g =-Vy
form triangles.[19] Collisions between surfaces axe detected h =ey - ( e o y +tVoy)
by testing for penetration of each vertex point through the
i = (P l , - P a x ) + t ( V l , - Vo,)
planes of any triangle not including that vertex (thus, self-
intersection of surfaces is detected). The surfaces are assumed J = ( P ~ - Po,) + t ( V ~ - Vo,)
to be initially separate. For each time step of animation, the k =-V z
positions of points at the beginning and the end of the time t = P , -(P0= +tVoD
step must be compared to see if any point went through a tri-
angle during that time step. If so, a collision has occurred. The Pw s and Vws are the position and velocity components of
The algorithm is O (nm) for n triangles and m points. the point, and the Piw S and Viw s are the position and velocity
components of the triangle vertices. The velocities are per
A correct test must consider edges and triangles, as po-
lyhedral objects can collide edge-on without any vertices be- time step.
ing directly involved. However, in many cases merely testing The linear system above can be solved for t and expand-
points versus triangles produces acceptable results. This algo- edto
rithm only tests points versus triangles. It is worth noting that 0 = a U a - / b ) ( h a - c a ) - a (da-ib)(ga --cc ) t
the mathematics for testing intersection of a moving point + (fa -eb )(ka-ic ) t - (la-id)ffa--eb)
with a fixed triangle is the same as for testing a fixed edge
Substitution of the actual expressions for a through l gives a
versus a fixed triangle. Thus the fully general edge versus tri-
5'th order polynomial in t. If further substitutions were made,
angle tests could be done at fixed instants in time, with the
the equations could be written in the form
same advantages and disadvantages that will be discussed for
the second collision detection algorithm. C 5t5 .l- c 4t4 -1-c 3t3 -I-c2t2-I-Cl tl -I- Co= O
The question of whether a moving point has intersected a Polynomials of order 5 and above cannot be solved
surface can be divided into two cases. The easy ease requires analytically,[10] so a binary search technique is used to find
the surface to be fixed in space, whereas the hard case allows approximate values for t.[5] Binary search is used because it
the surface to be moving also. When the surface triangle is is guaranteed to converge, and because, using economizing
fixed, the parametric vector equation techniques described below, this algorithm is not used often
enough to warrant large efforts at optimization. The interval
P + (P" - P ) t = Po + (Pi-Po) u + (P2---Po) v
from t=0 to t=l is subdivided into a number of sub-intervals,
where P and U a.re the beginning and ending positions of the and the left-hand side is evaluated at each dividing point. If
point and the Pi's define the triangle, is set up and solved for the sign of that value is different for the two endpoints of
the variables u,v,t, u and v are parametric variables for the some subinterval, then some t for which the equation is true
plane defined by the triangle, whereas t is a time variable must lie within that interval. A binary search of values of t
which is 0 at the beginning of the simulation step in question, within that interval brings the brackets around that value of t
and 1 at the end. The left hand side is the parametric equation closer together, until a limit is reached (after 10 iterations, in
for the path of the point, and the right hand side is the our system) and an approximate value of t is found. Each
parametric equation for any point o n the plane. This vector value of t thus arrived at is used to get values for u and v by
equation represents three scalar equations in three unknowns back substitution, and then the standard 0<_t<_l and u~0 and
and is solved by matrix inversion. If 0,St_<l and u:20 and v:20 v~0 and u + v ~ l test is used to determine whether a collision
and u+v_<l, then the point has intersected the triangle during has occurred.
290
~)' Computer Graphics, Volume 22, Number 4, August 1988
To minimize the cost of executing the above calcula- Figure 1 illustrates a two-dimensional version o f this pro-
tions, a preliminary step is used. Every point is compared to cedure. The points A through 1 were inserted into an initially
every triangle. The perpendicular distance of the point from empty quadtree in alphabetical order, so that A is the root ele-
the plane defined by the triangle is first derived, by substitut- ment of the tree. The tree is to be searched for all points inside
ing into the plane equation,[25] for the beginning and the end the dotted box. A is inside, so all of it's subtrees must be
of the time step. If the sign of the perpendicular distance has searched. B is above and to the right of the dotted box, so only
not changed intersection is assumed not to have occurred. If its lower left subtree must be searched. This finds C, which is
the sign has changed, then the more expensive tests outlined inside the box. If C had subtrees, they would all have to be
above must be done, but in practice this test eliminates most searched. The next subtree of A starts with F. F is above the
point-triangle pairs. bounding box, so both of its lower subtrees must be searched.
A special kind of bounding box can also be used to One is empty, and the other contains only I, which is also out-
minimize computation. This bounding box includes the be- side the box. A ' s third subtree contains only E, which is below
ginning and ending position o f the triangle. This box is then the box. If E had subtrees, only the upper ones would need to
grown by the distance between the beginning and ending posi- be searched. A ' s fourth and last subtree contains only G,
tions of the point being tested. (This is necessary to avoid the which is outside the box. If G had subtrees, only the two fight
point passing unnoticed completely through the box during the hand ones would be searched. A large, bushy quadtree would
time step. A similar growth technique is used in the Lozano- be very fast to search (if the dotted box were small relative to
Perez path planning algorithm.)[15] the area covered by the tree) because the unsearched subtrees
would often contain large numbers o f points.
The basic algorithm is O (nm), for n triangles and m
points. Use of an octree[19] and bounding boxes can reduce
2.2. Collision Detection for Convex P o l y h e d r a
the time to O (mlogm) to construct the octree, and O (n logm) to
search it (assuming that the tree is almost balanced and that The detection of collisions between solids (or closed sur-
the bounding boxes are small compared to the space covered faces) can be treated somewhat differently, for the objects
by the tree). have a distinguishable inside and outside. The problem is
somewhat more complex than might be initially thought.
The search finds all point - bounding box pairs that must Edges as well as vertex points may be involved in collisions.
be examined more closely for possible intersection. All of the This method for detecting collisions is based on the
points in the model are inserted into an octree, which is creat- Cyrus - Beck clipping algorithm.[25] Collisions of articulated
ed anew for each round of collision detection. This octree is objects can be detected by applying this algorithm to all pairs
based on the points themselves, with each point P having up of the polyhedra making up the two objects. The two polyhe-
to 8 subtrees containing points in each of the octants of space dra are assumed to be convex; concave polyhedra can be
defined by the P's position. This is an obvious generalization decomposed into collections of convex ones. The basic algo-
of the well known binary search tree.[13, 14] A pseudo- rithm is O(n2m 2) for n polyhedra and m vertices per po-
random number generator is used to scramble the order of lyhedron. Methods for reducing these exponents are discussed
insertion; in this way, Knuth assures us, J13] the tree will be al- below.
most balanced, i.e. the height of the octree will be O (logm) al-
most always. The two-dimensional Cyrus - Beck algorithm[25] tells
whether a point is inside a convex polygon. It takes the dot
Each triangle's bounding box is grown by the distance product of each side's outward normal vector (n) with a vector
between the starting and ending positions of the fastest point from some point (v) on the side to the point in question (p). If
being tested. Each bounding box is then recursively compared
that dot product is negative for all edges of the polygon, then
against the octree to find the points inside it. If a point is in- the point is inside; if not, it is outside (see Figure 2).
side the box, all of its subtrees must be searched recursively. If
a point is outside the box, at least half of its subtrees do not
need to be searched. If a point is found to be inside a box, then dot pro.duct
the algorithm above must be run to determine if the point in- negative,
tersected the associated triangle during the time step.
~ p
r. . . . . . . . . . . . . . . . . D n l
'
Figure 2
Cyrus - Beck Clipping
Figure 1
Searching a Quadtree
291
¢ SIGGRAPH '88, Atlanta, August 1-5, 1988
The collision detection algorithm is developed as a This will result in a collection of intersection points P ly-
three-dimensional analogy to Cyrus - Beck clipping. The al- ing along the edge. Intersection points with t < 0 or t > 1 do
gorithm works by testing whether representative points of one not lie on the actual edge and are discarded. The remaining in-
polyhedron are inside the other polyhedron. First points from tersections are sorted into order according to their t values,
polyhedron B are tested against polyhedron A, and then the forming a sequence of points from one vertex to the other
process is reversed and points from A are tested for inclusion along the edge. Each adjacent pair o f points in this sequence,
in B. These two steps combine to cover all special cases and including those made by the vertices and the first and last sub-
give a reliable answer. The algorithm given below terminates division points, defines a sub-segment of the edge. The mid-
when a single point o f interpenetration is found, which is point of each resulting line segment is checked for being in-
sufficient for collision detection. If collision response is also side A by the same method that was used for vertices, above.
required, the algorithm below should be modified to find all Again, if any of these midpoints is inside A the algorithm ter-
points of interpenetration. The rest of this section describes minates with a detected collision.
the test of points from B against A. The third step tests for the infrequent case where two
Let A consist of a set of planar polygonal faces (Pi). Each identical polyhedra are moving through each other with faces
polygon contains a set o f vertices (uii) and an outward point- perfectly aligned. Here, the centroid point of each face of B is
ing normal vector ni. Let B consist of a set of vertices (vD, a tested against A by the method used for vertices, above. If
set of edges (el), and a set of planar polygonal faces ffi). All any of these centroids is inside A the algorithm terminates
coordinates of B have been transformed into the reference with a detected collision.
frame of A. If the algorithm survives the above three steps without
The first step tests for the presence of vertices of B inside detecting a collision, and also does not detect one when rev-
of A. Each vertex of B is compared to every face of A ; if any ersing and comparing A against B, then the two polyhedra do
vertex is on the inward side of all such faces, it is inside A and not interpenetrate.
the algorithm terminates having detected a collision. For each The above algorithm can be speeded up by a variety of
vertex i of B and for each face j of A, form the dot product tricks. A bounding box or bounding sphere test can be applied
(vi-ujl) • nj. If this dot product is negative the vertex is on the to every pair of polyhedraa, yielding an immediate "no colli-
inward side of the face. sion" result in most cases. Many of these bounding box tests
The second step tests for penetration of the edges of B can even be eliminated by octree or voxel methods. [4,9]
through the faces of A. Each edge of B is divided into a When a point is to be tested against a polyhedron, it chn first
number o f smaller line segments by intersecting it with the be compared to the polyhedron's bounding box, which will
infinite planes corresponding to every face o f A . See Figure 3. probably eliminate the need to compare it against all of the
This subdivision is done as follows. Let some edge of B con- faces. The bounding box can be aligned with the coordinate
nect the vertices vi and vy, and let us compare it against some axes of the polyhedron's local frame to make this point elimi-
face of A that has an outward pointing normal n, and a vertex nation test particularly fast.
point u~l. First the perpendicular distance of each vertex from It should be noted that this algorithm, or indeed any algo-
the plane defining the face is calculated, by substitution into rithm which point samples the positions o f objects over time,
the plane equation.[25] If the perpendicular distances differ in could fail if one object moved entirely through another during
sign, then the edge intersects the plane, and the intersection a single time step. This is a rather unusual occurence in pro-
point P can be calculated. cedural or dynamic animation because simulation time steps
are normally small relative to the velocities of the objects. The
di = (vi - U k l ) " nk
correct solution to this problem is to generalize to four dimen-
a j = (vj - a k ~ ) ' n , sions;J3] the starting and ending positions of the polyhedra
td~t define 4-D hyper-polyhedra which are checked for interpene-
t-- tration by higher-dimensional analogues to the algorithm
mail + IdyE
given above. The more practical approach is either to ignore
P =v~ + t (vy -v~) the problem (as we do) or to restrict the animation step size so
that the change in any object's position in any step is small re-
lative to the object's size.
V2 3. C O L L I S I O N R E S P O N S E
In keyframed and procedural animation systems, colli-
sion detection is the main requirement; collision response usu-
ally consists of informing the animator or the motion control
program that a collision has occurred, and trusting them to
handle it. In animation systems using dynamics to generate
planes seen edge-on motion, the system itself must respond to a collision by deter-
mining new linear and angular velocities for the colliding ob-
jects. These new velocities must conserve linear and angular
momentum, or else the resulting "funny bounce" will be very
Figure 3 obvious to viewers of the animation. The elasticity of the sur-
faces must also be taken into account, as this determines how
Edge Subdivision
much kinetic energy is lost in the collision; no-one will be-
292
@ * ComputerGraphics,Volume22, Number4, August1988
lieve that a bean bag should bounce off of a hard surface as if This section develops the solution in stages. First, an
it were a golf ball. analytical solution for the collision of two rigid bodies is
presented; this result is due to MacMillan.[17] MacMillan's
3.1. Collision Response Using Springs solution is extended to tree-like articulated rigid objects with
revolute joints. Then, the restriction to wee-like objects is re-
The most intuitive way to handle collisions is with
moved, and finally the method is extended to encompass joints
springs. Dynamic simulation systems must already have a
with one or two sliding degrees of freedom.
method for applying external forces to objects. Thus, when a
collision is detected, a very stiff spring is temporarily inserted
between the points of closest approach (or deepest interpene-
3.2.1. Single Rigid Bodies
tration) of the two objects. The spring law is usually K / d , or MacMillan gives a general solution for the collision of
some other functional form that goes to infinity as the separa- two arbitrary rigid objects. Each object has a linear velocity
tion d of the two objects approaches 0 (or the interpenetration vector vi, an angular velocity vector toi, a mass m i, a center of
depth approaches some small value). K is a spring constant mass vector cl, and an inertial tensor matrix Ii which is rela-
controlling the stiffness o f the spring. The spring force is ap- tive to the center of mass. All of these quantities, for both ob-
plied equally and in opposite directions to the two colliding jects, are expressed in the same inertial reference frame. In
objects. The direction of the force is such as to push the two addition, each object has a vector Pi which points from its
objects apart (or to reduce their depth of interpenetration). center of mass to the collision point~ The solution also re-
quires three orthogonal unit vectors i ,j,k that define the "colli-
Our particular implementation handles variable elasticity sion frame", k will be perpendicular to the plane of collision
by making a distinction between collisions where the objects and i and j will be in that plane. The definition of the plane of
are approaching each other and collisions where the objects collision is somewhat arbitrary; for convenience we will
are receding from each other. For e = 1, i.e. perfectly elastic define it as follows. If a vertex of one object is colliding with
(hard) collisions, the spring constant K will be the same a face of the other, then that face defines the plane of collision.
whether the objects are approaching or receding. For e = 0, i.e. If an edge of one object is colliding with an edge of the other,
totally inelastic (soft) collisions, the spring will act as noted these two'edges define the plane of collision. If two vertices
above as long as the objects are approaching each other, but as are colliding, k is directed along the line joining them. See
soon as they start to move apart the spring force will decrease Figure 4.
to 0. For elasticities between 0 and 1, the two spring constants
will be related by K,e,,d~ = e Kot,p r ~ h .
The spring method is easy to understand and easy to pro-
gram. It applies equally well to rigid bodies (articulated or
not) and to flexible bodies, whether modeled as point masses
connected by springs, or by energy of deformation tech-
niques.[29] The main problem with this method is that it is
computationally expensive; stiffer springs mean stiffer equa-
tions, which require smaller time steps for accurate numerical
integration. [8] The numerical effort required goes up with the
"q ot
violence of the collision; as the springs are compressed more
and more, the equations become stiffer and stiffer, and smaller
and smaller time steps are needed. This was the motivation for
seeking a better method o f collision response.
293
SIGGRAPH '88, Atlanta, August 1-5, 1988
i i
refined by stating that interpenetration to greater than some point. This corresponds to the vector equation:
threshold depth iz unacceptable, and causes backtracking and
V2+~xp2-~l-~ lxpl=0
reduction of the step size. This allows the simulation to close
in on a collision point very close to the surfaces of the objects In between perfectly smooth and perfectly rough colli-
by a process similar to binary search. Multiple collision sions lies the great middle ground of partially rough friction.
points can be handled by a straightforward extension to the al- Modeling partial (i.e. realistic) friction can become quite com-
gorithms given below, by inventing multiple collision im- plex; the simple treatment given here is from MacMillan[17]
pulses and incorporating them into the matrix. and McLean[18] and is sufficient to produce visually reason-
able results.
The solution involves solving a set of 15 linear equations
in 15 unknowns. The fifteen unknowns are: the new linear The coefficient of friction, 7, is the maximum allowed ra-
velocity vector for each object (~1, V2); the new angular velo- tio of force parallel to the collision plane versus force perpen-
city vector for each object (c01, o2); and the impulse vector R. dicular to that plane. Although properly speaking, y is a pro-
An impulse has units of momentum and can be thought of as a perty of pairs of surfaces, we assign a y value to each surface,
huge force applied for a tiny time. Because the collision is as- and then use the larger of the 77values of the colliding objects.
sumed to occur in a negligible time (approximately instan- When the two objects have finite 77and e = 0, the collision can
taneous), only the collision impulse itself matters; any other be solved in two steps. First the collision is solved as if it were
forces being applied to the objects will be too small to have an infinitely rough. Then the resulting collision impulse, R, is
effect. By convention, the impulse is directed from object 2 to examined. If the allowed ratio, 77, of the components of R
object 1. parallel and perpendicular to the collision plane is not exceed-
Twelve linear equations can be written down immediate- ed (i.e. if77R, k ~ I R - k ( R - k ) I), all is well and the solution
ly, expressing the change in linear and angular momentum stands, because the objects should stick.
that each object experiences as a result of the collision im- Otherwise, the objects should slide. The system of equa-
pulse R. tions must be set up and solved again with different collision
conditions. These new conditions will give a smaller restrain-
rnlv- 1 = r n l v 1 + R
ing parallel force, because only a limited amount of friction
ra2V2 = rnxvz - R earl act against sliding motion. Two constants ct and 13are cal-
culated, such that the collision impulse will exactly fulfill
I101 =ll001 + Pl ×R
77R - k = I R - k (R • k) I, or in other words such that the ratio
12~2 = 12002- Pa × R of the parallel and perpendicular components of R is exactly y,
and the direction of the parallel component of R is the same as
The last three linear equations come from some assump-
before. This gives the maximum parallel force allowed by the
tions about the collision conditions; the assumptions that we necessary perpendicular force and the coefficient of friction.
will use are that the elasticity, e, is zero (so that the two collid- The collision conditions axe then:
ing objects come to rest relative to each other, at least at the
collision point) and that the surfaces are frictionless (so that R -i =txR -k
the impulse must be perpendicular to the collision plane). Oth- g -j = ~ R -k
er assumptions are possible and are discussed below. Our as-
sumptions require the dot products of R with the collision (V2 + ~2 x p2 - Vl - ~ l x pl) " k = O
frame unit vectors i and j to be zero, and the difference in the ct and ~ are calculated as follows, with Q the component
velocity of the collision point, as seen from each of the two of R perpendicular to the collision plane, and P the unit direc-
objects, to be zero in the k direction. We can write: tion vector of the component of R parallel to the collision
R.i=O plane:
R "j=0 Q=k(R .k)
294
~ ComputerGraphics, Volume 22, Number 4, August 1988
generally must be applied over a large number of very small colliding. Thus, the total size of the linear system to be solved
time steps. This analytical method is cheaper computationally is approximately 9n for n rigid objects involved in the coUi-
unless the collision is very gentle indeed, and the cost of this sion. The sparsity of the matrix increases as n increases, so
collision solution does not depend upon the violence of the that if sparse matrix methods are used the solution should be
collision, certainly a desirable property. around O (n).[20, 21]
Once again, the unknowns to be solved for are g. and ~i
3.2.2. A r t i c u l a t e d R i g i d B o d i e s - T r e e - S t r u c t u r e d , R e v o -
for i = 1...n, R, and Rq for all pairs of objects i and j connect-
lute Joints
ed by a joint. The equations for objects 1 and 2, and for the
Now we extend MacMillan's solution to tree-like articu- collision impulse, still look familiar. The extra summation
lated rigid objects with revolute joints. The various rigid ob- terms reflect the change in linear and angular momentum
jects that make up the tree-like linkages will be numbered resulting from any attachment impulses felt by those objects.
from 1 to n. Objects 1 and 2 will be the colliding objects, and
n
the rest will be linked to one or both of them, either directly or
m l ~ t = m l v l +R + ~ R l i
through some number o f intermediaries. Note that this solu- iffil
tion allows the links of an articulated object to collide with n
other links of the same object or with another object entirely. m2V2 =m2v 2 - R + ~ R ~
i=1
Each rigid object will again have a linear velocity vector v i , an
n
angular velocity vector toi, an inertial tensor mawix li, a mass 11~1 =I1091 +pl xR + ~Pli ×Rli
mi, and a center of mass ci, all expressed in a common inertial i=1
reference frame. n
12~2 =12(.022-- P2 × R + ~ 92i ~R2i
The revolute joints connecting the various rigid objects i=1
will be assumed to be ideal, that is, perfectly elastic and with
no mechanical tolerance. The single joint that connects object The conditions on the collision impulse R are still the
i to object j will be described by the vector Pij that points same.
from c i to the joint, and the vector Pji that points from cj to R "i = 0
the joint. As well as the collision impulse R, this solution will
calculate an attachment impulse Rij for each joint. Unlike the R 'j=0
collision impulse, the attachment impulses Rij are uncon- (V2+~xp2-VI-~I x Pl)" k = 0
strained as to direction. By convention, the attachment im-
pulse Rij points from object j to object i, and Rij =-Rji. Rij For the objects that are not directly colliding (for object
will be (0,0,0) if objects i and j are not connected by a joint. i = 3..n ), the momentum conservation equations are
n
See Figure 5.
rrti~. =miv i + ~Rij
j=l
n
lif-Oi =liOOi + ~Pij ×Rij
j=t
Each joint requires three more linear equations to make
the system of equations complete and solvable. These are
derived from the basic requirement of a revolute joint: the
velocity of the joining point, when seen as part of either of the
rigid objects which it connects, must be the same. Otherwise,
the joint would tend to pull apart. For each joint connecting
objects i and j , three more equations can be written.
. . . . collision
~',,,,. point ~ +~ xpu =~ +~j xp~
Once again, the algorithm requires that the necessary in-
formation about all of the objects be transformed from their
local reference frames to a common inertial reference frame.
The collision frame orthogonal unit vectors i, j , and k must
be determined. The (potentially rather large) linear system is
set up and solved for the variables V/, 0~i, R, and Rij, by stan-
Figure 5. dard methods.[5, 22, 20, 21] The actual elasticity of the colli-
Articulated Collision Problem sion is determined as above, and actual impulses are deter-
mined by multiplying R and the R q ' s by (1 + I~aa.al). The ac-
tual impulses are then put back into the equations above to get
For a collision involving n rigid objects there are 6n the final solution for linear and angular velocities. The last
unknowns corresponding to the resulting linear and angular step is to transform the solution back to the object's local
velocities of the objects, 3 unknowns for the collision impulse, frames.
and either 3 ( n - l ) unknowns corresponding to the attachment
impulses if the objects are all part of one articulated linkage,
or 3(n-2) unknowns if two different articulated objects are
295
SIGGRAPH '88, Atlanta, August 1-5, 1988
296
~ ComputerGraphics, Volume 22, Number4, August 1988
297
SIGGRAPH '88, Atlanta, August 1-5, 1988
298