This is a very old article, included for historical interest only!
I wasn’t going to present quite so much code in this series, but the following intersection tests
are (a) tricky to get working correctly and quickly, and (b) they’re not exactly exciting, so I
thought I’d include them here as reference. I’ve also been saying things like “if the ray
intersects the object…” without covering how you’d actually go about detecting that, so this
article covers that.
(Please note that these algorithms most definitely aren’t my work: I’ve adapted most of them from
So here we go: a variety of intersection methods, implemented in C#.
The intersection tests return either an intersection object, if the ray intersects the object,
or null, if not. The constructor of the intersection class has the following form:
The plane tests given determine whether the object is completely on one side of the given plane,
completely on the other side, or whether the plane passes through the object. Planes are
represented as a point on the surface, and the surface normal.
Note that _epsilon is some small number, say 0.00001. _p0, _p1, and _p2 are the
three vertices of the triangle.