(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) = 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) + E(xozd + zoxd) + F(yozd + ydzo) + Gxd + Hyd + Izd

Cq = Axo^{2} + Byo^{2} +
Czo^{2} + Dxoyo + Exozo + Fyozo + Gxo + Hyo + Izo + J

This leads to the solutions:

t0 =( - Bq - ((Bq^{2} - 4AqCq))^0.5)/ 2Aq

t1 =( - Bq + ((Bq^{2} - 4AqCq))^0.5)/ 2Aq

- Check Aq = 0 (If Aq = 0 then t = -Cq / Bq)
- If Aq <> 0, then check the discriminant. If (Bq
^{2}- 4AqCq ) <0.0 then there is no intersection - Compute t0 and if t0 > 0 then done else compute t1
- 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** ***R**d > 0 then reverse **Rn**.

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

**Sphere** x^{2} + y^{2}
+ z^{2} - 1 = 0

**Cylinder** along

x axis : y^{2} + z^{2} - 1 = 0

y axis : x^{2} + z^{2} - 1 = 0

z axis : y^{2} + y^{2} - 1 = 0

**Cone **along

x axis : -x^{2} + y^{2} + z^{2} = 0

y axis : x^{2} - y^{2} + z^{2} = 0

z axis : x^{2} + y^{2} - z^{2} = 0

**Plane** in

yz axis : x = 0

xz axis : y = 0

xy axis : z = 0

**Paraboloid** along

x axis : y^{2} + z^{2} - x = 0

y axis : x^{2} + z^{2} - y = 0

z axis : x^{2} + y^{2} - z = 0

**Hyperboloid** (one sheet) along

x axis : -x^{2} + y^{2} + z^{2} -1 = 0

y axis : x^{2} - y^{2} + z^{2} -1 = 0

z axis : x^{2} + y^{2} - z^{2} -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:

x^{2}/a^{2} + y^{2}/b^{2} + z^{2}/c^{2}
= 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)original page: G. Scott Owen, owen@siggraph.org errata: Andrés Mejía April 2012^{2}/1^{2}+ (y - 2)^{2}/2^{2}+ (z - 1)^{2}/5^{2}- 1 = 0 (x^{2}- 2x + 1)/1 + (y^{2}- 4y + 4)/4 + (z^{2}- 2z + 1)/25 -1 = 0 100x^{2}- 25y^{2}+ 4z^{2}-200x -100y -8z + 104 = 0 or A = 100, B = -25, C = 4, D = E = F = 0, G = -200, H = -100, I = -8, J = 104