HOME

TheInfoList



OR:

In the
mathematical Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
field of
numerical analysis Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic computation, symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of ...
, De Casteljau's algorithm is a
recursive Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
method to evaluate polynomials in
Bernstein form In the mathematical field of numerical analysis, a Bernstein polynomial is a polynomial expressed as a linear combination of Bernstein basis polynomials. The idea is named after mathematician Sergei Natanovich Bernstein. Polynomials in Bernste ...
or
Bézier curve A Bézier curve ( , ) is a parametric equation, parametric curve used in computer graphics and related fields. A set of discrete "control points" defines a smooth, continuous curve by means of a formula. Usually the curve is intended to approxima ...
s, named after its inventor
Paul de Casteljau Paul de Casteljau (19 November 1930 – 24 March 2022) was a French physicist and mathematician. In 1959, while working at Citroën, he developed an algorithm for evaluating calculations on a certain family of curves, which would later be formali ...
. De Casteljau's algorithm can also be used to split a single Bézier curve into two Bézier curves at an arbitrary parameter value. The algorithm is numerically stable when compared to direct evaluation of polynomials. The computational complexity of this algorithm is O(d n^2), where d is the number of dimensions, and n is the number of control points. There exist faster alternatives.


Definition

A Bézier curve B (of degree n, with control points \beta_0, \ldots, \beta_n) can be written in Bernstein form as follows B(t) = \sum_^\beta_b_(t), where b is a Bernstein basis polynomial b_(t) = (1-t)^t^i. The curve at point t_0 can be evaluated with the
recurrence relation In mathematics, a recurrence relation is an equation according to which the nth term of a sequence of numbers is equal to some combination of the previous terms. Often, only k previous terms of the sequence appear in the equation, for a parameter ...
\begin \beta_i^ &:= \beta_i, && i=0,\ldots,n \\ \beta_i^ &:= \beta_i^ (1-t_0) + \beta_^ t_0, && i = 0,\ldots,n-j,\ \ j= 1,\ldots,n \end Then, the evaluation of B at point t_0 can be evaluated in \binom operations. The result B(t_0) is given by B(t_0) = \beta_0^. Moreover, the Bézier curve B can be split at point t_0 into two curves with respective control points: \begin &\beta_0^,\beta_0^,\ldots,\beta_0^ \\ ex&\beta_0^,\beta_1^,\ldots,\beta_n^ \end


Geometric interpretation

The geometric interpretation of De Casteljau's algorithm is straightforward. *Consider a Bézier curve with control points P_0, \dots, P_n. Connecting the consecutive points we create the control polygon of the curve. *Subdivide now each line segment of this polygon with the ratio t : (1-t) and connect the points you get. This way you arrive at the new polygon having one fewer segment. *Repeat the process until you arrive at the single point – this is the point of the curve corresponding to the parameter t. The following picture shows this process for a cubic Bézier curve: Note that the intermediate points that were constructed are in fact the control points for two new Bézier curves, both exactly coincident with the old one. This algorithm not only evaluates the curve at t, but splits the curve into two pieces at t, and provides the equations of the two sub-curves in Bézier form. The interpretation given above is valid for a nonrational Bézier curve. To evaluate a rational Bézier curve in \mathbf^n, we may project the point into \mathbf^; for example, a curve in three dimensions may have its control points \ and weights \ projected to the weighted control points \. The algorithm then proceeds as usual, interpolating in \mathbf^4. The resulting four-dimensional points may be projected back into three-space with a perspective divide. In general, operations on a rational curve (or surface) are equivalent to operations on a nonrational curve in a
projective space In mathematics, the concept of a projective space originated from the visual effect of perspective, where parallel lines seem to meet ''at infinity''. A projective space may thus be viewed as the extension of a Euclidean space, or, more generally ...
. This representation as the "weighted control points" and weights is often convenient when evaluating rational curves.


Notation

When doing the calculation by hand it is useful to write down the coefficients in a triangle scheme as \begin \beta_0 & = \beta_0^ & & & \\ & & \beta_0^ & & \\ \beta_1 & = \beta_1^ & & & \\ & & & \ddots & \\ \vdots & & \vdots & & \beta_0^ \\ & & & & \\ \beta_ & = \beta_^ & & & \\ & & \beta_^ & & \\ \beta_n & = \beta_n^ & & & \\ \end When choosing a point ''t''0 to evaluate a Bernstein polynomial we can use the two diagonals of the triangle scheme to construct a division of the polynomial B(t) = \sum_^n \beta_i^ b_(t), \quad t \in ,1/math> into B_1(t) = \sum_^n \beta_0^ b_\left(\frac\right)\!, \quad t \in ,t_0/math> and B_2(t) = \sum_^n \beta_i^ b_\left(\frac\right)\!, \quad t \in _0,1


Bézier curve

