1

I am trying to implement the de Casteljau algorithm to trace a point along a Bézier curve.

I already have the Bézier curve in place given by the control points

pts = {{54.78, 62.24}, {26.87, 68.24}, {1.58, 63.24}, 
       {-1, 49.18}, {1.58, 35.18}, {28.57, 35.03}, {52.41, 35.03}, 
       {60.48, 22.58}, {52.4, 7.4}, {24.27, 2}, {0, 10}};

I have been reading up on the de Casteljau algorithm and I understand the basic implementation of it, but I don't understand how to manipulate the point to move along the curve using the algorithm.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
noobie93
  • 11
  • 2

1 Answers1

5

As suggested by george2079

pts = {{54.78, 62.24}, {26.87, 68.24}, {1.58, 63.24}, {-1, 49.18}, {1.58, 
    35.18}, {28.57, 35.03}, {52.41, 35.03}, {60.48, 22.58}, {52.4, 
    7.4}, {24.27, 2}, {0, 10}};

f = BezierFunction[pts];

llp = ListLinePlot[Table[f[t], {t, 0, 1, .02}]];

Manipulate[
 Show[llp,
  Epilog -> {Red, AbsolutePointSize[6],
    Point[f[u]]}],
 {{u, .5}, 0, 1, .01, Appearance -> "Labeled"}]

enter image description here

EDIT: In a comment, yode suggested the use of ParametricPlot). This has the advantage of exploiting the adaptive sampling of the built-in plotting functions and is more direct (i.e., you don't have to generate the Table of points used with ListLinePlot).

pp = ParametricPlot[f[t], {t, 0, 1}];

Manipulate[
 Show[pp,
  AspectRatio -> 1/GoldenRatio,
  Epilog -> {Red, AbsolutePointSize[6],
    Point[f[u]]}],
 {{u, .5}, 0, 1, .01, Appearance -> "Labeled"}]
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198