# Use de Casteljau algorithm to create Bezier Curve in Mathematica [closed]

Is anyone can tell me how to create Bezier Curve with given Bezier polygon and parameter t by using de Casteljau algorithm (not the Bezier function in Mathematica)in Mathematica code? Thanks a lot!

-

## closed as off-topic by rasher, bobthechemist, m_goldberg, Yves Klett, gpapApr 2 at 22:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – rasher, m_goldberg, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

I'm not sure what you are exactly looking for. Anyway, here's my code for computing a point on a Bézier curve using de Casteljau's algorithm. I'm fairly new to Mathematica and I hope I haven't made too many errors. Maybe one of the experienced users can have a look at the code?

The code is adapted from a code example of 'The NURBS book'. The same pseudo code can be found in the german Wikipedia article about de Casteljau's algorithm (http://de.wikipedia.org/wiki/De-Casteljau-Algorithmus).

decasteljau[p_, t_] := Module[{q, n, i, k},
n = Length[p];
q = {};
Do[AppendTo[q, p[[i]]], {i, 1, n, 1}];
Do[
Do[q[[i]] = (1.0 - t) * q[[i]] + t* q[[i + 1]],
{i, 1, n - k + 1, 1}],
{k, 2, n, 1}];
Return[q[[1]]];]


Some example data:

p = {{100.0, 80.0, 70.0},
{300.0, 100.0, 90.0},
{320.0, 140.0, 150.0},
{340.0, 120.0, 180.0}}

t = 0.1

decasteljau[p, t]
{154.78, 86.52, 77.13}

Show[Graphics3D[{Red, Point[decasteljau[p, t]]}, Axes -> True],
ParametricPlot3D[decasteljau[p, u], {u, 0, 1}]]


-
Since I'm also not sure what OP is looking for, I'd like to leave this as a comment :) It's just a simplified version of your decasteljau: de[p_, t_] := Nest[MovingAverage[#, {1 - t, t}] &, p, Length@p - 1] –  xzczd Apr 2 at 11:45
Thank you so much! –  user13368 Apr 2 at 21:30
One more question, how to display the points on curve? –  user13368 Apr 2 at 21:46
user13368, I have added the point on the Bézier curve. –  gdir Apr 3 at 6:08
Thanks again,but if with given Bezier polygon Table[{i, j, Cos[i]*Sin[j]}, {i, 5}, {j, 5}]].How to display its first /second derivative and tangent, normal, binormal? –  user13368 Apr 4 at 6:24