#include #include static __inline__ double func(double t, double a, double b) { return pow((pow(a, -2.0) - pow(b, -2.0)) * pow(cos(t), 2.0) + pow(b, -2.0), -0.5); } /* * Simpson's Method - approximate the area under a curve using n intervals * and parabolic curves. */ double simp(double a, double b, int n, double A, double B) { double c, d, s; int i; c = (b - a) / n; d = c / 3; s = func(a, A, B); for (i = 1; i <= (n - 1); i += 2) s += 4.0 * func(a + i * c, A, B); for (i = 2; i <= (n - 2); i += 2) s += 2.0 * func(a + i * c, A, B); s += func(b, A, B); s *= d; return s; } /* * Approximate an integral using Riemann sums on n sub-intervals. * Simple but slow, but who cares given the speed of modern computers! */ double sums(double a, double b, int n, double A, double B) { double h, sum; int i; /* Start with nothing */ sum = 0.0; /* Width of a sub-interval */ h = (b - a) / n; /* Mid=point of 1st sub-interval */ a += h / 2.0; for (i = 0; i < n; i++) { /* Area = width * height */ sum += h * func(a, A, B); /* Mid-point of next sub-interval */ a += h; } return sum; } int main(int argc, char *argv[]) { double a, b, i, g; double x, y, r, w, t, l; if (argc < 3) return 1; /* Radius */ sscanf(argv[1], "%lf", &a); /* Height = 70.7% of radius */ b = a * M_SQRT1_2; /* Gores */ sscanf(argv[2], "%lf", &g); /* Plot 1000 points */ i = M_PI_2 / 1000; /* Summary */ fprintf(stderr, "a=%f b=%f g=%f\n", a, b, g); l = 0.0; for (t = 0.0; t <= M_PI_2; t += i) { x = pow(pow(a, -2.0) + pow(tan(t) / b, 2.0), -0.5); y = x * tan(x); w = 2.0 * M_PI * x / g; l += sums(t ? t - i: 0.0, t, 1000, a, b); printf("%.8f %.8f\n", l, w / 2.0); printf("%.8f %.8f\n", l, -w / 2.0); } return 0; }