## Basic Primitives

Let the direction of the ray be given by the vector r = t - s. First, we compute the intersection of the unbounded line x = s + )...r and the sphere. The points of intersection of the line and the sphere's boundary are given by

This quadratic equation needs some rewriting in order to find the roots:

Thus,

A solution exists only if

This should not be too much of a surprise, since after rewriting this expression as

The ray itself intersects the sphere iff [),1, A2]n[O, 1] =I= 0. This is the case iff At :::; 1 and A2 2:: 0. If At > 1, then the ray did not reach far enough to hit the sphere. If A2 < 0, then the ray is pointing away from the sphere. In the case where the ray intersects the sphere, the parameter for the point where the ray enters the sphere is Aenter = max(At, 0). The value Aenter can be used as the time of collision of the spheres in the four-dimensional intersection test. The interval of time where the spheres are intersecting is [Aenter. Aexit], where Aexit = min(A2, 1). Note that if Aexit does not need to be returned, the value A2 is used only for testing whether it is at least zero. In that case, we can leave out the division by llrll2 in the computation of A2.