6

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?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Igor
  • 303
  • 1
  • 6

1 Answers1

6

(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

kglr
  • 394,356
  • 18
  • 477
  • 896