Intersecting rays with objects
Use whenever possible the implicit equation F(q) = 0 of the object or object parts. Use parametric equation of the line of the ray, q = p+vt.
Solve the equation F(p+vt) = 0 to find possible values of t. Find the minimal nonnegative value of t to get the intersection point (checking that t is nonegative is important: we want intersections with the ray starting from p, not with the whole line!