Advertisement
Shailrshah

Bezier Curve

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