1
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ You might want to point to the textbook you're using so that answerers can write something you can easily relate to what you're reading. $\endgroup$ – J. M. is away Feb 16 '16 at 19:56
  • 1
    $\begingroup$ Do you really need to implement this algorithm on your own as opposed to simply using the built in BezierFunction ? $\endgroup$ – george2079 Feb 16 '16 at 20:03
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/14736/… $\endgroup$ – Michael E2 Feb 16 '16 at 23:59
5
$\begingroup$

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"}]
$\endgroup$
  • $\begingroup$ f = BezierFunction[pts]; Manipulate[ Show[ParametricPlot[f[t], {t, 0, 1}], Epilog -> {Red, AbsolutePointSize[6], Point[f[u]]}], {{u, .5}, 0, 1, .01, Appearance -> "Labeled"}] $\endgroup$ – yode Feb 17 '16 at 16:39
  • $\begingroup$ @yode - Use of ParametricPlot is a good idea; however, since like the ListLinePlot it is independent of the Manipulate control, I would pull the plot outside of the Manipulate and use Show to keep the interaction as responsive as possible. Recommend that you post this as an answer. $\endgroup$ – Bob Hanlon Feb 17 '16 at 16:57
  • $\begingroup$ The honor should be attributed to you.I just wanna give a little advice to your answer. $\endgroup$ – yode Feb 17 '16 at 18:32
  • $\begingroup$ @yode - edited per your recommendation. $\endgroup$ – Bob Hanlon Feb 17 '16 at 19:15

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.