8
$\begingroup$

given a list of points I've created a Bézier curve, and now I would like to understand how to extract a "middle point" from a curve or get a list of points (not the input ones, the interpolated ones)

Thank you all in advance!

$\endgroup$
3
  • 2
    $\begingroup$ Please can you include a simple example of what you have done using Mathematica code we can copy and work with? $\endgroup$
    – Hugh
    Commented Jul 27, 2021 at 16:41
  • 2
    $\begingroup$ You should use the BezierFunction[your_points][i], where i is parameter (in range 0-1) which is proportional to the path along your curve. $\endgroup$
    – Rom38
    Commented Jul 27, 2021 at 16:52
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Commented Jul 27, 2021 at 17:39

2 Answers 2

8
$\begingroup$
  • Here we provided an example which indicate that we can not directly use BezierFunction or BSplineFunction since it is different to BezierCurve.
pts = {{0, 0}, {1, -1}, {3, -1}, {3, 3}, {4, 1}, {5, 1}, {6, 0}};
a = Graphics[{BezierCurve[pts], Dotted, Line[pts], Red, Point[pts]}];
b = ParametricPlot[BezierFunction[pts[[1 ;; 4]]][t], {t, 0, 1}, 
   PlotStyle -> Yellow];
c = ParametricPlot[BezierFunction[pts[[4 ;; 7]]][t], {t, 0, 1}, 
   PlotStyle -> Green];
d = ParametricPlot[BezierFunction[pts[[1 ;; 7]]][t], {t, 0, 1}, 
   PlotStyle -> Red];
{Show[a, b, c, PlotRange -> All], Show[a, b, c, d, PlotRange -> All]}

enter image description here

The red one is BezierFunction and the yellow+green is the BezierCurve.

  • BezierCurve can be draw as the piecewise function of the BezierFunction. When the Length of the points is 4,3,2,1, the BezierCurve or BezierFunction is the usual 3-degree Bezier curve, 2-degree parabola, Line,Point respectly. We see this as below. ( We can change the value of k, and since BezierFunction does not accepct one point, so maybe have some warning message )
Clear["Global`*"];
bezierFunction[pts_][t_] := 
  Module[{n = Length@pts}, 
   Sum[BernsteinBasis[n - 1, i - 1, t]*pts[[i]], {i, 1, n}]];

pts = {{0, 0}, {1, -1}, {3, -1}, {3, 3}, {4, 1}, {5, 1}, {6, 0}, {7, 
    2}, {8, 1}, {10, 1}, {11, -2}, {13, 2}};
k = 11;
pts = pts[[1 ;; k]];
partitions = Partition[pts, UpTo@4, 3];
g1 = Graphics[{BezierCurve@partitions}];
g2 = Graphics[{ColorData[97] /@ Range@Length@partitions, 
     BezierCurve /@ partitions} // Thread];
g3 = ParametricPlot[
   Through@(BezierFunction /@ partitions)@t // Evaluate, {t, 0, 1}];
g4 = ParametricPlot[
   Through@(bezierFunction /@ partitions)@t // Evaluate, {t, 0, 1}];
GraphicsGrid[{{g1, g2}, {g3, g4}}]

enter image description here

  • And on the contrary, we can set the degree of BezierCurve to fit the BezierFunction since the degree of BezierFunction is always equal to n-1 where n is the Length of the points.
Clear["Global`*"];
bezierFunction[pts_][t_] := 
  Module[{n = Length@pts}, 
   Sum[BernsteinBasis[n - 1, i - 1, t]*pts[[i]], {i, 1, n}]];

pts = {{0, 0}, {1, -1}, {3, -1}, {3, 3}, {4, 1}, {5, 1}, {6, 
     0}, {7, 2}, {8, 1}, {10, 1}, {11, -2}, {13, 2}};
Graphics[BezierCurve[pts, SplineDegree -> Length@pts]]
ParametricPlot[bezierFunction[pts]@t, {t, 0, 1}]
ParametricPlot[BezierFunction[pts]@t, {t, 0, 1}]

enter image description here

  • The Arrow and Arrowheads function give the correct position at all the cases,and to my suprise, the arrow move as the constant speed, that is, according to the arclength!!!
pts = {{0, 0}, {1, -1}, {3, -1}, {3, 3}, {4, 1}, {5, 1}, {6, 0}, {7, 
    2}, {8, 1}, {10, 1}, {11, -2}, {13, 2}};
k = 11;
pts = pts[[1 ;; k]];
ani = Animate[
  Graphics[{Arrowheads[{{Medium, t}}], Arrow[BezierCurve[pts]]}, 
   PlotRangePadding -> 1], {t, 0, 1}, AnimationRate -> .1]

enter image description here

$\endgroup$
2
$\begingroup$
Clear["`*"]
pts={{0,0},{1,1},{2,-1},{3,0},{5,2},{6,-1},{7,3},{7,2},{8,1},{10,1},{11,2},{13,1},{15,2}};
nd=5;
p=Partition[pts,UpTo[nd+1],nd][[;;Ceiling[(Length@pts-1)/nd]]];
n=Length@p;
a=ListConvolve[{-1,1},Prepend[UnitStep[n t-Range[n-1]],1],-1,0];
b=MapIndexed[BernsteinBasis[Length@#1-1,Range[0,Length@#1-1],n t+1-#2[[1]]].#1&,p];
f[t_]=a.b;
Graphics@BezierCurve[pts,SplineDegree->nd]
ParametricPlot[f@t,{t,0,1}]
Simplify@f@t

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks for your excellence code. $\endgroup$
    – cvgmt
    Commented Feb 20 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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