void Matrix3::CreateRotationMatrixAboutZAxis(real degrees, Matrix3* result) { result->SetElem(0, cos(dtr(degrees))); result->SetElem(2, sin(dtr(degrees))); result->SetElem(6, -sin(dtr(degrees))); result->SetElem(8, cos(dtr(degrees))); }
void Matrix3::CreateRotationMatrixAboutXAxis(real degrees, Matrix3* result) { result->SetElem(4, cos(dtr(degrees))); result->SetElem(5, -sin(dtr(degrees))); result->SetElem(7, sin(dtr(degrees))); result->SetElem(8, cos(dtr(degrees))); }
double kepler(double m, double ecc) { double e, delta; #define EPSILON 1E-6 e = m = dtr(m); do { delta = e - ecc * sin(e) - m; e -= delta / (1 - ecc * cos(e)); } while (fabs(delta) > EPSILON); return e; }
void sunpos(double jd, int apparent, double *ra, double *dec, double *rv, double* slong) { double t, t2, t3, l, m, e, ea, v, theta, omega, eps; // Time, in Julian centuries of 36525 ephemeris days, // measured from the epoch 1900 January 0.5 ET. t = (jd - 2415020.0) / 36525.0; t2 = t * t; t3 = t2 * t; // Geometric mean longitude of the Sun, referred to the // mean equinox of the date. l = fixangle(279.69668 + 36000.76892 * t + 0.0003025 * t2); // Sun's mean anomaly. m = fixangle(358.47583 + 35999.04975*t - 0.000150*t2 - 0.0000033*t3); // Eccentricity of the Earth's orbit. e = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; // Eccentric anomaly. ea = kepler(m, e); // True anomaly v = fixangle(2 * rtd(atan(sqrt((1 + e) / (1 - e)) * tan(ea / 2)))); // Sun's true longitude. theta = l + v - m; // Obliquity of the ecliptic. eps = 23.452294 - 0.0130125 * t - 0.00000164 * t2 + 0.000000503 * t3; // Corrections for Sun's apparent longitude, if desired. if (apparent) { omega = fixangle(259.18 - 1934.142 * t); theta = theta - 0.00569 - 0.00479 * sin(dtr(omega)); eps += 0.00256 * cos(dtr(omega)); } // Return Sun's longitude and radius vector *slong = theta; *rv = (1.0000002 * (1 - e * e)) / (1 + e * cos(dtr(v))); // Determine solar co-ordinates. *ra = fixangle(rtd(atan2(cos(dtr(eps)) * sin(dtr(theta)), cos(dtr(theta))))); *dec = rtd(asin(sin(dtr(eps)) * sin(dtr(theta)))); }
int _tmain(int argc, _TCHAR* argv[]) { __MessageBoxA(0, "", "", (int)_tmain); vx::detour dtr(L"user32.dll", "MessageBoxA", __MessageBoxA_Header); printf("__MessageA: %p %p\n", __MessageBoxA_Header, __MessageBoxA); MessageBoxA(0, "Hello, Detour Hooker", "Detour", MB_OK); #if 0 //__MessageBoxA_Header(); printf("__MessageA: %p %p\n", __MessageBoxA_Header, __MessageBoxA); //patch_iat(); vx::vector<std::wstring> mods; mods << L"" << L"gdi32.dll"; mods << L"user32.dll" << L"kernel32.dll" << L"msvcrt.dll" << L"msvcr100d.dll"; vx::ApiHooker& hkr = vx::ApiHooker::instance();//.LoadModules(mods); hkr.LoadModules(mods); //vx::MemoryManager::instance().calloc(10, 10, NULL); hkr.ReplaceFuntion(L"user32.dll", L"MessageBoxA", __MessageBoxA); hkr.ReplaceFuntion(L"user32.dll", L"MessageBoxW", __MessageBoxA); hkr.ReplaceFuntion(L"msvcrt.dll", L"malloc", __hooked_malloc); hkr.ReplaceFuntion(L"msvcr100d.dll", L"malloc", __hooked_malloc); hkr.ReplaceFuntion(L"msvcr100d.dll", L"??2@YAPAXI@Z", __hooked_operator_new); hkr.ReplaceFuntion(L"msvcr100d.dll", L"??3@YAXPAX@Z", __hooked_operator_delete); hkr.ReplaceFuntion(L"kernel32.dll", L"HeapAlloc", __hooked_HeapAlloc); int* p = new int[1000000]; //要hook下面这个API MessageBoxA(0, "Hello, IAT Hooker", "IAT", MB_OK); char* p1 = (char*)malloc(10240000); //p1[0] = 1; //DebugBreakProcess(GetCurrentProcess()); vx::ApiHooker::instance().RestoreAllFunctions(); #endif int ch = _getch(); return 0 ; }
void projillum(short *wtab, int xdots, int ydots, double dec) { int i, ftf = 1, ilon, ilat, lilon = 0, lilat = 0, xt; double m, x, y, z, th, lon, lat, s, c; // Clear unoccupied cells in width table for (i = 0; i < ydots; i++) wtab[i] = -1; // Build transformation for declination s = sin(-dtr(dec)); c = cos(-dtr(dec)); // Increment over a semicircle of illumination for (th = -(PI / 2); th <= PI / 2 + 0.001; th += PI / TERMINC) { // Transform the point through the declination rotation. x = -s * sin(th); y = cos(th); z = c * sin(th); // Transform the resulting co-ordinate through the // map projection to obtain screen co-ordinates. lon = (y == 0 && x == 0) ? 0.0 : rtd(atan2(y, x)); lat = rtd(asin(z)); ilat = int(ydots - (lat + 90) * (ydots / 180.0)); ilon = int(lon * (xdots / 360.0)); if (ftf) { // First time. Just save start co-ordinate. lilon = ilon; lilat = ilat; ftf = 0; } else { // Trace out the line and set the width table. if (lilat == ilat) { wtab[(ydots - 1) - ilat] = ilon == 0 ? 1 : ilon; } else { m = ((double) (ilon - lilon)) / (ilat - lilat); for (i = lilat; i != ilat; i += sgn(ilat - lilat)) { xt = int(lilon + (int)floor((m * (i - lilat)) + 0.5)); wtab[(ydots - 1) - i] = xt == 0 ? 1 : xt; } } lilon = ilon; lilat = ilat; } } // Now tweak the widths to generate full illumination for the correct pole. if (dec < 0.0) { ilat = ydots - 1; lilat = -1; } else { ilat = 0; lilat = 1; } for (i = ilat; i != ydots / 2; i += lilat) { if (wtab[i] != -1) { while (1) { wtab[i] = xdots / 2; if (i == ilat) break; i -= lilat; } break; } } }
int restart_zprimme(Complex_Z *V, Complex_Z *W, Complex_Z *H, Complex_Z *hVecs, double *hVals, int *flags, int *iev, Complex_Z *evecs, Complex_Z *evecsHat, Complex_Z *M, Complex_Z *UDU, int *ipivot, int basisSize, int numConverged, int *numConvergedStored, int numLocked, int numGuesses, Complex_Z *previousHVecs, int numPrevRetained, double machEps, Complex_Z *rwork, int rworkSize, primme_params *primme) { int numFree; /* The number of basis vectors to be left free */ int numPacked; /* The number of coefficient vectors moved to the */ /* end of the hVecs array. */ int restartSize; /* The number of vectors to restart with */ int indexOfPreviousVecs=0; /* Position within hVecs array the previous */ /* coefficient vectors will be stored */ int i, n, eStart; /* various variables */ int ret; /* Return value */ numPacked = 0; /* --------------------------------------------------------------------- */ /* If dynamic thick restarting is to be used, then determine the minimum */ /* number of free spaces to be maintained and call the DTR routine. */ /* The DTR routine will determine how many coefficient vectors from the */ /* left and right of H-spectrum to retain at restart. If DTR is not used */ /* then set the restart size to the minimum restart size. */ /* --------------------------------------------------------------------- */ if (primme->restartingParams.scheme == primme_dtr) { numFree = numPrevRetained+max(3, primme->maxBlockSize); restartSize = dtr(numLocked, hVecs, hVals, flags, basisSize, numFree, iev, rwork, primme); } else { restartSize = min(basisSize, primme->minRestartSize); } /* ----------------------------------------------------------------------- */ /* If locking is engaged, then swap coefficient vectors corresponding to */ /* converged Ritz vectors to the end of the hVecs(:, restartSize) subarray.*/ /* This allows the converged Ritz vectors to be stored contiguously in */ /* memory after restart. This significantly reduces the amount of data */ /* movement the locking routine would have to perform otherwise. */ /* The following function also covers some limit cases where restartSize */ /* plus 'to be locked' and previous Ritz vectors may exceed the basisSize */ /* ----------------------------------------------------------------------- */ if (primme->locking) { numPacked = pack_converged_coefficients(&restartSize, basisSize, &numPrevRetained, numLocked, numGuesses, hVecs, hVals, flags, primme); } /* ----------------------------------------------------------------------- */ /* Restarting with a small number of coefficient vectors from the previous */ /* iteration can be retained to accelerate convergence. The previous */ /* coefficient vectors must be combined with the current coefficient */ /* vectors by first orthogonalizing the previous ones versus the current */ /* restartSize ones. The orthogonalized previous vectors are then */ /* inserted into the hVecs array at hVecs(:,indexOfPreviousVecs). */ /* ----------------------------------------------------------------------- */ if (numPrevRetained > 0) { indexOfPreviousVecs = combine_retained_vectors(hVals, flags, hVecs, basisSize, &restartSize, numPacked, previousHVecs, &numPrevRetained, machEps, rwork, primme); } /* -------------------------------------------------------- */ /* Restart V by replacing it with the current Ritz vectors. */ /* -------------------------------------------------------- */ restart_X(V, hVecs, primme->nLocal, basisSize, restartSize, rwork,rworkSize); /* ------------------------------------------------------------ */ /* Restart W by replacing it with W times the eigenvectors of H */ /* ------------------------------------------------------------ */ restart_X(W, hVecs, primme->nLocal, basisSize, restartSize, rwork,rworkSize); /* ---------------------------------------------------------------- */ /* Because we have replaced V by the Ritz vectors, V'*A*V should be */ /* diagonal with the Ritz values on the diagonal. The eigenvectors */ /* of the new matrix V'*A*V become the standard basis vectors. */ /* ---------------------------------------------------------------- */ ret = restart_H(H, hVecs, hVals, restartSize, basisSize, previousHVecs, numPrevRetained, indexOfPreviousVecs, rworkSize, rwork, primme); if (ret != 0) { primme_PushErrorMessage(Primme_restart, Primme_restart_h, ret, __FILE__, __LINE__, primme); return RESTART_H_FAILURE; } /* --------------------------------------------------------------------- */ /* If the user requires (I-QQ') projectors in JDQMR without locking, */ /* the converged eigenvectors are copied temporarily to evecs. There */ /* they stay locked for use in (I-QQ') and (I-K^{-1}Q () Q') projectors.*/ /* NOTE THIS IS NOT LOCKING! The Ritz vectors remain in the basis, and */ /* they will overwrite evecs at the end. */ /* We recommend against this type of usage. It's better to use locking. */ /* --------------------------------------------------------------------- */ /* Andreas NOTE: is done inefficiently for the moment. We should only */ /* add the recently converged. But we need to differentiate them */ /* from flags... */ if (!primme->locking && primme->correctionParams.maxInnerIterations != 0 && numConverged > 0 && (primme->correctionParams.projectors.LeftQ || primme->correctionParams.projectors.RightQ ) ) { n = primme->nLocal; *numConvergedStored = 0; eStart = primme->numOrthoConst; for (i=0;i<primme->numEvals;i++) { if (flags[i] == CONVERGED) { if (*numConvergedStored < numConverged) { Num_zcopy_zprimme(n, &V[i*n], 1, &evecs[(eStart+*numConvergedStored)*n], 1); (*numConvergedStored)++; } } /* if converged */ } /* for */ if (*numConvergedStored != numConverged) { if (primme->printLevel >= 1 && primme->procID == 0) { fprintf(primme->outputFile, "Flags and converged eigenpairs do not correspond %d %d\n", numConverged, *numConvergedStored); } return PSEUDOLOCK_FAILURE; } /* Update also the M = K^{-1}evecs and its udu factorization if needed */ if (UDU != NULL) { apply_preconditioner_block(&evecs[eStart*n], &evecsHat[eStart*n], numConverged, primme ); /* rwork must be maxEvecsSize*numEvals! */ update_projection_zprimme(evecs, evecsHat, M, eStart*n, primme->numOrthoConst+primme->numEvals, numConverged, rwork, primme); ret = UDUDecompose_zprimme(M, UDU, ipivot, eStart+numConverged, rwork, rworkSize, primme); if (ret != 0) { primme_PushErrorMessage(Primme_lock_vectors,Primme_ududecompose,ret, __FILE__, __LINE__, primme); return UDUDECOMPOSE_FAILURE; } } /* if UDU factorization is needed */ } /* if this pseudo locking should take place */ return restartSize; }
//`gen_game (d)` generates a game with `d` doors modeled as a //winning door, a player selected door and the door to keep closed //before asking if the player wants to switch std::tuple<int, int, int> gen_game (int d) { int w = detail::rand (d), p = detail::rand (d); return std::make_tuple (w, p, dtr (w, p, d)); }