Bézier Curves and Splines
✨ The Beauty of Bézier Curves & Splines
Bézier curves and splines are fundamental tools in computer graphics and animation, enabling the creation of smooth, flexible paths and shapes. Unlike basic curves like parabolas or circular arcs, Bézier curves can navigate complex paths, including loops, offering immense versatility in design and animation. Understanding their construction naturally leads to the concept of splines, which are chains of connected curves.
These curves provide an elegant computational method for defining paths, offering several useful properties:
Tangent and Normal Directions: Crucial for orienting objects or constructing local coordinate spaces around any point on the curve, which is invaluable for procedural geometry generation.
Radius of Curvature: Allows analysis of how sharply a curve is bending and in what direction.
Analytical Bounding Box: Essential for optimization problems, such as efficient intersection tests in game development.
Bézier curves and splines are ubiquitous in games and various applications. They form the basis for:
Animations: Such as camera paths or character movements.
3D Models: Generating flexible structures like rollercoaster tracks that can be manipulated by bending, twisting, and extending.
Game Tracks: Used in games like Flowstorm to create smooth, curved sliding tracks.
Design Tools: Familiar to users of graphic design software like Photoshop's pen tool, which utilizes Bézier curve handles for precise shape control.
🏗️ Constructing Bézier Curves: De Casteljau's Algorithm
The construction of Bézier curves relies on a process of successive linear interpolations, famously known as De Casteljau's Algorithm.
📏 Linear Interpolation (Lerp)
The foundational concept is linear interpolation, or lerp.
Imagine two points, P0 and P1, connected by a line segment.
A third point, P, can be positioned along this segment using a t-value between 0 and 1.
When t=0, P is at P0.
When t=1, P is at P1.
Intermediate values of t represent a blend between P0 and P1.
Mathematically, this is expressed as: (1−t)P0+tP1.
📈 Quadratic Bézier Curve
To create a quadratic Bézier curve, we extend the lerp concept:
Start with three control points: P0, P1, and P2.
Perform two linear interpolations simultaneously:
Lerp(P0, P1, t)yields a point, let's call it P01.Lerp(P1, P2, t)yields a point, let's call it P12.
Connect P01 and P12 with another line segment.
Perform a final
lerpon this new segment:Lerp(P01, P12, t). The path traced by this final interpolated point as t varies from 0 to 1 forms a quadratic Bézier curve.
📊 Cubic Bézier Curve
The process can be generalized to create higher-degree curves. For a cubic Bézier curve, we use four control points: P0, P1, P2, and P3.
Perform three initial
lerpson the segments P0P1, P1P2, and P2P3, yielding P01, P12, and P23.Perform two subsequent
lerpson P01P12 and P12P23, yielding P012 and P123.Perform a final
lerpon P012P123. The path traced by this point is the cubic Bézier curve.
This nested lerp approach, known as De Casteljau's Algorithm, is valued for its numerical stability and ease of understanding. The resulting curve is always smooth, regardless of the control point configuration. Cubic Bézier curves are particularly common in practical applications.
📐 Bernstein Polynomial Form
Another powerful interpretation of Bézier curves is through Bernstein Polynomials. While De Casteljau's algorithm provides an intuitive construction, the Bernstein form offers a direct mathematical expression and deeper insights into curve properties.
📝 Mathematical Expansion
Starting from the nested lerp equations for a cubic Bézier curve, if we expand and rearrange the terms, we can express the curve's point P(t) as a weighted sum of its control points:
Here, P0, P1, P2, P3 are the control points (visualized as vectors from the origin), and Bi,n(t) are the Bernstein polynomials, which act as weighting functions. For a cubic Bézier curve (n=3), these polynomials are:
B0,3(t)=(1−t)3
B1,3(t)=3t(1−t)2
B2,3(t)=3t2(1−t)
B3,3(t)=t3
⚖️ Weighted Sum Properties
These polynomials exhibit key characteristics:
They are always non-negative within the t∈[0,1] range.
Their sum always equals 1 for any given t value: ∑i=0nBi,n(t)=1. This property ensures that the curve remains within the convex hull of its control points.
As t changes from 0 to 1, the weights shift across the control points.
At t=0, B0,3(0)=1, and all other Bi,3(0)=0, so P(0)=P0.
At t=1, B3,3(1)=1, and all other Bi,3(1)=0, so P(1)=P3.
For intermediate t values, the curve is a blend, with the influence of each control point varying smoothly.
This Bernstein Polynomial Form provides an alternative, equivalent mathematical representation that directly reveals the influence of each control point on the curve's shape.
〰️ Derivatives and Curve Properties
The ability to express Bézier curves using Bernstein polynomials allows for the analytical calculation of their derivatives, which unveil crucial information about the curve's behavior.
🚀 First Derivative: Velocity and Tangent
The first derivative of a Bézier curve, P′(t), represents the velocity vector at any given t-value along the curve.
A fascinating property is that the derivative of a Bézier curve is always another Bézier curve of one degree lower. For a cubic Bézier, its first derivative is a quadratic Bézier curve.
The derivative vector is tangent to the curve.
By normalizing this derivative vector, we obtain the tangent direction.
Rotating the tangent direction by 90° (in 2D) gives the normal direction.
Having both tangent and normal directions is key to creating local coordinate spaces along the curve, which are essential for generating offset geometry, such as roads or tracks in 3D.
💨 Second Derivative: Acceleration
The second derivative, P′′(t), represents the acceleration vector of the point along the curve—the rate of change of velocity.
Following the pattern, the second derivative of a cubic Bézier curve is a linear Bézier curve (a line segment or
lerp).
💥 Third Derivative: Jerk/Jolt
The third derivative, P′′′(t), is known as jerk or jolt, representing the rate of change of acceleration.
For a cubic Bézier curve, the third derivative is simply a constant point (a two-dimensional constant).
These derivatives illustrate how different aspects of the curve's motion and shape are interconnected and can be derived analytically.
🌀 Curvature
Curvature (κ) is a fundamental property that quantifies how sharply a curve is bending at any given point. It can be calculated for any parametric curve using the velocity and acceleration vectors.
🧮 Curvature Formula
For a parametric curve P(t), the curvature κ is given by:
In 2D, this simplifies to the determinant of the velocity and acceleration vectors:
Where:
P′(t) is the velocity vector (first derivative).
P′′(t) is the acceleration vector (second derivative).
∣∣...∣∣ denotes the magnitude of a vector.
📏 Interpreting Curvature
If κ=0, the curve is flat or straight at that point.
The further κ is from 0, the more tightly bent the curve is.
The unit of curvature can be interpreted as radians per meter or, more commonly, as reciprocal radius. This means κ=R1, where R is the radius of the osculating circle.
⭕ Osculating Circle
The osculating circle (or circle of curvature) is the circle that best approximates the curve at a given point, sharing the same tangent and curvature. Its radius is R=κ1.
🔄 Inflection Points
An inflection point occurs where the curvature changes sign (i.e., passes through zero).
At an inflection point, the curve transitions from bending in one direction to bending in the opposite direction.
The osculating circle is undefined at an inflection point because the curve is locally straight (κ=0), implying an infinite radius.
📦 Bounding Boxes
Bounding boxes are crucial optimization tools in game development and computer graphics, used for tasks like culling (determining visibility) and intersection testing. A tight bounding box around a Bézier curve can significantly reduce the computational cost of these operations.
💡 Naïve vs. Tight Bounding Box
Naïve Solution: Using the control points of the Bézier curve to define a bounding box. While simple, this often results in an overly large box that doesn't tightly fit the curve, especially for curves that extend beyond their control point convex hull.
Tight Bounding Box: The goal is to find the smallest possible axis-aligned bounding box that precisely encloses the curve. This box typically touches the curve at its local minima and maxima in X and Y directions.
📈 Finding Extrema Using Derivatives
The local minima and maxima of the curve (which define the tight bounding box) occur where the derivative changes sign. This means we can find these points by locating the roots of the first derivative for both the X and Y components of the curve.
Separate Components: Split the 2D curve P(t)=(x(t),y(t)) into its component functions x(t) and y(t).
Calculate Derivatives: Find the first derivatives x′(t) and y′(t).
Find Roots: Set x′(t)=0 and y′(t)=0. For a cubic Bézier curve, x′(t) and y′(t) are quadratic polynomials.
Quadratic Formula: Use the quadratic formula to find the roots (t-values) for x′(t)=0 and y′(t)=0. This yields up to two t-values for X and two for Y.
Filter and Evaluate:
Discard any t-values outside the range [0,1].
Discard any t-values that result from negative values inside the square root (non-real roots).
The remaining valid t-values, along with the curve's endpoints (t=0 and t=1), represent potential extrema.
Construct Bounding Box: Evaluate the curve P(t) at all valid t-values and the endpoints. The minimum and maximum X and Y coordinates among these points define the tight bounding box.
This analytical approach significantly improves the accuracy of bounding box calculations compared to relying solely on control points.
📏 Arc Length Parameterization
While Bézier curves are beautiful in their construction and properties, calculating their arc length and achieving uniform spacing along them presents a challenge.
❌ No Closed-Form Solution for Arc Length
One of the less "beautiful" aspects of cubic Bézier curves is that there is no closed-form analytical solution for their arc length. The integral required to calculate it is an elliptic integral, which means it cannot be expressed using elementary functions.
approximating Arc Length
Since an exact solution is impossible, we must approximate the arc length:
Subdivision: The most common method is to subdivide the curve into a series of small line segments.
Summation: Calculate the length of each individual line segment and sum them up.
Accuracy vs. Cost: The more segments (samples) used, the more accurate the approximation, but also the more computationally expensive.
🚶 Arc Length Parameterization (Equidistant Points)
A common requirement is to place points at equidistant intervals along a curve, or to animate an object at a constant speed. Simply using equally spaced t-values on a Bézier curve often does not result in equally spaced points by distance. This is because the speed (magnitude of the derivative) along the curve is generally not constant.
💡 Solving Uneven Spacing with a Lookup Table
To achieve arc length parameterization (i.e., getting a point at a specific distance along the curve, or ensuring uniform spacing):
Lookup Table Generation:
Subdivide the curve into many small segments.
For each sampled t-value, calculate the cumulative arc length from the start of the curve to that point.
Store these pairs of (t-value, cumulative distance) in a lookup table.
Querying the Table:
When a desired distance
Dis needed, search the lookup table for the two entries whose distances bracketD.Linearly interpolate between the t-values of these two entries to find the approximate t-value corresponding to
D.
Evaluate Curve: Use this interpolated t-value to evaluate the Bézier curve and get the desired point.
This method, though an approximation, is sufficiently accurate for most practical applications in games and animation, allowing for uniform motion and spacing along complex paths.
🌌 Beyond Bézier Curves
While this discussion has focused on the intricacies of Bézier curves, they are just one type within a broader "cinematic universe" of splines. Other important types include B-splines, which offer different control mechanisms and properties, often used for more complex geometric modeling.
The mathematical elegance of their construction, despite some approximation necessities, makes Bézier curves a beautiful and powerful tool for defining smooth, flexible paths in various digital domains.

Ask anything
We've read this whole study set, so questions about it get the best answers.