TExcelTAD
Home › Calculus in Depth › Cylinders and Quadric Surfaces

Cylinders and Quadric Surfaces

Planes are the graphs of first-degree equations in xx, yy and zz. Second-degree equations give the quadric surfaces: ellipsoids, paraboloids, cones and hyperboloids. This lesson shows how to identify them by their traces, classifies the six standard types, and ends with the ray–sphere test and the quadric shapes used for collision in games.

For a gentler first look, see Surfaces. The 2D cross-sections are the conics from Conic Sections.

Cylinders

A cylinder is the surface made of all lines (called rulings) parallel to a given line and passing through a given plane curve. In practice: if one variable is missing from the equation, the surface is a cylinder parallel to that variable's axis.

Equation Surface
x2+y2=4x^2 + y^2 = 4 circular cylinder of radius 2 around the zz-axis
z=y2z = y^2 parabolic cylinder: the parabola z=y2z = y^2 slid along the xx-axis
x29+z24=1\frac{x^2}{9} + \frac{z^2}{4} = 1 elliptic cylinder around the yy-axis

Traces

The trace of a surface in a plane is the curve where they intersect. To recognise a surface, set x=kx = k, y=ky = k and z=kz = k in turn and identify the resulting conics. Traces are also exactly the contour lines you meet in the next chapter (Functions of Several Variables).

Example: z=x2+4y2z = x^2 + 4y^2. In z=k>0z = k > 0 the trace is the ellipse x2+4y2=kx^2 + 4y^2 = k, which grows as kk grows. In x=0x = 0 the trace is the parabola z=4y2z = 4y^2, and in y=0y = 0 the parabola z=x2z = x^2. The surface is an elliptic paraboloid, a bowl opening upward.

The quadric surfaces

The general second-degree equation Ax2+By2+Cz2+Dxy+Eyz+Fxz+Gx+Hy+Iz+J=0Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Iz + J = 0 can be reduced by a rotation and a translation to one of two standard forms: Ax2+By2+Cz2+J=0Ax^2 + By^2 + Cz^2 + J = 0 or Ax2+By2+Iz=0Ax^2 + By^2 + Iz = 0. The nondegenerate cases are:

Surface Standard equation Traces Shape
Ellipsoid x2a2+y2b2+z2c2=1\frac{x^2}{a^2} + \frac{y^2}{b^2} + \frac{z^2}{c^2} = 1 all ellipses closed egg; a sphere if a=b=ca = b = c
Elliptic paraboloid zc=x2a2+y2b2\frac{z}{c} = \frac{x^2}{a^2} + \frac{y^2}{b^2} horizontal: ellipses; vertical: parabolas bowl
Hyperbolic paraboloid zc=x2a2−y2b2\frac{z}{c} = \frac{x^2}{a^2} - \frac{y^2}{b^2} horizontal: hyperbolas; vertical: parabolas saddle
Cone z2c2=x2a2+y2b2\frac{z^2}{c^2} = \frac{x^2}{a^2} + \frac{y^2}{b^2} horizontal: ellipses; vertical: hyperbolas or line pairs double cone
Hyperboloid of one sheet x2a2+y2b2−z2c2=1\frac{x^2}{a^2} + \frac{y^2}{b^2} - \frac{z^2}{c^2} = 1 horizontal: ellipses; vertical: hyperbolas cooling tower, connected
Hyperboloid of two sheets −x2a2−y2b2+z2c2=1-\frac{x^2}{a^2} - \frac{y^2}{b^2} + \frac{z^2}{c^2} = 1 horizontal: ellipses (∣z∣≥c\lvert z \rvert \ge c); vertical: hyperbolas two bowls, a gap between

Reading the signs: with all three squares positive and =1= 1, you have an ellipsoid; one minus sign gives one sheet; two minus signs give two sheets. A linear term in place of a square gives a paraboloid. The variable whose sign differs (or that appears linearly) names the axis.

