Ray - Quadric Intersection

(Treatment taken from "Practical Ray Tracing in C" by Craig A. Lindley, John Wiley & Sons, 1992, pp. 86-89)

The class of quadrics (surfaces that can be defined by a quadratic equation) include cylinders, cones, ellipsoids, paraboloids, etc. Note that spheres and planes are a special subclass but have faster routines as special cases. For these we will use the parametric ray formulation and the implicit surface equation for the quadratics.

The general quadric surface equation is

F(x, y, z) = Ax2 + By2 + Cz2 + Dxy+ Exz + Fyz + Gx + Hy + Iz + J = 0

Then substitute in ray equation R(t) = Ro + Rd and we get quadratic equation:

Aqt2 + Bqt + Cq = 0 with

Aq = Axd2 + Byd2 + Czd2 + Dxdyd + Exdzd + Fydzd

Bq = 2*Axoxd + 2*Byoyd + 2*Czozd + D(xoyd + yoxd) + E(xozd + zoxd) + F(yozd + ydzo) + Gxd + Hyd + Izd

Cq = Axo2 + Byo2 + Czo2 + Dxoyo + Exozo + Fyozo + Gxo + Hyo + Izo + J

This leads to the solutions:
t0 =( - Bq - ((Bq2 - 4AqCq))^0.5)/ 2Aq
t1 =( - Bq + ((Bq2 - 4AqCq))^0.5)/ 2Aq

  1. Check Aq = 0 (If Aq = 0 then t = -Cq / Bq)
  2. If Aq <> 0, then check the discriminant. If (Bq2 - 4AqCq ) <0.0 then there is no intersection
  3. Compute t0 and if t0 > 0 then done else compute t1
  4. Once t is found compute Ri = (xi yi zi)

To compute Rn which is the normal at Ri take the partial derivatives of F with respect to x, y, z
Rn = [xn yn zn] = [dF/dx dF/dy dF/dz]

which gives
xn = 2*A*xi + D*yi + E*zi + G
yn = 2*B*yi + D*xi + F*zi + H
z n = 2*C*zi + E*xi + F*yi + I

Rn must be normalized and also we have to find the normal for surface facing the ray.
If R *Rd > 0 then reverse Rn.

Unit Quadric Shape Definitions (all shapes centered about origin (0,0,0) and are of size 1)

Sphere x2 + y2 + z2 - 1 = 0

Cylinder along
x axis : y2 + z2 - 1 = 0
y axis : x2 + z2 - 1 = 0
z axis : y2 + y2 - 1 = 0

Cone along
x axis : -x2 + y2 + z2 = 0
y axis : x2 - y2 + z2 = 0
z axis : x2 + y2 - z2 = 0

Plane in
yz axis : x = 0
xz axis : y = 0
xy axis : z = 0

Paraboloid along
x axis : y2 + z2 - x = 0
y axis : x2 + z2 - y = 0
z axis : x2 + y2 - z = 0

Hyperboloid (one sheet) along
x axis : -x2 + y2 + z2 -1 = 0
y axis : x2 - y2 + z2 -1 = 0
z axis : x2 + y2 - z2 -1 = 0

To define a quadric surface with location and geometrical properties other than that given above we can perform the following steps, usiing an ellipsoid as an example.

1. The defining equation for an ellipsoid is as follows:
x2/a2 + y2/b2 + z2/c2 = 1 where a, b, and c are the axes for x, y, and z.
To displace the ellipsoid from the origin to a position xc, yc, zc, replace x with x - xc, y with y-yc, and z with z-zc.
2. Put in the actual values for a, b, c, xc, yc, and zc. Rearrange the equation to put it into the format of the general quadric surface equation as given above. Match the coefficients with the defining parameters.

Example: assume an ellipsoid centered at xc = 1, yc = 2, and zc = 1, with a = 1, b = 2, z = 5. Then we have the following:

(x - 1)2/12 + (y - 2)2/22 + (z - 1)2/52 - 1 = 0
(x2 - 2x + 1)/1 + (y2 - 4y + 4)/4 + (z2 - 2z + 1)/25 -1 = 0
100x2 - 25y2 + 4z2 -200x -100y -8z + 104 = 0

or A = 100, B = -25, C = 4, D = E = F = 0, G = -200, H = -100, I = -8, J = 104

original page: G. Scott Owen, owen@siggraph.org
errata: Andrés Mejía April 2012