3
$\begingroup$

The Bézier curve is defined by:

$$C(t)=\sum_{i=0}^{n} {{n}\choose{i}} t^i (1-t)^{n-i} P_i$$

where the $P_i$ are the control points.

I am trying to write it down in Mathematica. What I have is:

p0 = {0, 0};
p1 = {1, 1};
p2 = {2, 1};
p3 = {3, -1};
p = {p0, p1, p2, p3};

c[t_, n_] := \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 0\), \(n\)]\(Binomial[n, i] 
\*SuperscriptBox[\(t\), \(i\)] 
\*SuperscriptBox[\((1 - t)\), \(n - i\)] p[\([i]\)]\)\)

I can't manage to get a proper list for plotting. Can anyone please advise on how to correctly formulate the equations?

$\endgroup$
7
$\begingroup$

Here is how to manually implement a Bézier curve:

p = {{0, 0}, {1, 1}, {2, 1}, {3, -1}};
n = Length[p] - 1;

ParametricPlot[Sum[p[[i + 1]] Binomial[n, i] t^i (1 - t)^(n - i), {i, 0, n}] // Evaluate,
               {t, 0, 1}]

Bézier curve

To compare with the built-in:

Show[%, Prolog -> {Directive[AbsoluteThickness[4], ColorData[97, 2]], BezierCurve[p]}]

versus built-in version

$\endgroup$
1
$\begingroup$

An alternative is to use BezierFunction. Your example:

p = {{0,0},{1,1},{2,1},{3,-1}};

ParametricPlot[BezierFunction[p][t], {t, 0, 1}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.