fork download
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4.  
  5. void bezierCurve(int x[] , int y[])
  6. {
  7. double xu = 0.0 , yu = 0.0 , u = 0.0 ;
  8. int i = 0 ;
  9. for(u = 0.0 ; u <= 1.0 ; u += 0.05)
  10. {
  11. xu = pow(1-u,3)*x[0]+3*u*pow(1-u,2)*x[1]+3*pow(u,2)*(1-u)*x[2]
  12. +pow(u,3)*x[3];
  13. yu = pow(1-u,3)*y[0]+3*u*pow(1-u,2)*y[1]+3*pow(u,2)*(1-u)*y[2]
  14. +pow(u,3)*y[3];
  15. printf("X: %i Y: %i \n" , (int)xu , (int)yu) ;
  16. }
  17. }
  18.  
  19. int main(void) {
  20. int x[] = {0,75,50,300};
  21. int y[] = {0,2,140,100};
  22. bezierCurve(x,y);
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
X: 0   Y: 0 
X: 10   Y: 1 
X: 19   Y: 4 
X: 28   Y: 9 
X: 36   Y: 15 
X: 43   Y: 22 
X: 50   Y: 30 
X: 58   Y: 38 
X: 66   Y: 47 
X: 74   Y: 56 
X: 84   Y: 65 
X: 95   Y: 74 
X: 108   Y: 82 
X: 122   Y: 90 
X: 139   Y: 96 
X: 158   Y: 101 
X: 180   Y: 105 
X: 204   Y: 107 
X: 232   Y: 106 
X: 264   Y: 104