Ray Tracing Resources Page This page gives a grid of intersection routines for various popular objects, pointing to resources in books and on the web. The most comprehensive books on the subject are Geometric Tools for Computer Graphics (GTCG) and Real-Time Collision Detection (RTCD); the former is all-encompassing, the latter more approachable and focused. A book focused in large part on object/object intersection tests is the Game Physics Cookbook (GPC), with code - see its giant grid for what intersections it covers. Quílez has a bunch of shader-based ray/object intersectors, including ones (beyond those listed in the table) for the torus, disk, and capsule.

Guide to source abbreviations:

Individual article references follow after the table.

## Static Object Intersections

Entries are listed from oldest to newest, so often the last entry is the best. This table covers objects not moving; see the next section for dynamic objects.

References are listed in historical order, so it's usually best to look at the last reference first. References in parentheses indicate algorithms that will work, but are not optimized for the particular primitives. Note that all AABB algorithms can also be used for OBB intersections (simply transform the other primitive to the OBB's space), so we do not list these in the table.

## Dynamic Object Intersections

These are intersections in which the objects are moving relative to one another. Linear motion (only) is assumed; there is research on rotational motion collision detection, not covered here. The TGS collision system (non-commercial use only) has many methods in this area, and the book Real-Time Collision Detection covers the subject in some depth. Other relevant presentations can be found on the Essential Math for Games Programmers site. One principle is that even if both objects are moving, only one has to be considered moving. That is, one object's movement vector can be subtracted from both objects, leaving one object at rest. Another principle is to perform a Minkowski sum (or Minkowski difference) of the moving sphere with the other object, essentially shrinking the moving sphere to a ray. A set of static intersection tests are used in many of these tests, so look in the table above for these. The tests below are categorized as boolean, i.e., whether the objects intersect at all, or location, where the actual intersection location where the two moving objects first hit is formed. (Please let me know if you have simple ways of making a given boolean test into a location test.)

