Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void genCircle(float radius, int splits)
- {
- int N = 4;
- for (int i=0; i<splits; i++) N *= 2;
- float xs[N];
- float ys[N];
- int step = N/4;
- xs[0] = radius;
- ys[0] = 0;
- xs[step] = 0;
- ys[step] = radius;
- xs[2*step] = -radius;
- ys[2*step] = 0;
- xs[3*step] = 0;
- ys[3*step] = -radius;
- for (int k=0; k<splits; k++) {
- for (int i=0; i<N; i+=step) {
- float sx, sy;
- sx = (xs[i] + xs[(i+step)%N]) / 2;
- sy = (ys[i] + ys[(i+step)%N]) / 2;
- float f = radius / sqrt(sx*sx + sy*sy);
- xs[i + step/2] = sx*f;
- ys[i + step/2] = sy*f;
- }
- step /= 2;
- }
- float circumference = 0;
- for (int i=0; i<N; i++) {
- float xd = xs[i] - xs[(i+1)%N];
- float yd = ys[i] - ys[(i+1)%N];
- circumference += sqrt(xd*xd + yd*yd);
- }
- // Now, (xs[i], ys[i]) are coordinates on the circle.
- }
Add Comment
Please, Sign In to add comment