Bézier curve (source code)

= Bézier curve
{c}
{title2=$C(t)=\sum_{i=0}^n\binom ni(1-t)^{n-i}t^iP_i$}
{wiki}

A <Bézier curve> is a <parametric curve> specified by <control points> $P_0,\ldots,P_n$ in a <Euclidean space> and the <Bernstein basis>:
$$
C(t)=\sum_{i=0}^n b_{i,n}(t)P_i,\qquad b_{i,n}(t)=\binom ni(1-t)^{n-i}t^i,\qquad 0\leq t\leq1.
$$
Here $\binom ni$ is a <binomial coefficient>. Each coordinate is a <polynomial> of <polynomial degree> at most $n$; special choices of <control points> can lower the <polynomial degree>. The ordered <control points> form the <control polygon>. A cubic <Bézier curve> uses four <control points> and has the explicit form
$$
C(t)=(1-t)^3P_0+3(1-t)^2tP_1+3(1-t)t^2P_2+t^3P_3.
$$
The curve passes through $P_0$ and $P_3$; the interior <control points> steer its shape and need not lie on it.https://ocw.mit.edu/courses/6-837-computer-graphics-fall-2012/aba8735cf2cf7c71ca5d29b46873309a_MIT6_837F12_Lec01.pdf[MIT 6.837, Bézier Curves and Splines, slides 23–31 and 45–47, 2012]{ref}

For a worked example, choose
$$
P_0=(0,0),\qquad P_1=(1,2),\qquad P_2=(3,2),\qquad P_3=(4,0).
$$
Substituting these <control points> gives
$$
C(t)=\bigl(3t+3t^2-2t^3,\;6t(1-t)\bigr),\qquad C(1/2)=\tfrac18P_0+\tfrac38P_1+\tfrac38P_2+\tfrac18P_3=(2,1.5).
$$
Here $y(t)=1.5-6(t-1/2)^2\leq1.5$, so neither interior <control point>, both at height $2$, lies on the curve. <De Casteljau's algorithm> computes the same point using only successive <linear interpolations>.

The endpoint <tangent vectors> follow from the <Bézier derivative control polygon>:
$$
C'(0)=3(P_1-P_0)=(3,6),\qquad C'(1)=3(P_3-P_2)=(3,-6).
$$
Thus the curve leaves $P_0$ toward $P_1$ and arrives at $P_3$ from $P_2$. These nonzero <derivatives> determine the endpoint <tangent lines>; if an endpoint <derivative> vanishes, that formula alone does not determine its tangent direction. Endpoint handles are useful when arranging a <parametric first-derivative join of Bézier curves>.

The parameter $t$ is usually not <arc length>. For this example,
$$
C'(t)=\bigl(3+6t-6t^2,\;6-12t\bigr),\qquad \|C'(0)\|=\sqrt{45},\qquad \|C'(1/2)\|=4.5.
$$
Equal steps in $t$ therefore do not generally travel equal distances. Distance along the curve is instead the <arc length>, given by the <integral> $s(t)=\int_0^t\|C'(u)\|\,du$; its <derivative> is the <norm> of the <tangent vector> and measures the rate of travel.

Two geometric facts make <Bézier curves> especially convenient for design. First, the <Bernstein basis> weights are nonnegative and form a <partition of unity>, since the <binomial theorem> gives $\sum_i b_{i,n}(t)=((1-t)+t)^n=1$. Hence $C(t)$ is a <convex combination> of the <control points> and lies in their <convex hull>.https://groups.csail.mit.edu/graphics/classes/6.838/S98/meetings/m15/[MIT 6.838, Bézier Curve and B-Spline Curve, §1.4.1, 1998]{ref} The <convex hull> is the smallest <convex set> containing the <control points>, not their <axis-aligned bounding box>. Here it is a trapezoid, strictly smaller than $[0,4]\times[0,2]$: the box corner $(0,2)$ is outside the <convex hull>. The curve need not fill or touch every edge of either enclosure. The <convex hull> guarantee concerns $0\leq t\leq1$; outside that interval weights can be negative.

Second, applying an <affine map> to every <control point> gives exactly the same result as applying it to the entire curve. For $T(x)=Ax+b$,
$$
\sum_i b_{i,n}(t)T(P_i)=A\sum_i b_{i,n}(t)P_i+b\sum_i b_{i,n}(t)=T(C(t)).
$$
This is <affine equivariance of a geometric basis>: a <translation>, <rotation> or <shear mapping> can be performed on a handful of <control points>. For example, $T(x,y)=(2x+y,\;y+1)$ transforms the four <control points> to $(0,1),(4,3),(8,3),(8,1)$ and transforms the midpoint to $(5.5,2.5)$, also obtained from the same weights $(1,3,3,1)/8$.

These editable handles explain the usefulness of <Bézier curves> in <computer aided geometric design>, <vector graphics> paths and <outline fonts>: a small collection of points controls an entire smooth stroke, and resizing the design preserves its mathematical shape. Cambridge's computer-graphics notes describe their use in graphic design, typography and PostScript outlines. The industrial context includes Pierre Bézier's work at Renault and Paul de Casteljau's work at Citroën.https://www.cl.cam.ac.uk/teaching/1415/CompGraph/cgip.pdf[Neil A. Dodgson and Peter Robinson, Cambridge Computer Graphics and Image Processing, slides 183 and 226–228, 2014]{ref}

// Target: analysis.bigb