This post introduces some widely used splines in computer games including Bézier curves, cubic Hermite splines, Catmull-Rom splines, B-splines, Kochanek–Bartels splines, etc. We show these splines can be bridged through re-formulation. Then, we focus on the extension and generalization of Bézier curves and introduce mathematical methods to create dynamic smooth splines. Last, we develop a simple Editor in Unreal Engine to enable easy creation of splines under different constraints and conditions.
Common Splines
Bézier Curve
The most typical and widely-used spline might be Bézier curves. Bézier curve leverages a set of control points to define a smooth and continuous curve generated by interpolation between these control points. Using the De Casteljau's algorithm,1 we can easily express a Bézier curve in terms of a sum of Bernstein polynomials:
When there are four control points, the generated curve is called cubic Bézier curve. A cubic Bézier curve can be expanded as:
The derivative of an
Similarly, we can obtain the second-order derivative:
We will use these results later soon.
Degree elevation
Suppose
Note that when
Composite Bézier curves
A composite Bézier curve is a series of Bézier curves joined end to
end where the first point of one curve coincides with the last point of
the previous curve. If a Bézier curve is composite, we say it's
However, sometimes we want higher degrees of continuity than
Given two Bézier curves
(positional continuity): consecutive Bézier curves meet at the same point. This holds by definition. In this case, it's . (velocity continuity): the incoming and outgoing derivatives of are the same, vouching for a smooth transition from the first curve to the second. To show this, we let , and the solution is . This gives us . This equation tells us that and are not only colinear with respect to , but their vector lengths are also the same. Rewriting this equation to suggests is fully determined by and if we want continuity. (tangent continuity): and are colinear but not requiring their vector lengths to be equal. Thus, we say is less strict than . If a composite curve is , then it must be . To guarantee , we just add an extra degree of freedom to the vector length: . means the two curves share a common tangent direction at the join point. (acceleration continuity): following a similar process to continuity, the continuity can be defined by . That is to say, is fully determined by and . You should be very careful of using continuity: the continuity causes a loss of two control points and , leaving only one free control point . You perhaps cannot get the curve shape you expect. If you do not want to loss control over these points, you can use uniform B-splines, which will be introduced later. (curvature continuity): this type of continuity requires except requiring , i.e., satisfying . To obtain this result, first expand and then plug in. Last, substitute for with and with , and you will get the right formula. Curvature continuity implies that the curves share a common center of curvature at the join point. (jolt continuity): if a composite Bézier curve is , it satisfies . In this case, the fist curve full determines the second curve and thus the third, forth curve, etc. Now we say the generated composite Bézier curve is as there is indeed no joins.
If a curve is
Rational Bézier curves
The Bezier curve will be fully determined if we specify a particlar
type of continuity, say,
where
An interesting fact about an
To show this, assume there are
Note that this Bezier curve is in the
The first
We will show in later sections that rational Bezier curves are a special case of NURBS curves, and modifying a control point of a rational Bezier curve will lead to a global curve change.
Approximating circular arcs
Symmetrical 2D
A cubic Bézier curve can be used to approximate a circular arc. Let's
first start with a simple case: the arc starts at point
Assume the additional control points are
According to the expanded Bézier curve expression:
we have
On the other hand, according to the derivative of a cubic Bézier
curve
However, we highlight that the resulting curve is not exactly a
perfect circular arc, which means that there are small deviations from a
perfect circular arc. Assuming the radius is
Asymmetrical 2D
Now we've obtained the control points
What about
The rotated
Now we can follow the aforementioned process to calculate the control points:
Last, we rotate
Besides using transformation and rotation, we can also utilize another approach to calculate the control points, with which we can eliminate the need of transforming points and directly getting to the absolute coordinates.2
Let us assume the starting point
giving
When we choose
By differentiating
Returning to the more general case where the angle of
Recall that the choice of
Note that
We expect the overall error to be reduced by setting the minimum,
i.e.
When we have
3D Space
The three-dimension case is more complicated because four control points will form a Bezier curve in 3D space. We should put one constraint on the points: the curve made up of these control points lie in the 2D space.
Cubic Hermite splines
Cubic Hermite splines construct a curve based on two points along with their respecive tangents.
Suppose the given starting point is
Proof is quite simple. Assume our function is
Solving it gives us:
Rearranging
We can also reformulate
We can rewrite
This shows that a cubic Bézier curve that patches the control points in the middle determines the tangents of the interpolation curve at the respective outer points.3
B-splines
Definition and Properties
B-spline stands for basic splines. Let
From the following diagram, we know that the polynomial
B-spline has the following important properties:
is a degree polynomial in . is non-negative on .- On any knot span
, at most degree basic functions are non-zero, i.e., . - The sum of all non-zero degree
basic functions on span is 1. That is, . - If the number of knots is
and given degree , all basic functions with degree are . - At a knot of multiplicity
, basic function is continous. - At each internal knot of multiplicity
, the number of non-zero basic functions is at most , where is the degree of basic functions.
B-spline Curves
Given
Note that when
Typically, B-spline curves can be categorized into three types: open curve, clamped curve and closed curve.
- Open B-spline curves: the generated curve does not connect to the first and last control point.
- Clamped B-spline curves: the curve is connected to the first and
last control point and is also tangent to them. To be a clamped curve,
the first and last knot must be of multiplicity
(recall that there are in all knots). - Closed B-spline curves: the generated curve forms a closed loop.