*
*

**Elements of Ray Tracing:**

How can you find the first intersection between a ray and a

finite-length, open-ended cone aligned along the

x-axis,

for which both ends of the finite-length are on the positive x-axis?

(NB: we can later apply transformations of the co-ordinates to make this a general cone)

Note that the equation for the __infinite__ (double) cone lying along the

x-axis with it's "point" at the origin is:

**
**

*y*^{2} + z^{2} = x^{2}

for a

finite cone, this becomes

*y*^{2} + z^{2} = x^{2}, x

_{min}< x < x

_{max}
but we must also translate the "point" of the cone along the x-axis
to x

_{min} (presuming we want all cones to have points). The

equation is now:

**
***y*^{2} + z^{2} = (x - x_{min})^{2}, x_{min}< x < x_{max}

**(*)**
To find the first

intersection, we simply solve for the

ray equation in (*)

**P**(t) = **E** + t**D**, t ≥ 0

(Now assume that x

_{min} = 0 to make the equations slightly simpler)
giving:

*(y*_{E}+t.y_{D})^{2} + (z_{E}+t.z_{D})^{2} = (x_{E}+t.x_{D})^{2}, with the suitable constraints on the x parameter.
i.e.
t^{2}(y_{D}^{2} + z_{D}^{2} - x_{D}^{2}) + t(2y_{E}y_{D} + 2z_{E}z_{D} - 2x_{E}x_{D}) + (y_{E}^{2} + z_{E}^{2} - x_{E}^{2}) = 0

which is simply a

quadratic equation having

roots:

_________
t = -b ± √b^{2} - 4ac
---------------
2a
where a = (y_{D}^{2} + z_{D}^{2} - x_{D}^{2})
b = (2y_{E}y_{D} + 2z_{E}z_{D} - 2x_{E}x_{D})
c = (y_{E}^{2} + z_{E}^{2} - x_{E}^{2})

Giving the intersections of the ray with the cone in the

parameter t.
To find the position of the first intersection in x,y,z space we must

substitute back into either equation the value of t found at each root.
Additionally, we must now check that the x value found lies within the
x

range permitted above. The first t root which lies in the allowed range
in x space will give us the required

position.
N.B. for cones with their base closer to the y-axis than their point, we
simply translate the

other end of the

double cone into that region of
the x-axis.

**End Caps**
To cope with end caps, we need to inspect the x components of the roots
of the quadratic equation above. Assume the end cap was at
the x

_{min} end, if one of the (real) x roots lies to the left
of x

_{min} and the other lies to the right of x

_{min},
then we know that the ray must have passed through the end cap, and we
can find the position at which it would have intersected the infinite
plane normal to the cone and passing through x

_{min} by

t_{end} = x_{min} - x_{E}
------------
x_{D}

and again convert

t-space to

x-space in the

ray equation.

We should however consider the special case where the ray travels

parallel to the axis of the cone. Here, the quadratic equation will

have no real solutions (no cone point in x-range) or one real solution

(the point of the cone), but will have intersected the end cap(s).

Therefore, the ray tracer must be carefully coded to catch this case.