When evaluating a Bézier curve of degree ''n'' in 3-dimensional space with ''n'' + 1 control points P''i'' \mathbf(t) = \sum_^ \mathbf_i b_(t),\ t \in ,1/math> with \mathbf_i := \begin x_i \\ y_i \\ z_i \end, we split the Bézier curve into three separate equations \begin B_1(t) &= \sum_^ x_i b_(t), & t \in ,1\\ exB_2(t) &= \sum_^ y_i b_(t), & t \in ,1\\ exB_3(t) &= \sum_^ z_i b_(t), & t \in ,1\end which we evaluate individually using De Casteljau's algorithm.


Example

We want to evaluate the Bernstein polynomial of degree 2 with the Bernstein coefficients \begin \beta_0^ &= \beta_0 \\ ex\beta_1^ &= \beta_1 \\ ex\beta_2^ &= \beta_2 \end at the point ''t''0. We start the recursion with \begin \beta_0^ &&=&& \beta_0^ (1-t_0) + \beta_1^t_0 &&=&& \beta_0(1-t_0) + \beta_1 t_0 \\ ex\beta_1^ &&=&& \beta_1^ (1-t_0) + \beta_2^t_0 &&=&& \beta_1(1-t_0) + \beta_2 t_0 \end and with the second iteration the recursion stops with \begin \beta_0^ & = \beta_0^ (1-t_0) + \beta_1^ t_0 \\ \ & = \beta_0(1-t_0) (1-t_0) + \beta_1 t_0 (1-t_0) + \beta_1(1-t_0)t_0 + \beta_2 t_0 t_0 \\ \ & = \beta_0 (1-t_0)^2 + \beta_1 2t_0(1-t_0) + \beta_2 t_0^2 \end which is the expected Bernstein polynomial of degree ''2''.


Implementations

Here are example implementations of De Casteljau's algorithm in various programming languages.


Haskell Haskell () is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell pioneered several programming language ...

deCasteljau :: Double -> Double, Double)-> (Double, Double) deCasteljau t = b deCasteljau t coefs = deCasteljau t reduced where reduced = zipWith (lerpP t) coefs (tail coefs) lerpP t (x0, y0) (x1, y1) = (lerp t x0 x1, lerp t y0 y1) lerp t a b = t * b + (1 - t) * a


Python

def de_casteljau(t: float, coefs: list loat -> float: """De Casteljau's algorithm.""" beta = coefs.copy() # values in this list are overridden n = len(beta) for j in range(1, n): for k in range(n - j): beta = beta * (1 - t) + beta + 1* t return beta


Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...

public double deCasteljau(double t, double[] coefficients)


Code Example in JavaScript

The following JavaScript function applies De Casteljau's algorithm to an array of control points o
poles
as originally named by De Casteljau to reduce them one by one until reaching a point in the curve for a given t between 0 for the first point of the curve and 1 for the last one function crlPtReduceDeCasteljau(points, t) For example, var poles = [0, 128 [128, 0">[0,_128.html" ;"title="[0, 128">[0, 128 [128, 0 [256, 0">,_128">[0,_128<_a>_[128,_0.html" ;"title="[0,_128.html" ;"title="[0, 128">[0, 128 [128, 0">[0,_128.html" ;"title="[0, 128">[0, 128 [128, 0 [256, 0 [384, 128] ] crlPtReduceDeCasteljau (poles, .5) returns the array [ [0, 128 [128, 0">[0,_128.html" ;"title="[0, 128">[0, 128 [128, 0 [256, 0">,_128">[0,_128<_a>_[128,_0.html" ;"title="[0,_128.html" ;"title="[0, 128">[0, 128 [128, 0">[0,_128.html" ;"title="[0, 128">[0, 128 [128, 0 [256, 0 [384, 128 ] ], [ [64, 64], [192, 0], [320, 64] ], [ [128, 32], [256, 32, [ [192, 32, ] which yields the points and segments plotted below:


See also

* Bézier curves *
De Boor's algorithm In the mathematical subfield of numerical analysis, de Boor's algorithmC. de Boor 971 "Subroutine package for calculating with B-splines", Techn.Rep. LA-4728-MS, Los Alamos Sci.Lab, Los Alamos NM; p. 109, 121. is a polynomial-time and numericall ...
* Horner scheme to evaluate polynomials in monomial form * Clenshaw algorithm to evaluate polynomials in
Chebyshev form The Chebyshev polynomials are two sequences of orthogonal polynomials related to the cosine and sine functions, notated as T_n(x) and U_n(x). They can be defined in several equivalent ways, one of which starts with trigonometric functions: ...


References

*{{ cite book , last1 = Farin , first1 = Gerald E. , last2 = Hansford , first2 = Dianne , author2-link = Dianne Hansford , title = The Essentials of CAGD , date = 2000 , publisher = A.K. Peters , isbn = 978-1-56881-123-9 , location = Natick, MA


External links


Piecewise linear approximation of Bézier curves
– description of De Casteljau's algorithm, including a criterion to determine when to stop the recursion
Bézier Curves and Picasso
— Description and illustration of De Casteljau's algorithm applied to cubic Bézier curves.
de Casteljau's algorithm
- Implementation help and interactive demonstration of the algorithm. Splines (mathematics) Numerical analysis Articles with example Haskell code