Bezier curves (BK)

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 polynom

Part 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 of the 3rd grade

$$$APPLET

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.

Specification

Applet of Bezier Curve is well designed. Consist of three well structured java files.

  • BezierCurveApplet.java - implements swing layout and event from applet ( + animation Thread).
  • BezierCurveAlgorithm.java - static class implementing DeCasteljau Algorithm.
  • BezierCurve.java - class,that hold all data of bezier curve and implements drawing of curve.

Universal architecture of java files support further development or implementing new features.

 

(c) Galcik Peter 2007

Casteljau algorithm (CA) for BK 


Input : 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. : 
  1. V0,i (t) = Vi 
  2. Vr,i (t) = (1 - t). Vr-1,i(t) + t.V r-1,i+1 (t) , for t : ∈ < 0,1 >.
  3. Bn  = Bn (t) = { Bn(t) = Vn,0 (t), t : ∈ < 0,1 >}, where r = 1,...,n and i = 0,..., n-r.
Description : 

In first step we have Vo,i = Vi, for all i ie. point a curves polygon. 
In second step we recursiv compute point VVr,i (t)
In last step is point Vn,n (t) point on Bezier curve.

Berstein polynom attribute is Bernstein polynom :
  1. B0,0 (t) = 1
  2. B i,n (t) = (1-t) B i,n-1 (t) + t B i-1,n-1 (t)
  3. Suma(i=0,...,n) B i,n (t) = 1
  4. B i,n (t) >=0 for t : ∈ < 0,1 >.
Where : Vr,i (t) = Suma(j=0,...,r) V j+i * B r,j (t), pre r = 1,...,n a i = 0,...,n-r
Evidence : from Casteljau algoritmu Bezier curves attribute
  1. Afinite invariant

  2. Let j : E -> E (afinite display) and Bn(t) = Bn [V0, V1, ..., Vn,t]. Then j [Bn[V0, V1, ...,Vn,t]] = Bnj(V0), j(V1), ..., j(Vn),t].
    Meaning of this behaviour is for example in projection. As you can see on the algorithm to calculate BK using Bernstein polynoms, where the first will calculate BK and then the whole curve, will display on screen.
     
  3. Invariants regards on afinit transformation parameter

  4. means if we goes from parameter t on u [u = a + t (b-a)]then curve will not change.
     
  5. Behaviour of convex cover : BK lies in convex cover of own control points. It can be seen also from

  6. Casteljau algoritmu BK, where interpolate control points.
     
  7. End points interpolation. BK starts in point V0 and ends in point Vn. This results also from CA for BK.

  8.  
  9. Symetry. BK = Suma (i=0,...,n) Vn-i * B n,i (1-t), means that main polygon V0, V1, ..., Vn defines the same curve as Vn, Vn-1, ..., V0.

$$$APPLET

Bezier curve construct with Castejauov algorithm


$$$APPLET

Bezier curve of the 3rd grade in 3D, interakcia allows to change z-coordinate values to points creating main polygon

Copyright (c) 1999-2017 Juraj Štugel. www.netgraphics.sk