5
$\begingroup$

I would like to use BezierCurve with npts=7 and SplineDegree -> 3 and access its BezierFunction. This code helps:

pts = {{0, 0}, {1, 1}, {2, -1}, {3, 0}, {5, 2}, {6, -1}, {7, 3}};
f1 = BezierFunction[pts[[1;;4]]]
f2 = BezierFunction[pts[[4;;7]]]
Show[Graphics[{Red, Point[pts], Green, Line[pts]}, Axes -> True], 
ParametricPlot[{f1[t],f2[t]}, {t, 0, 1}],Graphics[{Blue, Dashed, 
BezierCurve[pts, SplineDegree -> 3]}]]

coincide

Can it be done better, defining f as a single function, whose plot is BezierCurve?

$\endgroup$
5
$\begingroup$

(1) Partition pts into blocks of 4 with offset 3,

(2) Use BezierFunction on each block and

(3) To get a single function, compose Through with the list of Bezier functions.

pts = {{0, 0}, {1, 1}, {2, -1}, {3, 0}, {5, 2}, {6, -1}, {7, 3}};
f0 = Through @* (BezierFunction /@ Partition[pts, 4, 3]);

Show[Graphics[{Red, Point[pts], Green, Line[pts]}, Axes -> True], 
 ParametricPlot[f0[t], {t, 0, 1}, PlotStyle -> Directive[Opacity[.7, Red], Thickness[.01]]],
 Graphics[{Blue, Dashed, BezierCurve[pts, SplineDegree -> 3]}]]

enter image description here

$\endgroup$
  • $\begingroup$ Perfect! Many thanks. $\endgroup$ – Igor Aug 5 at 16:35
  • $\begingroup$ Igor, you are welcome. And welcome to mma.se. Please consider upvoting (by clicking the triangles) the questions/answers you like and accepting the answer, if any, that solves your problem, by clicking the checkmark sign. $\endgroup$ – kglr Aug 5 at 17:03

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.