0
$\begingroup$

How to generate a Bézier curve using 4 points(arbitrary), without using the built-in function of Mathematica?

The main point is that we do not use the built-in function in Mathematica, instead use a step-by-step program to solve it?

$\endgroup$
4
$\begingroup$

Using cubic Bernstein polynomials, the Bézier curve of the points {p1, p2, p3, p4} is:

{(1 - u)^3, 3 u (1 - u)^2, 3 u^2 (1 - u), u^3}.{p1, p2, p3, p4} (* 0 < u < 1*)
$\endgroup$
2
$\begingroup$

The Bernstein polynomials mentioned by Ulrich are in fact built-in as BernsteinBasis[].

For instance:

PiecewiseExpand[BernsteinBasis[3, Range[0, 3], u], 0 < u < 1]
   {(1 - u)^3, 3 (1 - u)^2 u, 3 (1 - u) u^2, u^3}

Here is a short demo showing the equivalence of using BezierCurve[] directly with a construction using BernsteinBasis[]:

DynamicModule[{pts = {{0, 0}, {1, 1}, {2, 0}, {3, 2}}}, 
              LocatorPane[Dynamic[pts], 
                          Dynamic[With[{d = Length[pts] - 1}, 
                                       ParametricPlot[BernsteinBasis[d, Range[0, d], t].pts,
                                                      {t, 0, 1}, Axes -> None, Frame -> True, 
                                                      Prolog -> {ColorData[97, 2],
                                                                 AbsoluteThickness[4], 
                                                                 BezierCurve[pts,
                                                                             SplineDegree -> d]},
                                                      PlotRange -> 4]]], LocatorAutoCreate -> True]]

Bézier demo

Use Alt+click to add control points for the Bézier curve.

$\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.