void Transform::lerp(const Transform& transform, float t, int spin) { if(transform.curve_type == "quadratic") { t = quadratic(0, c1, 1, t); } else if(transform.curve_type == "cubic") { t = cubic(0, c1, c2, 1, t); } else if(transform.curve_type == "quartic") { t = quartic(0, c1, c2, c3, 1, t); } else if(transform.curve_type == "quintic") { t = quintic(0, c1, c2, c3, c4, 1, t); } x = lerp(x, transform.x, t); y = lerp(y, transform.y, t); alpha = lerp(alpha, transform.alpha, t); // 'spin' is based on what you are coming from (key1) if(spin != 0) { if(spin > 0 && angle > transform.angle) angle = lerp(angle, transform.angle + 360, t); else if(spin < 0 && angle < transform.angle) angle = lerp(angle, transform.angle - 360, t); else angle = lerp(angle, transform.angle, t); } if(angle > 360) { angle = angle - 360; } scale_x = lerp(scale_x, transform.scale_x, t); scale_y = lerp(scale_y, transform.scale_y, t); }
int main(void) { int N, i, retval; double *xi, *xf; custom_function quartic_min = {quartic, 0}; custom_function rosenbrock_min = {rosenbrock, 0}; N = 4; xi = (double*)malloc(sizeof(double)* N); xf = (double*)malloc(sizeof(double)* N); xi[0] = 3; xi[1] = -1; xi[2] = 0; xi[3] = -1; retval = fminsearch(&quartic_min, N, xi, xf); printf("Powell's Quartic Function \n"); printf("Return Value %d \nObjective Function %g \n", retval, quartic(xf, N,0)); printf("Function minimized at : "); for (i = 0; i < N; ++i) { printf("%g ", xf[i]); } printf("\n \n"); free(xi); free(xf); printf("\nRosenbrock Function \n"); N = 2; xi = (double*)malloc(sizeof(double)* N); xf = (double*)malloc(sizeof(double)* N); xi[0] = -1.2; xi[1] = 1; retval = fminsearch(&rosenbrock_min, N, xi, xf); printf("Return Value %d \nObjective Function %g \n", retval, rosenbrock(xf, N,0)); printf("Function minimized at : "); for (i = 0; i < N; ++i) { printf("%g ", xf[i]); } return 0; }
void Rmhd::FluxAndEigenvalues(const double *U, const double *P, double *F, double *ap, double *am, int dimension) const { const double V2 = P[vx]*P[vx] + P[vy]*P[vy] + P[vz]*P[vz]; const double B2 = P[Bx]*P[Bx] + P[By]*P[By] + P[Bz]*P[Bz]; const double Bv = P[Bx]*P[vx] + P[By]*P[vy] + P[Bz]*P[vz]; const double W2 = 1.0 / (1.0 - V2); const double W = sqrt(W2); const double b0 = W*Bv; const double b2 = (B2 + b0*b0) / W2; const double bx = (P[Bx] + b0 * W*P[vx]) / W; const double by = (P[By] + b0 * W*P[vy]) / W; const double bz = (P[Bz] + b0 * W*P[vz]) / W; const double e = EOS->Internal(P[rho], EOS->Temperature_p(P[rho], P[pre]))/P[rho]; const double p_ = P[pre] + 0.5 * b2; const double h = 1 + e + P[pre]/P[rho]; switch (dimension) { case 1: F[ddd] = U[ddd] * P[vx]; F[tau] = U[tau] * P[vx] - b0*P[Bx] / W + p_*P[vx]; F[Sx ] = U[Sx] * P[vx] - bx*P[Bx] / W + p_; F[Sy ] = U[Sy] * P[vx] - by*P[Bx] / W; F[Sz ] = U[Sz] * P[vx] - bz*P[Bx] / W; F[Bx ] = 0.0; F[By ] = P[vx]*P[By] - P[vy]*P[Bx]; F[Bz ] = P[vx]*P[Bz] - P[vz]*P[Bx]; break; case 2: F[ddd] = U[ddd] * P[vy]; F[tau] = U[tau] * P[vy] - b0*P[By] / W + p_*P[vy]; F[Sx ] = U[Sx] * P[vy] - bx*P[By] / W; F[Sy ] = U[Sy] * P[vy] - by*P[By] / W + p_; F[Sz ] = U[Sz] * P[vy] - bz*P[By] / W; F[Bx ] = P[vy]*P[Bx] - P[vx]*P[By]; F[By ] = 0.0; F[Bz ] = P[vy]*P[Bz] - P[vz]*P[By]; break; case 3: F[ddd] = U[ddd] * P[vz]; F[tau] = U[tau] * P[vz] - b0*P[Bz] / W + p_*P[vz]; F[Sx ] = U[Sx] * P[vz] - bx*P[Bz] / W; F[Sy ] = U[Sy] * P[vz] - by*P[Bz] / W; F[Sz ] = U[Sz] * P[vz] - bz*P[Bz] / W + p_; F[Bx ] = P[vz]*P[Bx] - P[vx]*P[Bz]; F[By ] = P[vz]*P[By] - P[vy]*P[Bz]; F[Bz ] = 0.0; break; } /* Begin eigenvalue calculation * --------------------------------------------------------------------------- * */ if (ap == NULL || am == NULL) return; // User may skip eigenvalue calculation double vi=0, bi=0; switch (dimension) { case 1: vi = P[vx]; bi = bx; break; case 2: vi = P[vy]; bi = by; break; case 3: vi = P[vz]; bi = bz; break; } const double cs2 = EOS->SoundSpeed2Sr(P[rho], EOS->Temperature_p(P[rho], P[pre])); const double W4 = W2*W2; const double v2 = vi*vi; const double v3 = vi*v2; const double v4 = vi*v3; const double K = P[rho]*h * (1.0/cs2-1) * W4; const double L = -(P[rho]*h + b2/cs2) * W2; const double A4 = K - L - b0*b0; const double A3 = -4*K*vi + L*vi*2 + 2*b0*bi; const double A2 = 6*K*v2 + L*(1.0-v2) + b0*b0 - bi*bi; const double A1 = -4*K*v3 - L*vi*2 - 2*b0*bi; const double A0 = K*v4 + L*v2 + bi*bi; QuarticEquation quartic(A4,A3,A2,A1,A0); double roots[4]; int nr = quartic.Solve(roots); *ap = -1.0; *am = 1.0; for (int i=0; i<nr; ++i) { if (roots[i] > *ap) *ap = roots[i]; if (roots[i] < *am) *am = roots[i]; } if (fabs(*ap)>1.0 || fabs(*am)>1.0) { *ap = 1.0; *am = -1.0; } }