Note: The saddle z=x2−y2z = x^2 - y^2 reappears in Maximum and Minimum Values as the standard picture of a saddle point: a critical point that is neither a maximum nor a minimum, common in the loss landscapes of deep networks.

Both the hyperboloid of one sheet and the hyperbolic paraboloid are doubly ruled: through every point pass two straight lines lying entirely in the surface. That is why cooling towers and some roofs can be built from straight beams.

python · try it yourself
import numpy as np

# show that the line (1, 0, 0) + t(0, 1, 1) lies on x² + y² − z² = 1
t = np.linspace(-5, 5, 11)
x, y, z = 1 + 0 * t, t, t
print("x²+y²−z² along the line:", np.unique(x**2 + y**2 - z**2))

# and that z = x² − y² contains the line (t, t, 0) and (t, −t, 0)
print("saddle on (t, t, 0):", np.unique(t**2 - t**2 - 0))
x²+y²−z² along the line: [1.]
saddle on (t, t, 0): [0.]

Identifying by completing the square

Classify 4x2+y2−4z2−8x+2y+1=04x^2 + y^2 - 4z^2 - 8x + 2y + 1 = 0:

python · try it yourself
import sympy as sp

x, y, z = sp.symbols("x y z")
expr = 4*x**2 + y**2 - 4*z**2 - 8*x + 2*y + 1
standard = 4*(x - 1)**2 + (y + 1)**2 - 4*z**2 - 4      # completed squares
print("difference:", sp.expand(standard - expr))
print("so (x−1)² + (y+1)²/4 − z² = 1  → hyperboloid of one sheet, axis parallel to z, centre (1, −1, 0)")
difference: 0
so (x−1)² + (y+1)²/4 − z² = 1  → hyperboloid of one sheet, axis parallel to z, centre (1, −1, 0)

Ray–sphere intersection

A sphere ∣p−c∣2=r2\lvert \mathbf{p} - \mathbf{c} \rvert^2 = r^2 and a ray p=o+td\mathbf{p} = \mathbf{o} + t\mathbf{d} (unit d\mathbf{d}) meet where

∣o+td−c∣2=r2→t2+2(d⋅m) t+(∣m∣2−r2)=0,m=o−ct=−(d⋅m)±(d⋅m)2−(∣m∣2−r2)\begin{aligned} \lvert \mathbf{o} + t\mathbf{d} - \mathbf{c} \rvert^2 = r^2 \quad&\to\quad t^2 + 2(\mathbf{d} \cdot \mathbf{m})\,t + (\lvert \mathbf{m} \rvert^2 - r^2) = 0, \qquad \mathbf{m} = \mathbf{o} - \mathbf{c} \\ t &= -(\mathbf{d} \cdot \mathbf{m}) \pm \sqrt{(\mathbf{d} \cdot \mathbf{m})^2 - (\lvert \mathbf{m} \rvert^2 - r^2)} \end{aligned}

The discriminant decides: negative means a miss, zero a tangent graze, positive two hits (entry and exit). The nearest hit with t≥0t \ge 0 is the one you see. Every quadric gives a quadratic in tt in the same way, which is why quadrics are the cheapest curved primitives in a ray tracer.

python · try it yourself
import numpy as np

def ray_sphere(o, d, c, r):
    m = o - c
    b, cc = d @ m, m @ m - r * r
    disc = b * b - cc
    if disc < 0:
        return None
    s = np.sqrt(disc)
    for t in (-b - s, -b + s):                 # nearest first
        if t >= 0:
            return float(t)
    return None                                # sphere behind the ray

c, r = np.array([0.0, 0.0, 5.0]), 1.0
o = np.zeros(3)
for d in [(0, 0, 1), (0.1, 0, 1), (0.2, 0, 1), (0, 0, -1)]:
    d = np.array(d, float) / np.linalg.norm(d)
    t = ray_sphere(o, d, c, r)
    print(np.round(d, 3), "->", "miss" if t is None else f"t = {t:.4f}, hit {np.round(o + t * d, 3)}")
