# Collision Detection in Interactive 3D Environments

The heart of any system that simulates the physical interaction between objects is collision detectionâthe ability to detect when two objects have come into contact. This system is also one of the most difficult aspects of a physical simulation to implement correctly, and invariably it is the main consumer of CPU cycles. Practitioners, new to the field or otherwise, quickly discover that the attempt to build a fast, accurate, and robust collision detection system takes them down a long path fraught with perils and pitfalls unlike most they have ever encountered. Without in-depth knowledge and understanding of the issues associated with engineering a collision detection system, the end of that path is an abyss that has swallowed many a good programmer!Gino van den Bergen's new book is the story of his successful journey down that path. The outcome is his well-known collision detection system, the SOftware Library for Interference Detection (SOLID). Along the way, he covers the topics of vector algebra and geometry, the various geometric primitives of interest in a collision system, the powerful method of separating axes for the purposes of intersection testing, and the equally powerful Gilbert-Johnson-Keerthi (GJK) algorithm for computing the distance between convex objects. But this book provides much more than a good compendium of the ideas that go into building a collision system. The curse of practical computational geometry is floating-point arithmetic. Algorithms with straightforward implementations when using exact arithmetic can have catastrophic failures in a floating-point system. Specifically, intersection and distance algorithms implemented in a floating-point system tend to fail exactly in the most important case in a collision systemâwhen two objects are just touching. Great care must be taken to properly handle floating-point round off errors. Gino's ultimate accomplishment in this book is his presentation on how to correctly implement the GJK distance algorithm in the presence of single-precision floating-point arithmetic. And what better way to illustrate this than with a case study, the final chapter on the design and implementation of SOLID.About the CD-ROMThe companion CD-ROM includes the full C++ source code of SOLID 3.5 as well as API documentation in HTML and PDF formats. Both single (32bit) and double (64bit) precision versions of the SOLID SDK plus example programs can be compiled for Linux platforms using GNU g++ version 2.95 to 3.3 and for Win32 platforms using Microsoft Visual C++ version 6.0 to 7.1. Use of the SOLID source code is governed by the terms of either the GNU GPL or the Trolltech QPL (see CD-ROM documentation for details).About the AuthorGino van den Bergen is a game developer living and working in The Netherlands. He is the creator of SOLID and holds a Ph.D. in computing science from Eindhoven University of Technology. Gino implemented collision detection and physics in NaN Technologies' Blender, a creation suite for interactive 3D content.

Audience
Professionals or students working in game development, simulation, scientific visualization, or virtual worlds.

,

Published: October 2003

Imprint: Morgan Kaufmann

ISBN: 978-1-55860-801-6

## Reviews

• "Having read this book from cover to cover, I can summarize my opinion in two words from a mathematician's lexicon: elegant and beautiful. There is very little to criticize in this exquisite work." âIan Ashdown, byHeart Consultants, Inc. "Building a real-time collision detection system is by no means a trivial task. A firm understanding is required of the geometry and mathematics for intersection testing, especially when the objects are in motion. The skilled use of convexity is essential for distance calculations. The system must be designed carefully to support high-performance physical simulations. In particular, spatial partitioning and tight-fitting bounding volumes must play a role in minimizing the computational requirements of the system. The system is sufficiently large that the principles of software engineering apply to its development. Moreover, collision detection is notoriously difficult to implement robustly when using floating-point arithmetic. The challenges of architecting and implementing a collision detection system are formidable! Collision Detection in Interactive 3D Environments is an elegantly written treatise on this topic. Gino guides you through the basic concepts, provides insightful discussions on how to cope with the problems inherent in floating-point arithmetic, covers the all-important topic of computing distance between convex objects, and presents an informative summary of the spatial data structures that are commonly encountered in practice. And as an artisan of the field, Gino finishes the story with a case studyâthe design and implementation of his own working collision detection system, SOLID. This is the first book to provide all the details necessary to build a collision detection system that really works. I hope you will find, as I did, that the amount of material in this book is incredible, making it an extremely valuable resource." âDave Eberly, president, Magic Software, Inc., and author of 3D Game Engine Design, co-author with Philip Schneider of Geometric Tools for Computer Graphics, and author of Game Physics.

## Contents

• 1 Introduction1.1 Problem Domain1.2 Historical Background1.3 Organization
2 Concepts2.1 Geometry2.1.1 Notational Conventions2.1.2 Vector Spaces2.1.3 Affine Spaces2.1.4 Euclidean Spaces2.1.5 Affine Transformations2.1.6 Three-dimensional Space2.2 Objects2.2.1 Polytopes2.2.2 Polygons2.2.3 Quadrics2.2.4 Minkowski Addition2.2.5 Complex Shapes and Scenes2.3 Animation2.4 Time2.5 Response2.6 Performance2.6.1 Frame Coherence2.6.2 Geometric Coherence2.6.3 Average Time2.7 Robustness2.7.1 Floating-Point Numbers2.7.2 Stability2.7.3 Coping with Numerical Problems
3 Basic Primitives3.1 Spheres3.1.1 Sphere-Sphere Test3.1.2 Ray-Sphere Test3.1.3 Line-Segment-Sphere Test3.2 Axis-Aligned Boxes3.2.1 Ray-Box Test3.2.2 Sphere-Box Test3.3 Separating Axes3.3.1 Line-Segment-Box Test3.3.2 Triangle-Box Test3.3.3 Box-Box Test3.4 Polygons3.4.1 Ray-Triangle Test3.4.2 Line Segment-Triangle Test3.4.3 Ray-Polygon Test3.4.4 Triangle-Triangle Test3.4.5 Polygon-Polygon Test3.4.6 Triangle-Sphere Test3.4.7 Polygon-Volume Tests
4 Convex Objects4.1 Proximity Queries4.2 Overview of Algorithms for Polytopes4.2.1 Finding a Common Point4.2.2 Finding a Separating Plane4.2.3 Distance and Penetration Depth Computation4.3 The Gilbert-Johnson-Keerthi Algorithm4.3.1 Overview4.3.2 Convergence and Termination4.3.3 Johnson's Distance Algorithm4.3.4 Support Mappings4.3.5 Implementing the GJK Algorithm4.3.6 Numerical Aspects of the GJK Algorithm4.3.7 Testing for Intersections4.3.8 Penetration Depth
5 Spatial Data Structures5.1 Nonconvex Polyhedra5.1.1 Convex Decomposition5.1.2 Polyhedral Surfaces5.1.3 Point in Nonconvex Polyhedron5.2 Space Partitioning5.2.1 Voxel Grids5.2.2 Octrees and k-d Trees5.2.3 Binary Space Partitioning Trees5.2.4 Discussion5.3 Model Partitioning5.3.1 Bounding Volumes5.3.2 Bounding-Volume Hierarchies5.3.3 AABB Trees versus OBB Trees5.3.4 AABB Trees and Deformable Models5.4 Broad Phase5.4.1 Sweep and Prune5.4.2 Implementing the Sweep-and-Prune Algorithm5.4.3 Ray Casting and AABBs
6 Design of SOLID6.1 Requirements6.2 Overview of SOLID6.3 Design Decisions6.3.1 Shape Representation6.3.2 Motion Specification6.3.3 Response Handling6.3.4 Algorithms6.4 Evaluation6.5 Implementation Notes6.5.1 Generic Data Types and Algorithms6.5.2 Fundamental 3D Classes
7 Conclusion7.1 State of the Art7.2 Future Work