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$
3
  • 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$ Commented Feb 16, 2016 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$ Commented Feb 16, 2016 at 20:03
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/14736/… $\endgroup$ Commented Feb 16, 2016 at 23:59

1 Answer 1

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$
4
  • $\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$ Commented Feb 17, 2016 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$ Commented Feb 17, 2016 at 16:57
  • $\begingroup$ The honor should be attributed to you.I just wanna give a little advice to your answer. $\endgroup$ Commented Feb 17, 2016 at 18:32
  • $\begingroup$ @yode - edited per your recommendation. $\endgroup$ Commented Feb 17, 2016 at 19:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.