Let's assume that we have got given dots A, D V0, V1, .. , Vn; Vi is (xi,yi) for a plane or (xi,yi,zi) for a space and t : ∈ < 0,1 >.
Bezier's curve of the n-th grade is given by n+1 operative dots of polygon
and by theorem
, t ∈
< 0,1 >.
is Bernstein polynom
:
, t ∈
< 0,1 > and i=0,1, ... n.
, where n! is factorial
a number n, for example 5!=5*4*3*2=120.
Compute BK with Berstein polynomPart of source code zobraz3d.java // help functions public double fact(int i4) // for calculation a factorial numbers from input{ x2=1; if (i4!=0) for (int i3=1;i3<i4+1;i3++){x2=x2*i3;}; return x2; } public double fx(double x1,int i4) // number x1 up i4 { x2=1; if (x1>=0.001) {for (int i3=1;i3<i4+1;i3++){x2=x2*x1;};} return x2; } public double berst(int i4,int i5,double x1) // 1.parameter = n; 2.par. from 0 to n; 3.parameter t from interval (0,1) { po1=fact(i4);po2=fact(i5); po1=po1/po2;po2=fact(i4-i5); po1=po1/po2;po2=fx(1-x1,i4-i5); po1=po1*po2;po2=fx(x1,i5); po1=po1*po2; x2=po1; return x2; } //// The algorithm body input : main points bod[i][0],bod[i][0],bod[i][0] - are x,y,z abscissa a midpoint double p1,p2,p3,p4,p5; int pr1=0,pr2=0; for (int i=1;i<101;i++) // number steps of algoritm = 100 { t=i;t=t/101; // parameter t = <0,1> p2=0;p3=0;p5=0; for (int i1=0;i1<(st+1);i1++) // adding (see figere in top) 0,..,n { p1=berst(st,i1,t); // calculation Berstein polynom p4=bod[i1][0];p2=p2+(p4*p1); // multiplying Berst. polynom with command a point for co-ordinate x,y and z p4=bod[i1][1];p3=p3+(p4*p1); p4=bod[i1][2];p5=p5+(p4*p1); } // conversion computed point on screen pix[0]=p2;pix[1]=p3;pix[2]=p5; osp = new objekt3d(pix,typpre); i1=osp.x()+stredx; i2=stredy-osp.y(); if (i==1){pr1=i1;pr2=i2;} // for first computed point g.drawLine(i1,i2,pr1,pr2); // line from old to new computed point pr1=i1;pr2=i2; // New point will be old } |
Applet Bezier curve . Set a news points with mouse button. Author: Galcik Peter
Applet for handling with Bezier Curves has simple layout and user interface. We can add, move points on canvas by mouse. No action on canvas can be made by keyboard. After every action the curve is redrawn and user can see immediately generated curve. Moreover if we want draw points precisely, we can activate coordinates of intermediate points. Interpolated lines in any point of bezier curve can be showed by moving "Position" slider. And last thing, we can activate animation of curve and set animation speed.
Applet of Bezier Curve is well designed. Consist of three well structured java files.
Universal architecture of java files support further development or implementing new features.
(c) Galcik Peter 2007
Casteljau algorithm (CA) for BKInput : control polygon with points V0, V1, .. , Vn; Vi is (xi,yi) for a plane, or (xi,yi,zi) for a space and t : ∈ < 0,1 >. - V0, V1, .. , Vn is polygon Algorithm. :
In first step we have Vo,i = Vi, for all i ie. point a
curves polygon.
|