real bump(real x, real y) { real cxs = cosr(x); cxs *= cxs; real cys = cosr(y); cys *= cys; return fabsr((cxs*cxs + cys*cys - 2*cxs*cys) / sqrtr(x*x+2*y*y)); }
void tformsetangle(Tform *t, real angle) { real c = cosr(angle); real s = sinr(angle); t->col1.x = c; t->col2.x = -s; t->col1.y = s; t->col2.y = c; }
/* n inner lobatto nodes (excluding -1,1) */ static void lobatto_nodes_aux(real *z, int n) { int i,j,np=n+1; for(i=0; i<=n/2-1; ++i) { real ox, x = cosr( (n-i)*PI/np ); do { ox = x; x -= legendre_d1(np,x)/legendre_d2(np,x); } while(fabsr(x-ox)>-x*EPS); z[i] = x - legendre_d1(np,x)/legendre_d2(np,x); } if(n&1) z[n/2]=0; for(j=(n+1)/2,i=n/2-1; j<n; ++j,--i) z[j]=-z[i]; }
/* n nodes */ void gauss_nodes(real *z, int n) { int i,j; for(i=0; i<=n/2-1; ++i) { real ox, x = cosr( (2*n-2*i-1)*(PI/2)/n ); do { ox = x; x -= legendre(n,x)/legendre_d1(n,x); } while(fabsr(x-ox)>-x*EPS); z[i] = x - legendre(n,x)/legendre_d1(n,x); } if(n&1) z[n/2]=0; for(j=(n+1)/2,i=n/2-1; j<n; ++j,--i) z[j]=-z[i]; }
real randn() { static bool prepped = false; static real prepped_result = 0; if (prepped) { prepped = false; return prepped_result; } else { real u1 = randf(), u2 = randf(); real len = sqrtr(-2 * logr(u1)); prepped = true; prepped_result = len * sinr(2*M_PI*u2); return len * cosr(2*M_PI*u2); } }