// Reflexive Trefoil #include #include typedef double R; #define lc 3000 R pi = 3.14159265358979323846; typedef struct{R x; R y; R z;} v; void pv(v x){printf("%10.6f %10.6f %10.6f\n", x.x, x.y, x.z);} R sq(R x){return x*x;} v sp(R s, v vv){return (v){s*vv.x, s*vv.y, s*vv.z};} R det(v x, v y, v z){return x.x * (y.y * z.z - y.z * z.y) + x.y * (y.z * z.x - y.x * z.z) + x.z * (y.x * z.y - y.y * z.x);} v vd(v * a, v * b){return (v){a->x - b->x, a->y - b->y, a->z - b->z};} v va(v a, v b){return (v){a.x + b.x, a.y + b.y, a.z + b.z};} void dcir(v * ans){ R da = 2.*pi/lc; {int k=lc; while(k--) ans[k] = sp(1, (v){cos(da*2*k) - cos(da*k)/2, sin(da*2*k) + sin(da*k)/2, 3*sin(da*3*k)});} ans[lc] = ans[0];} v l1[lc+1]; // places on the respective curves. int main(){ dcir(l1); pv(vd(&l1[lc-1], &l1[0])); // printf("det=%e\n", det((v){0,2,0}, (v){0,0,1}, (v){1,0,0})); int clo(int i, int j){return (abs(i-j)<4);} {R s = 0, rm = 1000.; {int j=lc; while(j--) {int k=lc; while(k--) if(j!=k) { v r = vd(l1+j, l1+k); R v2 = sq(r.x) + sq(r.y)+ sq(r.z); R i = det(vd(l1+j+1, l1+j), vd(l1+k+1, l1+k), r)/(sqrt(v2)*v2); if(0) if(clo(j, 380) && clo(k, 380)) printf("%d %d %e\n", j, k, i); s += i; if(v2