[0. 0. 1.] -> t = 4.0000, hit [0. 0. 4.]
[0.1   0.    0.995] -> t = 4.1077, hit [0.409 0.    4.087]
[0.196 0.    0.981] -> t = 4.7068, hit [0.923 0.    4.615]
[ 0.  0. -1.] -> miss

At the hit point, the outward normal is (p−c)/r(\mathbf{p} - \mathbf{c})/r. For a general quadric F(x,y,z)=0F(x, y, z) = 0, the normal is the gradient ∇F\nabla F, as you will see in Directional Derivatives and the Gradient Vector.

In software

  • Collision shapes. Physics engines love quadrics because their tests are closed-form: spheres (distance to centre ≤r\le r), capsules (a segment plus a radius: the set of points within rr of a segment), cylinders, and ellipsoids. An ellipsoid is a sphere under a non-uniform scale, so engines transform the ray or the other shape by the inverse scale and run the sphere test. Character controllers are usually capsules (Circles and Spheres, Ray–Sphere, Collision Pipeline).
  • Bounding volumes. Bounding spheres and boxes (AABB) wrap complex meshes so that most collision pairs are rejected cheaply.
  • Optics and antennas. Paraboloids focus parallel rays to a point, which is why satellite dishes, headlights and telescope mirrors use them.
  • Optimisation. Near a minimum, a smooth loss looks like an elliptic paraboloid. Near a saddle, it looks like the hyperbolic paraboloid. That picture drives the second-derivative test and the analysis of gradient descent.

Exercises

Exercise 1: Name the surface

Identify (a) x2+z2=9−y2x^2 + z^2 = 9 - y^2, (b) y=x2+z2y = x^2 + z^2, (c) x2−y2+z2=−1x^2 - y^2 + z^2 = -1, (d) z=2x2−3y2z = 2x^2 - 3y^2.

Answer

(a) Sphere of radius 3 centred at the origin. (b) Elliptic (here circular) paraboloid around the yy-axis. (c) Hyperboloid of two sheets with axis the yy-axis. (d) Hyperbolic paraboloid (saddle).

Solution

(a) x2+y2+z2=9x^2 + y^2 + z^2 = 9. (b) yy is linear and the squares have the same sign, so it is a paraboloid opening toward +y+y. (c) Multiply by −1-1: −x2+y2−z2=1-x^2 + y^2 - z^2 = 1. Two minus signs give two sheets, and the positive variable yy is the axis. (d) The squares have opposite signs and zz is linear, so it is a saddle.

Exercise 2: Traces

Describe the traces of x24+y29−z2=1\frac{x^2}{4} + \frac{y^2}{9} - z^2 = 1 in the planes z=0z = 0, z=2z = 2 and x=0x = 0.

Answer

z=0z = 0: the ellipse x2/4+y2/9=1x^2/4 + y^2/9 = 1. z=2z = 2: the larger ellipse x2/20+y2/45=1x^2/20 + y^2/45 = 1. x=0x = 0: the hyperbola y2/9−z2=1y^2/9 - z^2 = 1.

Solution

At z=2z = 2: x2/4+y2/9=5x^2/4 + y^2/9 = 5. Divide by 5: x2/20+y2/45=1x^2/20 + y^2/45 = 1. At x=0x = 0: y2/9−z2=1y^2/9 - z^2 = 1, a hyperbola opening along ±y\pm y.

Exercise 3: Where does the ray hit? (pencil, then code)

A ray starts at o=(0,0,0)\mathbf{o} = (0, 0, 0) with direction d=⟨2,1,2⟩/3\mathbf{d} = \langle 2, 1, 2 \rangle / 3. Find the first tt at which it hits the sphere centred at (4,2,4)(4, 2, 4) with radius 3, and the hit point.

Answer

t=3t = 3, hit point (2,1,2)(2, 1, 2).

