De Casteljau's algorithm
De Casteljau's algorithm is a recursive geometric procedure for evaluating points on Bézier curves by iteratively applying linear interpolation, or barycentric combinations, to a sequence of control points based on a parameter t in the interval [0, 1].[1] This method constructs the curve point through a triangular array of intermediate points, where each level refines the interpolation until the final value is obtained after n steps for a degree-n curve.[2]
Developed in 1959 by French mathematician and engineer Paul de Faget de Casteljau while employed at Citroën, the algorithm emerged from efforts to model smooth free-form surfaces for automotive design using early computational tools.[3] Although de Casteljau's work remained largely internal and unpublished until his 1986 book Shape Mathematics and CAD, it paralleled and influenced the development of Bézier curves by Pierre Bézier at Renault, establishing a numerically stable foundation for polynomial curve representation in computer-aided geometric design (CAGD).[2] The algorithm's inception in the late 1950s marked a pivotal advancement in parametric curve evaluation, enabling efficient computation without direct polynomial expansion.[4]
At its core, the algorithm operates on a control polygon defined by points P_0, P_1, \dots, P_n, initializing the zeroth level as P_i^{(0)} = P_i for i = 0, \dots, n. Subsequent levels are computed recursively via P_i^{(k)} = (1 - t) P_i^{(k-1)} + t P_{i+1}^{(k-1)} for k = 1, \dots, n and appropriate i, culminating in the curve point B(t) = P_0^{(n)}.[1] This process not only yields the point but also facilitates curve subdivision by generating new control polygons for segments on either side of t, preserving properties like C^k-continuity at join points.[2] The method extends naturally to Bézier surfaces, applying the interpolation bidirectionally for rectangular patches or via barycentric coordinates for triangular ones, supporting applications in rendering, font design, and parametric modeling.[4]
Key attributes of de Casteljau's algorithm include its affine invariance, ensuring transformations like translation and rotation preserve the curve shape, and the convex hull property, whereby the curve lies entirely within the convex hull of its control points.[2] It provides endpoint interpolation, with tangents derivable from adjacent control segments (e.g., the tangent at P_0 aligns with P_0 P_1), and exhibits numerical stability due to its reliance on simple linear operations rather than high-degree polynomial arithmetic.[1] These features have made it indispensable in modern graphics software, such as PostScript and SVG standards, and continue to underpin extensions like polar forms and blossoms for advanced curve manipulation in CAGD.[2]
Overview
Definition
De Casteljau's algorithm is a recursive numerical procedure for evaluating points on Bézier curves through successive linear interpolations, serving as a stable alternative to direct polynomial evaluation.[5] Developed as a barycentric method, it computes a specific point on a Bézier curve of degree n at a parameter t \in [0,1] by iteratively combining the curve's control points. This approach ensures the resulting point lies precisely on the curve while maintaining geometric intuition and avoiding numerical instabilities common in explicit polynomial expansions.[5]
The algorithm initiates with the ordered set of control points P_0, P_1, \dots, P_n that define the Bézier curve. It then performs repeated interpolations between consecutive points, weighted by t and $1-t, which systematically reduces the effective degree at each step—from n down to a single point representing the curve evaluation at t. This iterative barycentric combination process leverages the convex hull properties of the control points to produce smooth, aesthetically controlled curve segments suitable for applications in computer-aided design.[5]
One primary advantage of De Casteljau's algorithm is its ability to facilitate curve subdivision and point evaluation without deriving or storing the full polynomial equation of the Bézier curve, thereby enhancing computational efficiency and enabling seamless refinement in design workflows.[5] This geometric recursion also supports extensions to higher-dimensional surfaces and derivative computations, underscoring its foundational role in parametric curve modeling.
Historical development
Paul de Casteljau developed the algorithm in 1959 while employed at the French automaker Citroën, where he began work on April 1, 1958, in the company's laboratory focused on machining and design processes.[6] His invention addressed challenges in automotive bodywork design, aiming to mathematically define smooth curves and surfaces with precision exceeding traditional manual methods like French curves.[6] Initially constrained by the computational capabilities of the era, de Casteljau's approach drew inspiration from mechanical analogs such as cams and projective geometry to facilitate numerically controlled milling for car parts, enabling the creation of complex shapes in automotive prototypes and designs.[7][6]
De Casteljau's work remained internal to Citroën, documented first in the company's 1958 annual activity report and formalized in a 1959 Enveloppe Soleau registration (No. 40.040) in March at the Institut National de la Propriété Industrielle (INPI) in Paris, followed by a more detailed internal report in 1963.[7][6] Due to Citroën's policy of secrecy for competitive advantage, the algorithm was not publicly disclosed during this period, limiting its immediate dissemination despite early applications in machined prototypes by 1960.[8] This internal focus contrasted with broader industry needs but laid the groundwork for computational curve design in manufacturing.
Independently, Pierre Bézier at rival automaker Renault developed a similar parametric curve representation in the early 1960s, which became known as Bézier curves and gained prominence through Bézier's publications starting in 1966.[7] De Casteljau's algorithm received its first public description in his 1985 book Formes à pôles, published by Hermès, where he introduced related concepts like polar forms or blossoms, marking the broader academic recognition of his contributions decades after invention.[7][6]
The algorithm's influence extended to the foundations of computer-aided design (CAD) systems in the 1960s and 1970s, powering tools like Renault's UNISURF and later Dassault's CATIA for precise surface modeling in automotive and aerospace industries.[8] It proved essential for extensions to rational curves in the 1980s, as explored by researchers like Gerald Farin, and contributed to the development of non-uniform rational B-splines (NURBS) in the late 1970s, standardizing spline-based representations in modern CAD/CAM software.[8][7]
Mathematical Background
Bézier curves
A Bézier curve of degree n is a parametric polynomial curve defined by a set of n+1 control points P_0, P_1, \dots, P_n in the plane or space, expressed as
\mathbf{B}(t) = \sum_{i=0}^n \binom{n}{i} (1-t)^{n-i} t^i \mathbf{P}_i, \quad t \in [0,1].
This formulation weights each control point by a binomial coefficient and powers of t and $1-t, ensuring the curve traces a smooth path from start to end as t varies from 0 to 1.[9]
Bézier curves possess several key geometric properties that make them suitable for design applications. They exhibit endpoint interpolation, passing exactly through the first control point \mathbf{B}(0) = \mathbf{P}_0 and the last \mathbf{B}(1) = \mathbf{P}_n.[9] The curve is contained within the convex hull of its control points, meaning it lies entirely inside the smallest convex polygon formed by connecting the \mathbf{P}_i.[9] Additionally, Bézier curves are affine invariant: applying an affine transformation (such as translation, rotation, scaling, or shearing) to the control points yields the same transformation on the curve.[10] They also satisfy the variation diminishing property, where the number of times the curve crosses any straight line does not exceed the number of times the control polygon crosses it, preventing excessive oscillations.[11]
In computer-aided design and graphics, Bézier curves are widely used to model smooth contours. TrueType fonts, for instance, employ quadratic Bézier curves (degree 2) to define glyph outlines, allowing scalable rendering without aliasing.[12] They form the basis for paths in vector graphics standards like SVG, enabling precise, resolution-independent representations of illustrations and icons.[13] In animation, Bézier curves define easing functions and motion paths, providing intuitive control over acceleration and deceleration in keyframe transitions.[14] De Casteljau's algorithm serves as the primary method for evaluating these curves at specific parameter values.
Bernstein basis polynomials
The Bernstein basis polynomials of degree n, denoted B_{i,n}(t) for i = 0, 1, \dots, n, are defined as
B_{i,n}(t) = \binom{n}{i} t^i (1-t)^{n-i},
where t \in [0,1] and \binom{n}{i} is the binomial coefficient. These polynomials form a basis for the vector space of all polynomials of degree at most n on the interval [0,1], as any such polynomial can be uniquely expressed as a linear combination of them. Introduced by Sergei Natanovich Bernstein in 1912 as part of a constructive proof of the Weierstrass approximation theorem, they provide a stable representation for function approximation due to their inherent properties.[15][16][17]
Key properties of the Bernstein basis polynomials include non-negativity, partition of unity, and a recursion relation. Non-negativity holds because B_{i,n}(t) \geq 0 for all t \in [0,1] and $0 \leq i \leq n, since the binomial coefficients are positive and the powers of t and $1-t are non-negative in this interval. The partition of unity property ensures that
\sum_{i=0}^n B_{i,n}(t) = 1
for all t \in [0,1], which follows from the binomial theorem applied to (t + (1-t))^n = 1^n = 1. Additionally, they satisfy the recursion relation
B_{i,n}(t) = (1-t) B_{i,n-1}(t) + t B_{i+1,n-1}(t),
with boundary conditions B_{i,n}(t) = 0 if i < 0 or i > n; this relation allows efficient computation by building higher-degree polynomials from lower ones. These properties collectively ensure the basis is well-suited for applications requiring convex combinations and stability.[18][16][17]
In the context of De Casteljau's algorithm, the recursion relation of the Bernstein basis polynomials directly mirrors the iterative interpolation steps used to evaluate points on Bézier curves. Each step in the algorithm performs a convex combination analogous to the recursion, leveraging the non-negativity and partition of unity to maintain geometric invariance and numerical stability during the computation. This structural similarity underpins the algorithm's efficiency in generating curve points without explicitly forming the full polynomial expression.[17]
Algorithm Description
Notation and setup
De Casteljau's algorithm evaluates points on a Bézier curve of degree n, defined by n+1 control points denoted as P_0, P_1, \dots, P_n, where each P_i is a point in \mathbb{R}^d to support multivariate coordinates such as 2D or 3D vectors. The algorithm uses a parameter t \in [0, 1] to determine the position along the curve. Intermediate points, required for the recursive computation, are denoted as \mathbf{P}_{i,k} for each level k = 1, \dots, n and index i = 0, \dots, n - k, formed through linear combinations of the control and prior intermediate points.
Recursive evaluation steps
De Casteljau's algorithm evaluates a point on a Bézier curve of degree n defined by control points P_0, P_1, \dots, P_n at a parameter t \in [0, 1] through a series of iterative linear interpolations.[1] The process initializes with the zeroth-level points P_{i,0} = P_i for i = 0, 1, \dots, n. For each level k = 1, 2, \dots, n, new points are computed recursively as
P_{i,k} = (1 - t) P_{i,k-1} + t P_{i+1,k-1}, \quad i = 0, 1, \dots, n - k.
This formula applies barycentric combinations to adjacent points from the previous level, generating n - k + 1 points at level k.[1]
The algorithm proceeds iteratively across n levels, progressively reducing the number of points: starting from n+1 initial points, each level yields one fewer point until a single point remains at level n. This constructs a triangular array of intermediate points, often visualized as building a pyramid that converges to the curve point. The final output is the Bézier curve point B(t) = P_{0,n}.[1]
A key application of the recursion arises in subdivision, where evaluating at t = 0.5 splits the curve into two degree-n Bézier segments; the intermediate points along the "upper" path form the control polygon for the left subcurve from t=0 to t=0.5, while those along the "lower" path define the right subcurve from t=0.5 to t=1. This enables recursive refinement for curve rendering or approximation without altering the overall curve.[19]
Geometric interpretation
De Casteljau's algorithm provides a geometric interpretation of Bézier curve evaluation as a sequence of linear interpolations between control points, offering an intuitive visualization of how the curve is constructed.[1] Each step involves computing points that divide line segments connecting adjacent control points in a fixed ratio determined by the parameter t, effectively blending the positions progressively.[20] This process forms intermediate polylines at each level, starting from the initial control polygon and refining toward the desired curve point.
The algorithm's structure manifests as a pyramid or trellis of these polylines, with the control points forming the broad base and successive interpolations narrowing the figure until it converges to a single point on the curve.[1] Visually, this pyramid illustrates the curve's smoothness, as the intermediate levels represent lower-degree Bézier segments that smoothly transition, emphasizing the recursive refinement inherent in the evaluation process.[20]
A key intuitive benefit of this geometric view is its revelation of why the Bézier curve lies entirely within the convex hull of the control points, achieved through the use of convex combinations in the interpolations without needing to evaluate the full polynomial expression.[1] This property ensures the curve remains bounded by the control polygon, aiding in design and rendering applications.[20]
Properties and Analysis
Computational complexity
De Casteljau's algorithm requires O(n²) time to evaluate a Bézier curve of degree n, as it performs n(n+1)/2 linear interpolations across the recursive levels of the triangular array.[21] This quadratic complexity stems from the nested structure of the evaluation steps, where each level reduces the number of points by one through pairwise convex combinations.[22]
In terms of space, the algorithm demands O(n²) storage if the full triangular array of intermediate points is retained for subsequent operations like subdivision.[22] However, practical implementations can achieve O(n) space complexity by overwriting the control points in place during the recursion, reusing a single array of size n+1.[22]
Relative to explicit evaluation via binomial expansion of the Bernstein basis polynomials, which naively computes O(n²) terms including potentially large binomial coefficients, De Casteljau's approach is more efficient for high degrees n, as it avoids explicit coefficient calculations and relies solely on linear interpolations. The algorithm's structure also supports efficient curve subdivision, leveraging the intermediates to generate subcurves in the same O(n²) pass.
Numerical stability
De Casteljau's algorithm exhibits strong numerical stability primarily because it relies exclusively on convex combinations of control points, involving only additions and scalar multiplications by parameters t and $1-t, thereby avoiding the computation of high-degree powers of t or binomial coefficients that can lead to overflow or underflow in direct polynomial evaluation methods.[23][5][22] This approach ensures that intermediate values remain bounded within the convex hull of the control points, minimizing the propagation of rounding errors throughout the recursion.[23]
In terms of error propagation, the recursive nature of the algorithm causes any initial floating-point errors to diminish with each subdivision step, as the convex combinations progressively average out perturbations and reduce their relative impact on the final curve point.[24] This property makes it better conditioned than Horner's method for evaluating Bernstein polynomials, particularly for parameter values t near 0.5, where Horner's scheme can amplify errors due to nested multiplications; numerical experiments confirm that de Casteljau's forward error bounds are sharper in such cases.[25][26] Within the interval [0, 1], the algorithm is unconditionally stable, with relative errors proportional to the condition number of the evaluation problem.[27][28]
Overall, the algorithm's preservation of affine invariance—stemming directly from its composition of linear interpolations—renders it particularly superior for computer-aided design (CAD) applications, where maintaining geometric properties under transformations is essential for reliable curve modeling and subdivision.[23][4][24]
Examples
Quadratic Bézier curve
A quadratic Bézier curve is defined by three control points P_0, P_1, and P_2, and De Casteljau's algorithm evaluates a point on this curve at a parameter t \in [0, 1] through successive linear interpolations.[5]
The process begins by computing the first-level intermediate points:
\begin{align*}
Q_0 &= (1 - t) P_0 + t P_1, \\
Q_1 &= (1 - t) P_1 + t P_2.
\end{align*}
These points lie on the line segments connecting the control points.[29]
The curve point B(t) is then found by linear interpolation between Q_0 and Q_1:
B(t) = (1 - t) Q_0 + t Q_1.
Substituting the expressions for Q_0 and Q_1 yields the explicit quadratic form B(t) = (1 - t)^2 P_0 + 2t(1 - t) P_1 + t^2 P_2, but the algorithm computes it via the geometric steps for stability.[5]
This two-step recursion specializes the general recursive evaluation procedure to degree 2.[29]
For a numerical illustration, consider control points P_0 = (0, 0), P_1 = (1, 1), P_2 = (2, 0), and t = 0.5.
The intermediate points are Q_0 = 0.5 (0, 0) + 0.5 (1, 1) = (0.5, 0.5) and Q_1 = 0.5 (1, 1) + 0.5 (2, 0) = (1.5, 0.5).[29]
Thus, B(0.5) = 0.5 (0.5, 0.5) + 0.5 (1.5, 0.5) = (1, 0.5).
Cubic Bézier curve application
De Casteljau's algorithm applied to a cubic Bézier curve, defined by four control points \mathbf{P}_0, \mathbf{P}_1, \mathbf{P}_2, \mathbf{P}_3, evaluates the curve point \mathbf{B}(t) at parameter t \in [0, 1] through a series of linear interpolations across three levels, leveraging the recursive structure inherent to degree-3 polynomials.[30] This multi-level process highlights the algorithm's geometric interpretability, where each interpolation step refines intermediate points toward the final curve position.[20]
In the first level, compute the intermediate points:
\mathbf{Q}_0 = (1-t) \mathbf{P}_0 + t \mathbf{P}_1, \quad \mathbf{Q}_1 = (1-t) \mathbf{P}_1 + t \mathbf{P}_2, \quad \mathbf{Q}_2 = (1-t) \mathbf{P}_2 + t \mathbf{P}_3.
These represent linear interpolations between consecutive control points, forming a quadratic Bézier-like structure from the original cubic setup.[30]
The second level further interpolates among these points:
\mathbf{R}_0 = (1-t) \mathbf{Q}_0 + t \mathbf{Q}_1, \quad \mathbf{R}_1 = (1-t) \mathbf{Q}_1 + t \mathbf{Q}_2.
This step reduces the degree to linear, bridging the intermediate quadratic layer.[20]
The final curve point is obtained by:
\mathbf{B}(t) = (1-t) \mathbf{R}_0 + t \mathbf{R}_1.
This yields the exact position on the cubic Bézier curve at t, preserving the curve's smoothness and endpoint interpolation properties.[30]
To demonstrate, consider control points \mathbf{P}_0 = (0,0), \mathbf{P}_1 = (1,2), \mathbf{P}_2 = (2,0), \mathbf{P}_3 = (3,1) and t = 0.25 (so $1-t = 0.75).[20]
First level:
\mathbf{Q}_0 = 0.75 \cdot (0,0) + 0.25 \cdot (1,2) = (0.25, 0.5),
\mathbf{Q}_1 = 0.75 \cdot (1,2) + 0.25 \cdot (2,0) = (1.25, 1.5),
\mathbf{Q}_2 = 0.75 \cdot (2,0) + 0.25 \cdot (3,1) = (2.25, 0.25).
Second level:
\mathbf{R}_0 = 0.75 \cdot (0.25, 0.5) + 0.25 \cdot (1.25, 1.5) = (0.5, 0.75),
\mathbf{R}_1 = 0.75 \cdot (1.25, 1.5) + 0.25 \cdot (2.25, 0.25) = (1.5, 1.1875).
Final point:
\mathbf{B}(0.25) = 0.75 \cdot (0.5, 0.75) + 0.25 \cdot (1.5, 1.1875) = (0.75, 0.859375).
This computation traces the algorithm's path from control points to the curve, illustrating its utility in applications like vector graphics where cubic Béziers model smooth paths.[30]
Implementations
Pseudocode
De Casteljau's algorithm evaluates a point on a Bézier curve of degree n given an array of n+1 control points and a parameter t \in [0, 1]. The input consists of the control points P = [P_0, P_1, \dots, P_n], where each P_i is a point in space (e.g., 2D or 3D coordinates), and the scalar t. The output is the point B(t) on the Bézier curve at parameter t.[1][5]
This iterative procedure mirrors the recursive evaluation steps by building intermediate points through successive linear interpolations, avoiding the exponential complexity of naive recursion.[1]
The following pseudocode outlines the algorithm using a 2D array points to store intermediate results, where points[0] holds the initial control points:
function deCasteljau(P, n, t):
// Initialize 2D array: points[k][i] for level k = 0 to n, i = 0 to n-k
points = new array of size (n+1) x (n+1)
for i = 0 to n:
points[0][i] = P[i]
for k = 1 to n:
for i = 0 to n - k:
points[k][i] = (1 - t) * points[k-1][i] + t * points[k-1][i+1]
return points[n][0] // This is B(t)
function deCasteljau(P, n, t):
// Initialize 2D array: points[k][i] for level k = 0 to n, i = 0 to n-k
points = new array of size (n+1) x (n+1)
for i = 0 to n:
points[0][i] = P[i]
for k = 1 to n:
for i = 0 to n - k:
points[k][i] = (1 - t) * points[k-1][i] + t * points[k-1][i+1]
return points[n][0] // This is B(t)
To optimize space usage, the algorithm can be implemented in-place by updating a single array of size n+1, overwriting earlier points as new ones are computed, since previous levels are no longer needed after each iteration. This reduces memory from O(n^2) to O(n).[1][5]
Python implementation
A Python implementation of De Casteljau's algorithm leverages NumPy for vectorized operations on control points in multiple dimensions, providing an efficient way to evaluate Bézier curves at a given parameter t \in [0, 1]. The function takes control points as a NumPy array of shape (n, d), where n is the degree plus one (number of points) and d is the dimensionality (e.g., 2 for 2D, 3 for 3D), and returns the point on the curve as a 1D array of length d. This iterative approach avoids recursion for better performance and numerical stability, following the standard procedure described in foundational CAGD literature.
python
import numpy as np
def de_casteljau(control_points, t):
"""
Evaluate a [Bézier curve](/page/Bézier_curve) at parameter t using De Casteljau's algorithm.
Parameters:
- control_points: np.ndarray of shape (n, d), where n is the number of control points,
d is the dimension (e.g., 2 for [2D](/page/2D) points).
- t: float, parameter in [0, 1].
Returns:
- np.ndarray of shape (d,), the point on the curve.
"""
points = control_points.copy() # Avoid modifying input
n = len(points)
for k in range(1, n):
for i in range(n - k):
points[i] = (1 - t) * points[i] + t * points[i + 1]
return points[0]
import numpy as np
def de_casteljau(control_points, t):
"""
Evaluate a [Bézier curve](/page/Bézier_curve) at parameter t using De Casteljau's algorithm.
Parameters:
- control_points: np.ndarray of shape (n, d), where n is the number of control points,
d is the dimension (e.g., 2 for [2D](/page/2D) points).
- t: float, parameter in [0, 1].
Returns:
- np.ndarray of shape (d,), the point on the curve.
"""
points = control_points.copy() # Avoid modifying input
n = len(points)
for k in range(1, n):
for i in range(n - k):
points[i] = (1 - t) * points[i] + t * points[i + 1]
return points[0]
This implementation is based on the generic pseudocode for the algorithm and is optimized for scientific computing environments. To visualize the curve, evaluate the function over a range of t values and plot the results using Matplotlib, for example, by generating points with np.linspace(0, 1, 100) and connecting them.
JavaScript example
A JavaScript implementation of De Casteljau's algorithm provides an efficient way to evaluate points on Bézier curves for dynamic web visualizations, such as animations or interactive graphics in browsers. The algorithm iteratively applies linear interpolations between control points to compute the curve position at a given parameter t (where $0 \leq t \leq 1). This approach is particularly useful for client-side rendering on HTML5 Canvas or SVG, enabling smooth curve generation without server dependencies.[31]
To handle 2D points, control points are represented as arrays of the form [x, y], where x and y are numeric coordinates. A helper function for linear interpolation (lerp) is required to perform component-wise operations on these arrays:
javascript
function [lerp](/page/Lerp)(p0, p1, t) {
return [
(1 - t) * p0[0] + t * p1[0],
(1 - t) * p0[1] + t * p1[1]
];
}
function [lerp](/page/Lerp)(p0, p1, t) {
return [
(1 - t) * p0[0] + t * p1[0],
(1 - t) * p0[1] + t * p1[1]
];
}
The core evaluation function, adapted from standard pseudocode, iteratively reduces the set of points through repeated lerping until a single point remains:[27]
javascript
function deCasteljau(points, t) {
let [current](/page/Current) = points.map(p => [...p]); // Deep copy to avoid [mutation](/page/Mutation)
for (let k = 1; k < points.length; k++) {
let temp = [];
for (let i = 0; i < [current](/page/Current).length - 1; i++) {
temp.push([lerp](/page/Lerp)([current](/page/Current)[i], [current](/page/Current)[i + 1], t));
}
[current](/page/Current) = temp;
}
return [current](/page/Current)[0];
}
function deCasteljau(points, t) {
let [current](/page/Current) = points.map(p => [...p]); // Deep copy to avoid [mutation](/page/Mutation)
for (let k = 1; k < points.length; k++) {
let temp = [];
for (let i = 0; i < [current](/page/Current).length - 1; i++) {
temp.push([lerp](/page/Lerp)([current](/page/Current)[i], [current](/page/Current)[i + 1], t));
}
[current](/page/Current) = temp;
}
return [current](/page/Current)[0];
}
For example, to draw a quadratic Bézier curve on an HTML5 Canvas, obtain a 2D rendering context and loop over discrete t values, computing and plotting points with lineTo or moveTo:
javascript
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
const controlPoints = [[100, 100], [200, 50], [300, 100]]; // Example [quadratic](/page/Quadratic) curve points
ctx.beginPath();
ctx.moveTo(controlPoints[0][0], controlPoints[0][1]);
for (let t = 0; t <= 1; t += 0.01) {
const point = deCasteljau(controlPoints, t);
ctx.lineTo(point[0], point[1]);
}
ctx.stroke();
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
const controlPoints = [[100, 100], [200, 50], [300, 100]]; // Example [quadratic](/page/Quadratic) curve points
ctx.beginPath();
ctx.moveTo(controlPoints[0][0], controlPoints[0][1]);
for (let t = 0; t <= 1; t += 0.01) {
const point = deCasteljau(controlPoints, t);
ctx.lineTo(point[0], point[1]);
}
ctx.stroke();
This setup assumes the Canvas element is sized appropriately (e.g., 400x200 pixels) and styled for visibility. The loop generates approximately 100 points for a smooth approximation, scalable based on performance needs.
JavaScript's native handling of floating-point arithmetic ensures sufficient precision for most curve evaluations, as the algorithm avoids explicit polynomial expansions that could amplify rounding errors. No external libraries are required, making it compatible with all modern browsers supporting ES6 features like arrow functions and spread operators; for older environments, polyfills may be added.