In general, the $nth$-degree Bézier curve is defined as: $$\vec{C}(u)=\sum_{i=0}^{n} B_{i,n}(u) \vec{P_i} \qquad 0\leq u\leq1$$
where $B_{i,n}(u)$ is the classical Bernstein polynomial, $$B_{i,n}(u)=\frac{n!}{i!(n-i)!}u^i(1-u)^{n-i}$$
$\vec{P_i}$ is the control point.
I have written a function to plot these curves:
Trial 1
bezierPlot1[n_, pts : {{_, _} ..}, opts : OptionsPattern[Plot]]:=
ParametricPlot[
Total@Table[
BernsteinBasis[n, i, u] # & /@ pts, {i, 0, n}], {u, 0, 1}]
pts = {{0, 0}, {2, 4}, {4, 5}, {6, 0}};
bezierPlot1[3,pts]
It failed; that is, no graphics appeared.
Trial 2
I replaced the built-in function BernsteinBasis
with $\frac{n!}{i! (n - i)!} u^i(1 - u)^{n - i}$
bezierPlot2[n_, pts : {{_, _} ..}, u_, opts : OptionsPattern[Plot]] :=
ParametricPlot[
Total@Table[
n!/(i! (n - i)!) u^i (1 - u)^(n - i) # & /@ pts, {i, 0, n}] /.
u -> x, {x, 0, 1}]
bezierPlot2[3, pts, u]
It failed
Lastly, I know that Mathematica has the built-in function BezierCurve
:
Graphics[{BezierCurve[pts], Green, Line[pts], Red, Point[pts]}]
So my question is, how do I make my bezierPlot
work normally?