Solution
m=o−c=⟨−4,−2,−4⟩,d⋅m=(−8−2−8)/3=−6,∣m∣2−r2=36−9=27t=6±36−27=6±3→t=3 (entry), 9 (exit)hit=3⋅⟨2,1,2⟩/3=(2,1,2)\begin{aligned} \mathbf{m} &= \mathbf{o} - \mathbf{c} = \langle -4, -2, -4 \rangle, \quad \mathbf{d} \cdot \mathbf{m} = (-8 - 2 - 8)/3 = -6, \quad \lvert \mathbf{m} \rvert^2 - r^2 = 36 - 9 = 27 \\ t &= 6 \pm \sqrt{36 - 27} = 6 \pm 3 \quad\to\quad t = 3 \ \text{(entry)},\ 9 \ \text{(exit)} \\ \text{hit} &= 3 \cdot \langle 2, 1, 2 \rangle / 3 = (2, 1, 2) \end{aligned}

The ray goes straight through the centre, so the exit is at (6,3,6)(6, 3, 6).

python · try it yourself
import numpy as np
o, d, c, r = np.zeros(3), np.array([2.0, 1.0, 2.0]) / 3, np.array([4.0, 2.0, 4.0]), 3.0
m = o - c
b, cc = d @ m, m @ m - r * r
ts = [float(-b - np.sqrt(b * b - cc)), float(-b + np.sqrt(b * b - cc))]
print("t values:", [round(t, 6) for t in ts], " first hit:", np.round(o + ts[0] * d, 6))
t values: [3.0, 9.0]  first hit: [2. 1. 2.]

Exercise 4: Ellipsoid via scaling

Explain how to intersect a ray with the ellipsoid x24+y2+z29=1\frac{x^2}{4} + y^2 + \frac{z^2}{9} = 1 using only a unit-sphere routine.

Answer

Scale space by (1/2,1,1/3)(1/2, 1, 1/3). The ellipsoid becomes the unit sphere, and the ray becomes o′=(ox/2,oy,oz/3)\mathbf{o}' = (o_x/2, o_y, o_z/3), d′=(dx/2,dy,dz/3)\mathbf{d}' = (d_x/2, d_y, d_z/3). Solve for tt with the sphere test, keeping d′\mathbf{d}' unnormalised (or rescaling tt), and map the hit back with p=o+td\mathbf{p} = \mathbf{o} + t\mathbf{d}.

Solution

The map S(x,y,z)=(x/2,y,z/3)S(x, y, z) = (x/2, y, z/3) sends the ellipsoid onto x′2+y′2+z′2=1x'^2 + y'^2 + z'^2 = 1, and it is linear, so it sends the line o+td\mathbf{o} + t\mathbf{d} to o′+td′\mathbf{o}' + t\mathbf{d}' with the same parameter tt. Solve ∣o′+td′∣2=1\lvert \mathbf{o}' + t\mathbf{d}' \rvert^2 = 1, which is a quadratic in tt (keep the d′⋅d′\mathbf{d}' \cdot \mathbf{d}' coefficient, since d′\mathbf{d}' is not a unit vector). The same tt plugged into o+td\mathbf{o} + t\mathbf{d} gives the hit on the original ellipsoid. Normals do not transform the same way: they need the inverse-transpose scale.

Test yourself

What surface is y2+z2=1y^2 + z^2 = 1 in R3\mathbb{R}^3?

  1. A circle
  2. A sphere
  3. A circular cylinder around the xx-axis
  4. A cone

x2+y2−z2=−1x^2 + y^2 - z^2 = -1 is a…

  1. hyperboloid of one sheet
  2. cone
  3. hyperboloid of two sheets
  4. ellipsoid

In a ray–sphere test, what does a negative discriminant mean?

  1. The ray grazes the sphere
  2. The ray starts inside the sphere
  3. The ray misses the sphere
  4. The hit is behind the ray