Guest User

Untitled

a guest
Jul 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. void genCircle(float radius, int splits)
  2. {
  3. int N = 4;
  4. for (int i=0; i<splits; i++) N *= 2;
  5.  
  6. float xs[N];
  7. float ys[N];
  8.  
  9. int step = N/4;
  10. xs[0] = radius;
  11. ys[0] = 0;
  12.  
  13. xs[step] = 0;
  14. ys[step] = radius;
  15.  
  16. xs[2*step] = -radius;
  17. ys[2*step] = 0;
  18.  
  19. xs[3*step] = 0;
  20. ys[3*step] = -radius;
  21.  
  22. for (int k=0; k<splits; k++) {
  23. for (int i=0; i<N; i+=step) {
  24. float sx, sy;
  25. sx = (xs[i] + xs[(i+step)%N]) / 2;
  26. sy = (ys[i] + ys[(i+step)%N]) / 2;
  27.  
  28. float f = radius / sqrt(sx*sx + sy*sy);
  29. xs[i + step/2] = sx*f;
  30. ys[i + step/2] = sy*f;
  31. }
  32. step /= 2;
  33. }
  34.  
  35.  
  36. float circumference = 0;
  37. for (int i=0; i<N; i++) {
  38. float xd = xs[i] - xs[(i+1)%N];
  39. float yd = ys[i] - ys[(i+1)%N];
  40. circumference += sqrt(xd*xd + yd*yd);
  41. }
  42.  
  43. // Now, (xs[i], ys[i]) are coordinates on the circle.
  44. }
Add Comment
Please, Sign In to add comment