Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 50 ยท Curves and Surfaces

Parametric Curves and Interpolation

Learn parametric curves: Hermite and Catmull-Rom splines, tangents, and C0, C1 and G1 continuity, with a live curve editor you can drag around.

So far you have drawn straight lines, circles and ellipses, each with its own special algorithm. But the outline of a car body, a font glyph or an animation path is none of those. Designers need one flexible tool that can describe almost any smooth shape from a few numbers, and that tool is the parametric curve.

In this lesson you build the foundations: what a parametric curve is, how to make one pass through chosen points (interpolation), and how to join pieces smoothly. The next lessons build on this to reach Bezier curves and B-splines.

Why not y = f(x)?

The curve you learned in school, y = f(x), has one weakness: for each x it gives exactly one y. A circle, a loop or a vertical wall fails that test. A circle needs two values of y for most x. Describing it needs the awkward y = ยฑsqrt(rยฒ โˆ’ xยฒ), and the slope becomes infinite at the sides.

A parametric curve avoids this by computing both coordinates from a third variable, the parameter t, usually running from 0 to 1:

TEXT
P(t) = ( x(t), y(t) )          for 0 <= t <= 1

Think of t as time and P(t) as the position of a moving point; the curve is the path it traces. A circle is simply (r cos t, r sin t) for t from 0 to 2ฯ€, with no special cases. A straight line from A to B is the parametric curve P(t) = A + t (B โˆ’ A), which is the "lerp" you already use for colors.

The tangent (or velocity) is the derivative P'(t) = (x'(t), y'(t)). It points in the direction of travel, and its length tells how fast the point moves. Tangents are the key to joining curves smoothly.

To draw a parametric curve you don't solve anything. You simply evaluate P(t) at many values of t and connect the results with short lines. With 50 to 100 steps per segment the polyline looks perfectly smooth.

Cubic polynomials

The workhorse of graphics is the cubic curve, where each coordinate is a polynomial of degree three:

TEXT
x(t) = a tยณ + b tยฒ + c t + d        (and the same for y, and z in 3D)

Why three? Degree one gives only straight lines. Degree two (parabolas) cannot make an S-shape or control the direction at both ends. Cubics are the lowest degree that can bend one way and then back, and that can match both a position and a direction at each end of a segment. Higher degrees wiggle unpredictably and cost more.

A cubic has four coefficients per coordinate, so you can impose four conditions. Different choices of conditions give different curve types, and the rest of the chapter is a tour of them.

Interpolation versus approximation

A curve interpolates a set of points if it passes through them. It approximates them if the points only pull the curve in their direction without touching it. Interpolation fits data and animation keyframes (the path must go through the keyframes). Approximation, as with Bezier and B-spline curves, feels more natural when designing shapes, because the control points steer the curve without causing unexpected overshoots.

This lesson covers interpolation.

Hermite curves

A Hermite segment is defined by the conditions that matter most for joining: the position and tangent at both ends.

  • P0, the start point, and P1, the end point
  • T0, the tangent at the start, and T1, the tangent at the end

Solving the four conditions for a cubic gives four blending functions, the Hermite basis:

TEXT
h00(t) =  2tยณ โˆ’ 3tยฒ + 1        weight of P0
h10(t) =   tยณ โˆ’ 2tยฒ + t        weight of T0
h01(t) = โˆ’2tยณ + 3tยฒ            weight of P1
h11(t) =   tยณ โˆ’  tยฒ            weight of T1

P(t) = h00 P0 + h10 T0 + h01 P1 + h11 T1

You can verify the endpoints by hand. At t = 0: h00 = 1, everything else is 0, so P(0) = P0. At t = 1: h01 = 1, so P(1) = P1. The tangent weights are zero at both ends but their derivatives are 1, which is why T0 and T1 control the direction.

The longer a tangent, the longer the curve "keeps going" in that direction before turning. A zero tangent makes the curve ease to a stop at that end. The demo shows two Hermite segments joined at a middle point. Drag the orange handles (the tangents) and the blue points. The sliders change how the outgoing tangent at the joint relates to the incoming one.

Continuity

When you join curve segments you care how smooth the joint is. There are two families of definitions.

Parametric continuity compares the actual derivatives:

  • C0: the segments meet at the same point. No gaps, but a corner is allowed.
  • C1: also the first derivatives (tangent vectors) are equal, in direction and length. Moving along the curve at constant t speed shows no jolt.
  • C2: also the second derivatives agree, meaning the curvature (and so the acceleration) is continuous. Cubic B-splines reach this.

Geometric continuity is weaker and compares only shapes:

  • G0 is the same as C0.
  • G1: the tangent directions are the same, but the lengths may differ. The curve looks smooth, but the point may speed up or slow down at the joint.