Ray/Moving Sphere: (location) Form a cylinder between the two spheres, intersect the two spheres and cylinder with the ray. See Gregorius 2015.
Ray/Moving Triangle: (boolean) If each triangle is entirely on one side of the plane formed by the other triangle, form the polyhedron between the two triangles. The connecting faces are formed by all the combinations of an edge on one triangle and a vertex on the other. Discard any separating planes formed (i.e., use only planes in which both triangles are on the same side of the plane). Shoot the ray against it using ray/polyhedron testing. (Short of splitting the triangles into two parts each and forming volumes amongst these, is there an elegant way to perform this operation when one triangle's plane splits the other triangle?)
Ray/Moving AABB: (boolean) Form a shaft (paper) between the beginning and ending position of the AABB and shoot the ray against it using ray/polyhedron testing. See RTR4, free Collision Detection chapter.
Ray/Moving OBB: (boolean) An inelegant way is to form all combinations of edge/vertex pairs and form planes to bound the OBBs (see Ray/Moving triangle, above).
Ray/Moving Polyhedron: Take the convex hull of each polyhedron and then the convex hull of both of these. Glassner is the earliest reference I know. See Gregorius 2015 for a modern treatment.

Plane/Moving Sphere: (location) Transform the problem into changing the plane into a thick slab, of thickness equal to the radius of the sphere. Change the sphere's path into a line segment. Perform slab/line segment intersection, i.e., ray/plane intersection for the two sides of the slab. See Gomez; and RTR4, free Collision Detection chapter..
Plane/Moving AABB: (location) If the plane's normal is along one of the primary axes, e.g., it is [0 1 0], [0 0 -1], etc., then turn the problem into slab/line segment intersection, similar to plane/moving sphere above. That is, take the thickness of the AABB and make the plane this thick.

The general principal of intersecting a moving sphere against an object is to simplify thinking about the problem by making the sphere into a line segment between its center's start and end locations, while "adding" this sphere (a Minkowski sum) to the other object.
Moving Sphere/Sphere: (location) Add the radius of the moving sphere to the static sphere, and treat the moving sphere as a ray. Use this ray to perform ray/sphere intersection. See Gomez and RTR4, free Collision Detection chapter..
Moving Sphere/Triangle: (location) Similar to above, turn the sphere into a ray. The triangle turns into a solid defined by a set of spheres at the vertices, cylinders along the edges, and a slab for the interior of the triangle. See ; GTWeb doc; RTR4, free Collision Detection chapter.; Gregorius 2012.
Moving Sphere/AABB: GTWeb has a more detailed document on this topic. (boolean) A conservative test (i.e., no false misses, but can give false hits when there actually is no overlap) is to make the AABB move, so forming a shaft (paper) between the beginning and ending position of the AABB. Test the static sphere with shaft testing.

Moving Triangle/Triangle: See GTweb doc and Catto 2013.

Moving AABB/AABB: (location) See Gomez for a use of the Separating Axis Theorem to solve this problem. (boolean) Form a shaft (paper) between the beginning and ending position of the AABB and compare the static AABB against it with shaft testing.

Moving OBB/OBB: (location) See GTweb doc.

Moving Convex Polyhedra/Convex Polyhedra: (boolean) The GTCG book, p. 615 on, gives pseudocode for using the method of separating axes to solve this problem. See GTweb doc.

Gregorius 2015 covers computing contact points among spheres, capsules, convex hulls, and meshes.

Many of the non-curved objects which are moving can be treated as forming shafts between the starting and ending locations, and then the shaft can be tested against a ray simply enough, or against another non-curved object by using the polyhedron/polyhedron test in Gems IV p.83. Another approach is to use the Separating Axis Theorem (also see Bobic) to tell if the two objects overlap. However, all of these approaches are just boolean tests.

## Article references

Bobic - Bobic, Nick, Gamasutra, March 2000.
Gomez - Gomez, Miguel, Gamasutra, October 1999.
Schroeder - Schroeder, Tim, "Collision Detection Using Ray Casting," Game Developer Magazine, pp. 50-57, August 2001.

## Graphics Gems references

Ray/ray: Ronald Goldman, Intersection of Two Lines in Three-Space, Graphics Gems, p. 304.
Ray/sphere: Jeff Hultquist, Intersection of a Ray with a Sphere, Graphics Gems, pp. 388-389.
Ray/cylinder: Joseph M. Cychosz and Warren N. Waggenspack, Jr., Intersecting a Ray with a Cylinder, Graphics Gems IV, pp. 356-365, includes code.
Ray/polygon: Eric Haines, Point in Polygon Strategies, Graphics Gems IV, pp. 24-46, includes code.
Ray/cone: Ching-Kuang Shene, Computing the Intersection of a Line and a Cone, Graphics Gems V, pp. 227-231.
Ray/AABB: Andrew Woo, Fast Ray-Box Intersection, Graphics Gems, pp. 395-396, includes code.
Ray/polyhedron: Eric Haines, Fast Ray-Convex Polyhedron Intersection, Graphics Gems II, pp. 247-250, includes code.

Plane/AABB and AABB/polyhedron: Ned Greene, Detecting Intersection of a Rectangular Solid and a Convex Polyhedron, Graphics Gems IV, pp. 74-82.

Sphere/AABB: Jim Arvo, A Simple Method for Box-Sphere Intersection Testing, Graphics Gems, pp. 247-250, includes code.

Triangle/AABB: Doug Voorhies, Triangle-Cube Intersection, Graphics Gems III, pp. 236-239, includes code.
Triangle/AABB and AABB/polyhedron: Green and Hatch, Fast Polygon-Cube Intersection Testing, Graphics Gems V, pp. 375-379, includes code.
Triangle/frustum: Paul Heckbert, Generic Convex Polygon Scan Conversion and Clipping, Graphics Gems, pp. 84-86, includes code.

Polyhedron/polyhedron: Rich Rabbitz, Fast Collision Detection of Moving Convex Polyhedra, Graphics Gems IV, pp. 83-109, includes code.

## Algorithms

Scalar values are lowercase italic: a, n, t. Vectors are lowercase bold: p, v, x. Matrices are uppercase bold: M, T. "X" denotes a cross product, "^2" means "squared", "||x||" means the length of vector x.

Ray/ray: (after Goldman, Graphics Gems; see his article for the derivation) Define each ray by an origin o and a normalized (unit vector) direction d. The two lines are then

L1(t1) = o1 + d1*t1
L2(t2) = o2 + d2*t2

The solution is:
t1 = Determinant{(o2-o1),d2,d1 X d2} / ||d1 X d2||^2

and

t2 = Determinant{(o2-o1),d1,d1 X d2} / ||d1 X d2||^2

If the lines are parallel, the denominator ||d1 X d2||^2 is 0.

If the lines do not intersect, t1 and t2 mark the points of closest approach on each line. 