manthanthakker40

CG_beziercurve

Nov 3rd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1.    
  2.  
  3.     #include<stdio.h>
  4.     #include<conio.h>
  5.     #include<math.h>
  6.     #include<graphics.h>
  7.     void beizer(int x[6],int y[6]);
  8.     void main()
  9.     {
  10.     int i,j,x[4],y[4];
  11.     int gd=DETECT,gm;
  12.     initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  13.     for(i=0;i<6;i++)
  14.     {
  15.     printf("enter coordinates of point %d\n",i+1);
  16.     scanf("%d%d",&x[i],&y[i]);
  17.     }
  18.     beizer(x,y);
  19.     getch();
  20.     closegraph();
  21.     }
  22.     void beizer(int x[6],int y[6])
  23.     {
  24.     double u;
  25.     int i,j;
  26.     for(u=0.0;u<1.0;u+=0.00005)
  27.     {
  28.     double tx=pow(1-u,5)*x[0]+5*u*pow(1-u,4)*x[1]+10*u*u*pow(1-u,3)*x[2]+10*pow(u,3)*x[3]*pow(1-u,2)+5*pow(u,4)*(1-u)*x[4]+pow(u,5)*x[5];
  29.     double ty=pow(1-u,5)*y[0]+5*u*pow(1-u,4)*y[1]+10*u*u*pow(1-u,3)*y[2]+10*pow(u,3)*y[3]*pow(1-u,2)+5*pow(u,4)*(1-u)*y[4]+pow(u,5)*y[5];
  30.     putpixel(tx,ty,12);
  31.     }
  32.     for(i=0;i<6;i++)
  33.     putpixel(x[i],y[i],10);
  34.     return;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment