The face collision algorithm takes as input a triangle, the starting and ending positions of the ball, and the ball's radius. The algorithm returns an α in [0,1], which is the fraction of the path the ball can travel before colliding with the front face of the triangle. In the event of a collision, the algorithm also returns the foward-facing normal of the triangle.
We begin by describing the standardized face collision algorithm, which handles a special case of triangles. Then we show how to use the special case algorithm to detect collisions for arbitrary triangles.
Standardized Face Collision Algorithm
The special case we consider first is when the triangle is in a standard orientation;
triangle (
v0,
v1,
v2)
is in a standard orientation if
v0
is at the origin,
v1
is in the x - positive z half-plane, and
v2
is on the positive x axis. We note that the front face of a standardized triangle is facing up.
The figure below illustrates a triangle in standard orientation.
If y0 < r or y0 = y1 then there cannot be a front face collision. In the first case, the ball, in its initial position, either intersects the x-z plane or is below it. In the second case, the ball moves parallel to the x-z plane. In either case, no matter how the ball moves it cannot collide with the front face of the triangle. Our algorithm returns α=1. The two cases are illustrated below
If neither of the two cases described above hold, we go on to test for a face collision.
Note that the point q exists. Since y0 ≠ y1, p0 and p1 are distinct points and define a line. Further, this line is not parallel to the x-z plane. Thus there is a unique point on this line that is exactly r units above the x-z plane.
To compute q, we first represent the line through p0 and p1 parametrically as p0 + β (p1 -p0). Each point on the line corresponds to a unique value of β. In particular, p0 and p1 correspond to β=0 and β=1, respectively. Points on the line segment between p0 and p0 correspond to values of β in the range [0,1].
To compute q, we simply need to find the value of β such that the y-component of q = p0 + β (p1 -p0) is r. This occurs at β =(r- y0)/ (y1 -y0).
Assuming q=( xq, yq, zq), the projection is simply q'=( xq,0, zq).

Next we show how to test whether this projected point, q',
lies inside the
triangle. First we need a definition.
An edge e of the triangle lies on a line
L that partitions the
x-z plane into two half-planes. We'll say
that the point q' is
in with respect to e if q' lies in
in the half-plane defined by L
that contains the triangle. This idea is illustrated in the figure
below.

Thus the point
q' is inside the triangle if and only
if it is in with respect to the three edges of
the triangle.
This edge lies on the x-axis. The q' is inside with respect to the edge if and only if
To detect a collision, we transform the triangle into its standard orientation. We also transform the ball's starting and ending position into this standard frame. We use the standardized face collision algorithm to determine if a collision occurs and, if so, the corresponding α value. Note that the α value is unchanged by the transformation. We return this α value and, if a collision does occur (i.e. 0 ≤ α <1), the forward facing normal of the triangle in its real world orientation.
Separate notes describe the algorithm for standardizing a triangle and for transforming points (the ball's starting and ending position) into the standard frame. To speed our algorithm, we can precompute the standard orientation of each triangle.