-
-
Notifications
You must be signed in to change notification settings - Fork 0
A.06 Bezier Curves and Surfaces
Curves and surfaces can be described by parametric equations that allow to specify each of their points as a weighted sum of specific vertices, commonly known as control points, since they provide a means to shape and control the curve or surface they define.
In parametric representations, a curve is defined by an equation that depends on a single parameter, typically denoted as
There are various methods for defining curves and surfaces with parametric equations. In this tutorial, our focus will be on Bézier curves and surfaces, which are widely employed in computer graphics due to their semplicity and versatility.
In a previous appendix (A.05 - Analytic Geometry), we showed that a line segment can be expressed as a weighted sum of its endpoints
with the parameter
Essentially, what has been derived is a method to calculate all the points along a line segment when only the endpoints are known. In general, when a technique is found for generating new points in space (across any dimension) from a finite set of given points, it is referred to as interpolation. In this specific case, the highest degree of the parameter
If the parameter domain is different, for example, if
Hence, you should use
As a result, if you have a loop that increments
Taking a finite and ordered set of points, it is possible to linearly interpolate every pair within the point set, resulting in a piecewise linear curve, also known as a polyline.
Linear interpolation is useful for interpolating between two points. However, when dealing with more than two points, polylines are not usually employed in computer graphics due to the abrupt changes in direction at the points, referred to as joints in a polyline. Consequently, we need to find a way for representing a smoother curve as a weighted sum of the control points.
Bézier curves use linear interpolation repeatedly to build smoothed curves described by polynomials (in particular, as a weighted sums of control points). To achieve this, it is necessary to define a series of control points where, apart from the first and last points through which the curve passes, the remaining control points act as attractors for the curve.
Now, we need to find a way to express this curve as a polynomial so that it can be expressed as a weighted sum of the control points. Let's start with a simple, practical example. Assume we have three control points
By using linear interpolation, the two line segments with endpoints
Given a fixed value for the parameter
which is the function of the curve
By increasing the number of control points and the linear interpolations performed, Bézier curves offers more control over the shape of the curve at the cost of increasing the degree of the polynomial. As a rule, we require
For example, to build a cubic (3-degree) Bézier curve, we need four control points, which are used in the first linear interpolation to define three line segments as follows:
By linearly interpolating again between
Finally, by interpolating a third time between
As you can see, now the highest degree of the parameter
This equation can also be rewritten in matrix form as
where the superscript has been omitted for convenience, so that
Typically, one can stop at cubic Bézier curves. However, thanks to the repeated linear interpolation and the practical examples we've just examined, it's possible to provide a recursive formula for calculating Bézier curves of any degree.
Nevertheless, in the end, we always end up with a weighted sum of the original control points. So, it would be nice to find an algebraic formula for Bézier curves that avoids the use of recursive formulas and repeated interpolations. Fortunately, such a formula exists, and it's called the Bernstein form of a Bézier curve. The Bernstein form allows to describe Bézier curves of any degree
where
where
For cubic Bézier curves, the Bernstein polynomials are
which are indeed the weights of the fours control points calculated earlier, so that we can rewrite the cubic Bézier curve as follows:
The derivative of a Bézier curve is often used to calculate the tangent space (more details will be provided in a later tutorial). For now, it's enough to note that
where
Finally, it's worth noting that if you want to describe relatively complex curves, the degree of the Bézier curve polynomial can become very high, making it computationally demanding or less practically useful. Fortunately, in most cases, it's possible to build a composition of lower-degree Bézier curve segments that share control points at their endpoints.
In a previous tutorial (01.F - Hello Textures), we indirectly showed that it is possible to use linear interpolation for describing a unit square (in addition to a line segment). Indeed, with four points representing the corners of the square, we can linearly interpolate two pairs of points in one direction, resulting in two horizontal or vertical segments that describe two sides of the square. These segments can then be used for a second linear interpolation in a direction perpendicular to the first one, enabling us to describe every point on the square.
It's clear that two parameters
For example, the point
Considering the concepts presented in this section, it is not too difficult to understand why this technique is referred to as bilinear interpolation.
The concept of Bézier curves, presented in section 3, can be extended to describe nonplanar (curved) surfaces by using bilinear interpolation repeatedly to find a parametric equation as a weighted sum of some control points used to control the shape of the surface. When described this way, a 3D nonplanar surface is oten called a patch.
Now, we need to derive a parametric equation describing a patch. For this purpose, let's first examine a practical example from which to derive a more general formula.
Assume we have a grid of
(source: realtimerendering.com)
Following the same strategy used for Bézier curves, we can bilinearly interpolate repeatedly up to calculating the final point. In the case under consideration, we need to bilinearly interpolate four times to create four intermediate points, which can be used in an additional bilinear interpolation to calculate the final point of the patch, as illustrated in the image above (on the right).
By using the same strategy used for Bézier curves and following the example provided in section 4, we can derive the following recursive formula:
where
However, even in this case we can derive a Bernstein form using Bernstein polynomials that allow to semplify our calculations.
Here, we need
Partially differentiating the above equation gives the following equations:
We hardly use patches with
Besides linear and bilinear interpolations, we also examined another type of interpolation in appendix 05 (Analytic Geometry) that allow to describe every point of a tringle as a weighted sum of its vertices
We can use this type of interpolation repeatedly to describe Bézier triangles, which cannot be described using bilinear interpolation as we they require a triangular domain.
In general, we need
The recursive formula is as follows:
where
Even in this case, we can rely on a Bernstein form, which is as follows:
Observe that the Bernstein polynomials now depend on two variables and are computed differently, as shown below
with
[1] Real-Time Rendering (Haines, Möller, Hoffman)
[2] Introduction to 3D Game Programming with DirectX 12 (Luna)
[3] 3D Graphics for Game Programming (Han)
If you found the content of this tutorial somewhat useful or interesting, please consider supporting this project by clicking on the Sponsor button. Whether a small tip, a one time donation, or a recurring payment, it's all welcome! Thank you!