double Ring::computeTentativePhiAperture(double moduleWaferDiameter, double minRadius) { double r = moduleWaferDiameter/2; double l = (minRadius-r); double y = pow(r/l, 2); double x = solvex(y); double tempd; int i = 0; for (; i < MAX_WEDGE_CALC_LOOPS; i++) { l = compute_l(x, y, minRadius); y = pow(r/l, 2); x = solvex(y); tempd = compute_d(x, y, l); if (fabs(minRadius - tempd)<1e-15) break; } if (i >= MAX_WEDGE_CALC_LOOPS) { //logWarning("Maximum number of iterations hit while computing wedge geometry"); } double alpha = asin(sqrt(x)) * 2; return alpha; }
void kepstep(double dt, double M1, double x, double y, double z, double vx, double vy, double vz, double *xnew, double *ynew, double *znew, double *vxnew, double *vynew, double *vznew) { double r0 = sqrt(x * x + y * y + z * z); // current radius double v2 = (vx * vx + vy * vy + vz * vz); // current velocity double r0dotv0 = (x * vx + y * vy + z * vz); double alpha = (2.0 / r0 - v2 / M1); // inverse of semi-major eqn 2.134 MD // here alpha=1/a and can be negative double x_p = solvex(r0dotv0, alpha, M1, r0, dt); // solve universal kepler eqn double smu = sqrt(M1); double foo = 1.0 - r0 * alpha; double sig0 = r0dotv0 / smu; double x2, x3, alx2, Cp, Sp, r; x2 = x_p * x_p; x3 = x2 * x_p; alx2 = alpha * x2; Cp = C_prussing(alx2); Sp = S_prussing(alx2); r = sig0 * x_p * (1.0 - alx2 * Sp) + foo * x2 * Cp + r0; // eqn 2.42 PC // f,g functions equation 2.38a PC double f_p = 1.0 - (x2 / r0) * Cp; double g_p = dt - (x3 / smu) * Sp; // dfdt,dgdt function equation 2.38b PC double dfdt = x_p * smu / (r * r0) * (alx2 * Sp - 1.0); double dgdt = 1.0 - (x2 / r) * Cp; if (r0 > 0.0) { // error catch if a particle is at Sun *xnew = x * f_p + g_p * vx; // eqn 2.65 M+D *ynew = y * f_p + g_p * vy; *znew = z * f_p + g_p * vz; *vxnew = dfdt * x + dgdt * vx; //eqn 2.70 M+D *vynew = dfdt * y + dgdt * vy; *vznew = dfdt * z + dgdt * vz; } else { *xnew = x; *ynew = y; *znew = z; *vxnew = vx; *vynew = vy; *vznew = vz; } }
static bool cohen_sutherland_clip(int* X1, int* Y1, int* X2, int* Y2) { int x1 = *X1; int y1 = *Y1; int x2 = *X2; int y2 = *Y2; const int clipX1 = a__screen.clipX; const int clipX2 = a__screen.clipX2; const int clipY1 = a__screen.clipY; const int clipY2 = a__screen.clipY2; #define A__OUT_LEFT 1 #define A__OUT_RIGHT 2 #define A__OUT_TOP 4 #define A__OUT_DOWN 8 #define outcode(o, x, y) \ { \ if(x < clipX1) o |= A__OUT_LEFT; \ else if(x >= clipX2) o |= A__OUT_RIGHT; \ \ if(y < clipY1) o |= A__OUT_TOP; \ else if(y >= clipY2) o |= A__OUT_DOWN; \ } #define solvex() (x1 + (x1 - x2) * (y - y1) / (y1 - y2)) #define solvey() (y1 + (y1 - y2) * (x - x1) / (x1 - x2)) while(true) { int outcode1 = 0; int outcode2 = 0; outcode(outcode1, x1, y1); outcode(outcode2, x2, y2); if((outcode1 | outcode2) == 0) { *X1 = x1; *Y1 = y1; *X2 = x2; *Y2 = y2; return true; } else if(outcode1 & outcode2) { return false; } else { int x, y; const int outcode = outcode1 ? outcode1 : outcode2; if(outcode & A__OUT_LEFT) { x = clipX1; y = solvey(); } else if(outcode & A__OUT_RIGHT) { x = clipX2 - 1; y = solvey(); } else if(outcode & A__OUT_TOP) { y = clipY1; x = solvex(); } else { // outcode & A__OUT_DOWN y = clipY2 - 1; x = solvex(); } if(outcode == outcode1) { x1 = x; y1 = y; } else { x2 = x; y2 = y; } } } }