(Treatment taken from "Practical Ray Tracing in C" by Craig A. Lindley)

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) = Ax^2 + By^2 + Cz^2 + Dxy+ Exz + Fyz + Gx + Hy + Iz + J = 0

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

Aqt^2 + Bqt + Cq = 0 with

Aq = Axd^2 + Byd^2 + Czd^2 + Dxdyd + Exdzd + Fydzd

Bq = 2*Axoxd + 2*Byoyd + 2*Czozd + D(xoyd + yoxd) + Exozd + F(yozd + ydzo) + Gxd + Hyd + Izdpr> Cq = Axo^2 + Byo^2 + Czo^2 + Dxoyo + Exozo + Fyozo + Gxo + Hyo + Izo + J

This leads to the solutions:

t0 =( - Bq - Ö(Bq2 - 4AqCq))/ 2Aq

t1 =( - Bq + Ö(Bq2 - 4AqCq))/ 2Aq

1. Check Aq = 0 (If Aq = 0 then t = -Cq / Bq

2.If Aq ¹ 0, then check the discriminant (If Bq2 - 4AqCq < 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)

5. 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 = 2Axi + Dyi + Ezi + G

yn = 2Byi + Dxi + Fzi + H

z n = 2Czi + Exi + Fyi + I

Rn must be normalized and also we have to find the normal for surface facing the ray. If Rn.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 y2 + z2 - 1 = 0

y x2 + z2 - 1 = 0

z y2 + y2 - 1 = 0

Cone along

x -x2 + y2 + z2 = 0

y x2 - y2 + z2 = 0

z x2 + y2 - z2 = 0

Plane in

yz axis x = 0

xz axis y = 0

xy axis z = 0

paraboloid along

x y2 + z2 - x = 0

y x2 + z2 - y = 0

z x2 + y2 - z = 0

Hyperboloid (one sheet) along

x -x2 + y2 + z2 -1 = 0

y x2 - y2 + z2 -1 = 0

z 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

Main intersection
page

HyperGraph home
page.

*Last changed April 01, 1998, G. Scott Owen, owen@siggraph.org*