NB. To evaluate nth degree Bernstein polynomials B_[n,i] (u) NB. n All_Bern u --> B_[n,0](u), B_[n,1](u), ... B_[n,n](u) NB. u may be a vector NB. adapted from The NURBS Book, p20-21 NB. Alg A1.3 - AllBernstein(n,u,B) All_Bern=: dyad define B=. 1 (0)} ((>:x),#y)$0 u1=. 1-y j=.0 while. (j=. >:j)<: x do. k=. <: s=. 0 while. (k=. >:k)< j do. tmp=. k{B B=. (s+ u1*tmp) k} B s=. y* tmp end. B=. s j} B end. ) NB. Example: u=. int01 200 NB. w=. 8 All_Bern u NB. 'pensize 3' plot w NB. ======================================================== NB. To evaluate the points along a Bezier Curve. NB. Let P be an array of (2D or 3D) control points NB. Let u be the value(s) of the parameter along curve NB. so that 0 <= u <= 1 traces out the Bezier curve NB. P PoBC u ---> x,y (or x,y,z) of points along curve PoBC=: dyad : '+/ x*"(1 0) (<: #x) All_Bern y' NB. define the control points: NB. P=. >0 0;0.2 0.5;0.7 0.8;1 0 NB. or a more interesting set (Pt just transposed array): NB. Pt=. |: P=. > 0 0;0.5 1;1.1 0.2;0.7 0.2 NB. u=. int01 1000 NB. 1001 points along the curve NB. w=. |: z=. P PoBC u NB. plot the curve: NB. plot (0{w);(1{w) NB. plot the conected control points and NB. the resultant Bezier curve: NB. pd 'reset' NB. pd 'pensize 3' NB. pd 'type symbol' NB. pd (0{Pt);(1{Pt) NB. pd 'type line' NB. pd (0{Pt);(1{Pt) NB. pd (0{w);(1{w) NB. pd 'show' NB. ========================================================= NB. To evaluate points on a Bezier curve using the NB. deCasteljau algorithm. Arguments same as PoBC. NB. after NURBS Book, p 24 deCas=: dyad define n=. <: #P=. x NB. make a copy of P for each y: P=. >(#y)#

:k)<: n do. i=. _1 while. (i=. >:i)<: n-k do. v=. (y1*i{"2 P)+y*(i+1){"2 P P=. v i}"_1 P end. end. {."2 P ) NB. Compare to PoBC above: NB. w=. |: z=. P deCas u