flowchart LR
  C0["C0 / G0:<br/>same point"] --> G1["G1:<br/>same tangent direction"]
  G1 --> C1["C1:<br/>same tangent vector"]
  C1 --> C2["C2:<br/>same curvature behavior"]

Each step demands more of the joint; C1 implies G1, and C2 implies C1.

For still pictures, G1 usually looks perfectly smooth. For motion, such as a camera moving along a path, you want C1, or the camera visibly lurches at joints. Try it below by changing the slider "length ratio": at 1.00 the joint is C1, at any other positive value it is only G1, and with the angle slider away from 0 it drops to C0 with a visible corner.

Hermite segments and continuity

At the joint the red segment starts with the gray handle. If the ratio is not 1 you can see the curve is still smooth to the eye (G1) but the red part leaves the joint faster or slower than the blue part arrives.

Catmull-Rom splines: interpolating a list of points

Hermite curves need tangents, but when a user clicks a list of points they don't want to specify tangents too. Catmull-Rom splines invent them automatically: at each point, the tangent is parallel to the line connecting its two neighbors.

TEXT
T_i = (P_{i+1} โˆ’ P_{iโˆ’1}) / 2

Then each span between P_i and P_{i+1} is a Hermite segment using T_i and T_{i+1}. Because neighboring spans share the same point and tangent at the joint, the whole spline is C1 and it passes through every point. This makes Catmull-Rom the standard choice for camera paths, animation curves and smooth strokes through sampled points.

The first and last points lack one neighbor; the common fix is to use the endpoint twice (so the tangent there points toward its single neighbor) or to invent a mirrored point.

A small generalization is the cardinal spline, which multiplies the tangent by (1 โˆ’ c), where c is the tension. At c = 0 you get Catmull-Rom, at c = 1 the tangents vanish and the curve is a polyline of straight lines with eased ends, and negative values loosen the curve into bigger loops.

JavaScript
function tangent(pts, i, c) {
  const a = pts[Math.max(0, i - 1)], b = pts[Math.min(pts.length - 1, i + 1)];
  const s = (1 - c) / 2;
  return [(b[0] - a[0]) * s, (b[1] - a[1]) * s];
}

One caveat: the standard Catmull-Rom (the "uniform" kind) can overshoot or form small loops when the points are spaced very unevenly. A centripetal version, which uses a parameter based on distance, avoids that, at the price of more code.

A live editor

Click on empty canvas space to add points, drag any point to move it, and double-click a point to remove it. Move the tension slider to change how tightly the curve hugs the polyline.

Catmull-Rom curve editor

Pull one point far away and notice that the curve only changes near that point, never beyond its neighbors. This property, called local control, is one of the reasons splines are so useful. Another observation: you control the shape only indirectly (the curve is forced through your points), so it can bulge between them. If you want to steer a curve more directly, use control points that the curve doesn't have to touch. That is the idea of Bezier curves.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why is a parametric form P(t) = (x(t), y(t)) better than y = f(x) for general curves?

    A function of x gives only one y per x. With a parameter, x and y are both functions of t, so circles, loops and vertical tangents are no problem.
  2. 2. What four things define a cubic Hermite segment?

    Hermite uses position and tangent at both ends: P0, P1, T0 and T1. The four basis functions weight exactly those.
  3. 3. Two segments meet at a point with the same tangent direction but different tangent lengths. Which statement is correct?

    Equal directions give geometric continuity G1. C1 would need equal tangent vectors, including length, so a speed jump remains.
  4. 4. How does a Catmull-Rom spline choose the tangent at an interior point P_i?

    T_i = (P_(i+1) - P_(i-1)) / 2 makes the curve pass smoothly through every point without asking for tangents.
  5. 5. What does raising the tension of a cardinal spline to 1 do?

    The tangent is scaled by (1 - tension). At tension 1 it vanishes, giving straight spans with eased ends.

Summary

  • A parametric curve P(t) computes every coordinate from a parameter t; draw it by evaluating many values of t.
  • Cubic polynomials are the lowest degree that can match position and direction at both ends and form an S-shape.
  • A Hermite segment is defined by two points and two tangents, blended by four basis functions.
  • C0 means the segments meet, G1 same tangent direction, C1 same tangent vector, C2 same curvature behavior.
  • Catmull-Rom splines compute tangents from neighboring points, so they interpolate every point with C1 continuity; tension generalizes this to cardinal splines.
  • Interpolating curves pass through their points and can overshoot; approximating curves are steered more gently.

Next up is the family of curves that designers prefer for drawing shapes: Bezier Curves.