Elements of Ray Tracing:

How can you find the first intersection between a ray and a
finite-length, open-ended cone aligned along the
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:

y2 + z2 = x2
for a finite cone, this becomes y2 + z2 = x2, xmin< x < xmax but we must also translate the "point" of the cone along the x-axis to xmin (presuming we want all cones to have points). The equation is now:
y2 + z2 = (x - xmin)2, xmin< x < xmax
(*) To find the first intersection, we simply solve for the ray equation in (*)
P(t) = E + tD, t ≥ 0
(Now assume that xmin = 0 to make the equations slightly simpler) giving:
(yE+t.yD)2 + (zE+t.zD)2 = (xE+t.xD)2, with the suitable constraints on the x parameter.

t2(yD2 + zD2 - xD2) + t(2yEyD + 2zEzD - 2xExD) + (yE2 + zE2 - xE2) = 0
which is simply a quadratic equation having roots:
t = -b ± √b2 - 4ac

where a = (yD2 + zD2 - xD2)
      b = (2yEyD + 2zEzD - 2xExD)
      c = (yE2 + zE2 - xE2)
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 xmin end, if one of the (real) x roots lies to the left of xmin and the other lies to the right of xmin, 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 xmin by
tend = xmin - xE

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.

Log in or register to write something here or to contact authors.