void LTEpops_elem(Element *element) { register int k, i; bool_t hunt; double *Uk, *Ukp1, C1, *sum, *CT_ne; getCPU(4, TIME_START, NULL); C1 = (HPLANCK/(2.0*PI*M_ELECTRON)) * (HPLANCK/KBOLTZMANN); sum = (double *) malloc(atmos.Nspace * sizeof(double)); CT_ne = (double *) malloc(atmos.Nspace * sizeof(double)); Uk = (double *) malloc(atmos.Nspace * sizeof(double)); Ukp1 = (double *) malloc(atmos.Nspace * sizeof(double)); for (k = 0; k < atmos.Nspace; k++) { CT_ne[k] = 2.0 * pow(C1/atmos.T[k], -1.5) / atmos.ne[k]; sum[k] = 1.0; element->n[0][k] = 1.0; } Linear(atmos.Npf, atmos.Tpf, element->pf[0], atmos.Nspace, atmos.T, Uk, hunt=TRUE); for (i = 1; i < element->Nstage; i++) { Linear(atmos.Npf, atmos.Tpf, element->pf[i], atmos.Nspace, atmos.T, Ukp1, hunt=TRUE); for (k = 0; k < atmos.Nspace; k++) { element->n[i][k] = element->n[i-1][k] * CT_ne[k] * exp(Ukp1[k] - Uk[k] - element->ionpot[i-1]/(KBOLTZMANN*atmos.T[k])); sum[k] += element->n[i][k]; } SWAPPOINTER(Uk, Ukp1); } for (k = 0; k < atmos.Nspace; k++) element->n[0][k] = element->abund * atmos.nHtot[k] / sum[k]; for (i = 1; i < element->Nstage; i++) { for (k = 0; k < atmos.Nspace; k++) element->n[i][k] *= element->n[0][k]; } free(sum); free(CT_ne); free(Uk); free(Ukp1); }
void subdiv_sbasis(SBasis const & s, std::vector<double> & roots, double left, double right) { Interval bs = bounds_fast(s); if(bs.min() > 0 || bs.max() < 0) return; // no roots here if(s.tailError(1) < 1e-7) { double t = s[0][0] / (s[0][0] - s[0][1]); roots.push_back(left*(1-t) + t*right); return; } double middle = (left + right)/2; subdiv_sbasis(compose(s, Linear(0, 0.5)), roots, left, middle); subdiv_sbasis(compose(s, Linear(0.5, 1.)), roots, middle, right); }
void Curves::Exponential(std::vector<float>& curve) { // Make sure curve is empty curve.clear(); // Get normalised linear vector std::vector<float> normLin; Linear(normLin); // Create vector to contain the non-normalised exponential std::vector<float> expVector(normLin.size()); // Create exponential function auto expFunc = [](float v) { return std::exp(v) - 1; }; // Create non-normalised exponential vector std::transform(normLin.begin(), normLin.end(), expVector.begin(), expFunc); // Create normalised exponential vector Normalise(expVector); // Copy generated vector into the curve vector curve.swap(expVector); return; }
void Animation::Draw(int x, int y, int angle, bool more, SDL_Renderer* render) { if(m_animation_type=="background") { Background(x, y, angle, more,render); } else if(m_animation_type=="loop") { LOOP(x, y, angle, more, render); } else if(m_animation_type=="linear") { Linear(x, y, angle, more, render); } else if(m_animation_type=="repeat middle") { Repeat_middle(x, y, angle, more, render); } else if(m_animation_type=="return from end") { Return_end(x, y, angle, more, render); } else if(m_animation_type=="random") { Random(x, y, angle, more, render); } else if(m_animation_type=="hpbarbody") { HP_Bar_body(x, y, angle, more, render); } else if(m_animation_type=="draw image") { Draw_Image(x, y, angle, more, render); } }
shared_ptr<SpineItem> SpineItem::PriorStep() const { auto p = Previous(); while ( p != nullptr && p->Linear() == false ) p = p->Previous(); return p; }
shared_ptr<SpineItem> SpineItem::NextStep() const { auto n = Next(); while ( n != nullptr && n->Linear() == false ) n = n->Next(); return n; }
boost::shared_ptr<SmileSection> SwaptionVolCube2::smileSectionImpl(const Date& optionDate, const Period& swapTenor) const { calculate(); Rate atmForward = atmStrike(optionDate, swapTenor); Volatility atmVol = atmVol_->volatility(optionDate, swapTenor, atmForward); Time optionTime = timeFromReference(optionDate); Real exerciseTimeSqrt = std::sqrt(optionTime); std::vector<Real> strikes, stdDevs; strikes.reserve(nStrikes_); stdDevs.reserve(nStrikes_); Time length = swapLength(swapTenor); for (Size i=0; i<nStrikes_; ++i) { strikes.push_back(atmForward + strikeSpreads_[i]); stdDevs.push_back(exerciseTimeSqrt*( atmVol + volSpreadsInterpolator_[i](length, optionTime))); } Real shift = atmVol_->shift(optionTime,length); return boost::shared_ptr<SmileSection>(new InterpolatedSmileSection<Linear>(optionTime, strikes, stdDevs, atmForward, Linear(), Actual365Fixed(), volatilityType(), shift)); }
/** Changes the basis of d2 p to be sbasis. \param p the d2 Bernstein basis polynomial \returns the d2 Symmetric basis polynomial if the degree is even q is the order in the symmetrical power basis, if the degree is odd q is the order + 1 n is always the polynomial degree, i. e. the Bezier order */ void bezier_to_sbasis (D2<SBasis> & sb, std::vector<Point> const& bz) { size_t n = bz.size() - 1; size_t q = (n+1) / 2; size_t even = (n & 1u) ? 0 : 1; sb[X].clear(); sb[Y].clear(); sb[X].resize(q + even, Linear(0, 0)); sb[Y].resize(q + even, Linear(0, 0)); double Tjk; for (size_t k = 0; k < q; ++k) { for (size_t j = k; j < q; ++j) { Tjk = sgn(j, k) * binomial(n-j-k, j-k) * binomial(n, k); sb[X][j][0] += (Tjk * bz[k][X]); sb[X][j][1] += (Tjk * bz[n-k][X]); sb[Y][j][0] += (Tjk * bz[k][Y]); sb[Y][j][1] += (Tjk * bz[n-k][Y]); } for (size_t j = k+1; j < q; ++j) { Tjk = sgn(j, k) * binomial(n-j-k-1, j-k-1) * binomial(n, k); sb[X][j][0] += (Tjk * bz[n-k][X]); sb[X][j][1] += (Tjk * bz[k][X]); sb[Y][j][0] += (Tjk * bz[n-k][Y]); sb[Y][j][1] += (Tjk * bz[k][Y]); } } if (even) { for (size_t k = 0; k < q; ++k) { Tjk = sgn(q,k) * binomial(n, k); sb[X][q][0] += (Tjk * (bz[k][X] + bz[n-k][X])); sb[Y][q][0] += (Tjk * (bz[k][Y] + bz[n-k][Y])); } sb[X][q][0] += (binomial(n, q) * bz[q][X]); sb[X][q][1] = sb[X][q][0]; sb[Y][q][0] += (binomial(n, q) * bz[q][Y]); sb[Y][q][1] = sb[Y][q][0]; } sb[X][0][0] = bz[0][X]; sb[X][0][1] = bz[n][X]; sb[Y][0][0] = bz[0][Y]; sb[Y][0][1] = bz[n][Y]; }
/** Make a path from a d2 sbasis. \param p the d2 Symmetric basis polynomial \returns a Path If only_cubicbeziers is true, the resulting path may only contain CubicBezier curves. */ void build_from_sbasis(Geom::PathBuilder &pb, D2<SBasis> const &B, double tol, bool only_cubicbeziers) { if (!B.isFinite()) { THROW_EXCEPTION("assertion failed: B.isFinite()"); } if(tail_error(B, 2) < tol || sbasis_size(B) == 2) { // nearly cubic enough if( !only_cubicbeziers && (sbasis_size(B) <= 1) ) { pb.lineTo(B.at1()); } else { std::vector<Geom::Point> bez; sbasis_to_bezier(bez, B, 4); pb.curveTo(bez[1], bez[2], bez[3]); } } else { build_from_sbasis(pb, compose(B, Linear(0, 0.5)), tol, only_cubicbeziers); build_from_sbasis(pb, compose(B, Linear(0.5, 1)), tol, only_cubicbeziers); } }
Piecewise<SBasis> reciprocalOnDomain(Interval range, double tol){ Piecewise<SBasis> reciprocal_fn; //TODO: deduce R from tol... double R=2.; SBasis reciprocal1_R=reciprocal(Linear(1,R),3); double a=range.min(), b=range.max(); if (a*b<0){ b=std::max(fabs(a),fabs(b)); a=0; }else if (b<0){ a=-range.max(); b=-range.min(); } if (a<=tol){ reciprocal_fn.push_cut(0); int i0=(int) floor(std::log(tol)/std::log(R)); a=pow(R,i0); reciprocal_fn.push(Linear(1/a),a); }else{ int i0=(int) floor(std::log(a)/std::log(R)); a=pow(R,i0); reciprocal_fn.cuts.push_back(a); } while (a<b){ reciprocal_fn.push(reciprocal1_R/a,R*a); a*=R; } if (range.min()<0 || range.max()<0){ Piecewise<SBasis>reciprocal_fn_neg; //TODO: define reverse(pw<sb>); reciprocal_fn_neg.cuts.push_back(-reciprocal_fn.cuts.back()); for (unsigned i=0; i<reciprocal_fn.size(); i++){ int idx=reciprocal_fn.segs.size()-1-i; reciprocal_fn_neg.push_seg(-reverse(reciprocal_fn.segs.at(idx))); reciprocal_fn_neg.push_cut(-reciprocal_fn.cuts.at(idx)); } if (range.max()>0){ reciprocal_fn_neg.concat(reciprocal_fn); } reciprocal_fn=reciprocal_fn_neg; } return(reciprocal_fn); }
VColor RadioField::operator () (MPoint point) const { DCoord len=Smooth::Length(center-point); if( len>=radius ) return va; return Linear(vc,va,d(uMCoord(len)),d); }
VColor TwoField::operator () (MPoint point) const { DCoord P=Prod(point-a,b); if( P<=0 ) return va; if( P>=D ) return vb; return Linear(va,vb,d(uDCoord(P)),d); }
SBasis compose(SBasis2d const &fg, D2<SBasis> const &p) { SBasis B; SBasis s[2]; SBasis ss[2]; for(unsigned dim = 0; dim < 2; dim++) s[dim] = p[dim]*(Linear(1) - p[dim]); ss[1] = Linear(1); for(unsigned vi = 0; vi < fg.vs; vi++) { ss[0] = ss[1]; for(unsigned ui = 0; ui < fg.us; ui++) { unsigned i = ui + vi*fg.us; B += ss[0]*compose(fg[i], p); ss[0] *= s[0]; } ss[1] *= s[1]; } return B; }
//TODO: handle the case when B is "behind" A for the natural orientation of the level set. //TODO: more generally, there might be up to 4 solutions. Choose the best one! D2<SBasis> sb2d_cubic_solve(SBasis2d const &f, Geom::Point const &A, Geom::Point const &B){ D2<SBasis>result;//(Linear(A[X],B[X]),Linear(A[Y],B[Y])); //g_warning("check 0 = %f = %f!", f.apply(A[X],A[Y]), f.apply(B[X],B[Y])); SBasis2d f_u = partial_derivative(f , 0); SBasis2d f_v = partial_derivative(f , 1); SBasis2d f_uu = partial_derivative(f_u, 0); SBasis2d f_uv = partial_derivative(f_v, 0); SBasis2d f_vv = partial_derivative(f_v, 1); Geom::Point dfA(f_u.apply(A[X],A[Y]),f_v.apply(A[X],A[Y])); Geom::Point dfB(f_u.apply(B[X],B[Y]),f_v.apply(B[X],B[Y])); Geom::Point V0 = rot90(dfA); Geom::Point V1 = rot90(dfB); double D2fVV0 = f_uu.apply(A[X],A[Y])*V0[X]*V0[X]+ 2*f_uv.apply(A[X],A[Y])*V0[X]*V0[Y]+ f_vv.apply(A[X],A[Y])*V0[Y]*V0[Y]; double D2fVV1 = f_uu.apply(B[X],B[Y])*V1[X]*V1[X]+ 2*f_uv.apply(B[X],B[Y])*V1[X]*V1[Y]+ f_vv.apply(B[X],B[Y])*V1[Y]*V1[Y]; std::vector<D2<SBasis> > candidates = cubics_fitting_curvature(A,B,V0,V1,D2fVV0,D2fVV1); if (candidates.empty()) { return D2<SBasis>(Linear(A[X],B[X]),Linear(A[Y],B[Y])); } //TODO: I'm sure std algorithm could do that for me... double error = -1; unsigned best = 0; for (unsigned i=0; i<candidates.size(); i++){ Interval bounds = *bounds_fast(compose(f,candidates[i])); double new_error = (fabs(bounds.max())>fabs(bounds.min()) ? fabs(bounds.max()) : fabs(bounds.min()) ); if ( new_error < error || error < 0 ){ error = new_error; best = i; } } return candidates[best]; }
//-Sqrt---------------------------------------------------------- static Piecewise<SBasis> sqrt_internal(SBasis const &f, double tol, int order){ SBasis sqrtf; if(f.isZero() || order == 0){ return Piecewise<SBasis>(sqrtf); } if (f.at0()<-tol*tol && f.at1()<-tol*tol){ return sqrt_internal(-f,tol,order); }else if (f.at0()>tol*tol && f.at1()>tol*tol){ sqrtf.resize(order+1, Linear(0,0)); sqrtf[0] = Linear(std::sqrt(f[0][0]), std::sqrt(f[0][1])); SBasis r = f - multiply(sqrtf, sqrtf); // remainder for(unsigned i = 1; int(i) <= order && i<r.size(); i++) { Linear ci(r[i][0]/(2*sqrtf[0][0]), r[i][1]/(2*sqrtf[0][1])); SBasis cisi = shift(ci, i); r -= multiply(shift((sqrtf*2 + cisi), i), SBasis(ci)); r.truncate(order+1); sqrtf[i] = ci; if(r.tailError(i) == 0) // if exact break; } }else{ sqrtf = Linear(std::sqrt(fabs(f.at0())), std::sqrt(fabs(f.at1()))); } double err = (f - multiply(sqrtf, sqrtf)).tailError(0); if (err<tol){ return Piecewise<SBasis>(sqrtf); } Piecewise<SBasis> sqrtf0,sqrtf1; sqrtf0 = sqrt_internal(compose(f,Linear(0.,.5)),tol,order); sqrtf1 = sqrt_internal(compose(f,Linear(.5,1.)),tol,order); sqrtf0.setDomain(Interval(0.,.5)); sqrtf1.setDomain(Interval(.5,1.)); sqrtf0.concat(sqrtf1); return sqrtf0; }
/** Compute the sqrt of a function. \param f function */ Piecewise<SBasis> sqrt(Piecewise<SBasis> const &f, double tol, int order){ Piecewise<SBasis> result; Piecewise<SBasis> zero = Piecewise<SBasis>(Linear(tol*tol)); zero.setDomain(f.domain()); Piecewise<SBasis> ff=max(f,zero); for (unsigned i=0; i<ff.size(); i++){ Piecewise<SBasis> sqrtfi = sqrt_internal(ff.segs[i],tol,order); sqrtfi.setDomain(Interval(ff.cuts[i],ff.cuts[i+1])); result.concat(sqrtfi); } return result; }
D2<SBasis> EllipticalArc::toSBasis() const { D2<SBasis> arc; // the interval of parametrization has to be [0,1] Coord et = initialAngle().radians() + ( _sweep ? sweepAngle() : -sweepAngle() ); Linear param(initialAngle(), et); Coord cos_rot_angle, sin_rot_angle; sincos(_rot_angle, sin_rot_angle, cos_rot_angle); // order = 4 seems to be enough to get a perfect looking elliptical arc SBasis arc_x = ray(X) * cos(param,4); SBasis arc_y = ray(Y) * sin(param,4); arc[0] = arc_x * cos_rot_angle - arc_y * sin_rot_angle + Linear(center(X),center(X)); arc[1] = arc_x * sin_rot_angle + arc_y * cos_rot_angle + Linear(center(Y),center(Y)); // ensure that endpoints remain exact for ( int d = 0 ; d < 2 ; d++ ) { arc[d][0][0] = initialPoint()[d]; arc[d][0][1] = finalPoint()[d]; } return arc; }
/* * This version works by inverting a reasonable upper bound on the error term after subdividing the * curve at $a$. We keep biting off pieces until there is no more curve left. * * Derivation: The tail of the power series is $a_ks^k + a_{k+1}s^{k+1} + \ldots = e$. A * subdivision at $a$ results in a tail error of $e*A^k, A = (1-a)a$. Let this be the desired * tolerance tol $= e*A^k$ and invert getting $A = e^{1/k}$ and $a = 1/2 - \sqrt{1/4 - A}$ */ void subpath_from_sbasis_incremental(Geom::OldPathSetBuilder &pb, D2<SBasis> B, double tol, bool initial) { const unsigned k = 2; // cubic bezier double te = B.tail_error(k); assert(B[0].IS_FINITE()); assert(B[1].IS_FINITE()); //std::cout << "tol = " << tol << std::endl; while(1) { double A = std::sqrt(tol/te); // pow(te, 1./k) double a = A; if(A < 1) { A = std::min(A, 0.25); a = 0.5 - std::sqrt(0.25 - A); // quadratic formula if(a > 1) a = 1; // clamp to the end of the segment } else a = 1; assert(a > 0); //std::cout << "te = " << te << std::endl; //std::cout << "A = " << A << "; a=" << a << std::endl; D2<SBasis> Bs = compose(B, Linear(0, a)); assert(Bs.tail_error(k)); std::vector<Geom::Point> bez = sbasis_to_bezier(Bs, 2); reverse(bez.begin(), bez.end()); if (initial) { pb.start_subpath(bez[0]); initial = false; } pb.push_cubic(bez[1], bez[2], bez[3]); // move to next piece of curve if(a >= 1) break; B = compose(B, Linear(a, 1)); te = B.tail_error(k); } }
bool_t Rayleigh_H2(double lambda, double *scatt) { register int k; static double a[3] = {8.779E+01, 1.323E+06, 2.245E+10}; static double lambdaRH2[N_RAYLEIGH_H2] = { 121.57, 130.00, 140.00, 150.00, 160.00, 170.00, 185.46, 186.27, 193.58, 199.05, 230.29, 237.91, 253.56, 275.36, 296.81, 334.24, 404.77, 407.90, 435.96, 546.23, 632.80 }; static double sigma[N_RAYLEIGH_H2] = { 2.35E-06, 1.22E-06, 6.80E-07, 4.24E-07, 2.84E-07, 2.00E-07, 1.25E-07, 1.22E-07, 1.00E-07, 8.70E-08, 4.29E-08, 3.68E-08, 2.75E-08, 1.89E-08, 1.36E-08, 8.11E-09, 3.60E-09, 3.48E-09, 2.64E-09, 1.04E-09, 5.69E-10 }; /* --- Rayleigh scattering by H2 molecules. Cross-section is given in in units of Mb, 1.0E-22 m^2. See: G. A. Victor and A. Dalgarno (1969), J. Chem. Phys. 50, 2535 (for lambda <= 632.80 nm), and S. P. Tarafdar and M. S. Vardya (1973), MNRAS 163, 261 Also: R. Mathisen (1984), Master's thesis, Inst. Theor. Astroph., University of Oslo, p. 49 -- -------------- */ bool_t hunt; double lambda2, sigma_RH2, *nH2; nH2 = atmos.H2->n; if (lambda >= RAYLEIGH_H2_LIMIT) { if (lambda <= lambdaRH2[N_RAYLEIGH_H2 - 1]) { Linear(N_RAYLEIGH_H2, lambdaRH2, sigma, 1, &lambda, &sigma_RH2, hunt=FALSE); } else { lambda2 = 1.0 / SQ(lambda); sigma_RH2 = (a[0] + (a[1] + a[2]*lambda2) * lambda2) * SQ(lambda2); } sigma_RH2 *= MEGABARN_TO_M2; for (k = 0; k < atmos.Nspace; k++) scatt[k] = sigma_RH2 * nH2[k]; return TRUE; } else return FALSE; }
SBasis extract_u(SBasis2d const &a, double u) { SBasis sb(a.vs, Linear()); double s = u*(1-u); for(unsigned vi = 0; vi < a.vs; vi++) { double sk = 1; Linear bo(0,0); for(unsigned ui = 0; ui < a.us; ui++) { bo += (extract_u(a.index(ui, vi), u))*sk; sk *= s; } sb[vi] = bo; } return sb; }
SBasis extract_v(SBasis2d const &a, double v) { SBasis sb(a.us, Linear()); double s = v*(1-v); for(unsigned ui = 0; ui < a.us; ui++) { double sk = 1; Linear bo(0,0); for(unsigned vi = 0; vi < a.vs; vi++) { bo += (extract_v(a.index(ui, vi), v))*sk; sk *= s; } sb[ui] = bo; } return sb; }
MixedLinearCubicInterpolation(const I1& xBegin, const I1& xEnd, const I2& yBegin, Size n, CubicInterpolation::DerivativeApprox da, bool monotonic, CubicInterpolation::BoundaryCondition leftC, Real leftConditionValue, CubicInterpolation::BoundaryCondition rightC, Real rightConditionValue) { impl_ = boost::shared_ptr<Interpolation::Impl>(new detail::MixedInterpolationImpl<I1, I2, Linear, Cubic>( xBegin, xEnd, yBegin, n, Linear(), Cubic(da, monotonic, leftC, leftConditionValue, rightC, rightConditionValue))); impl_->update(); }
bool PolynomialRootsR<Real>::Quadratic (const PRational& c0, const PRational& c1, const PRational& c2) { if (c2 == msZero) { return Linear(c0, c1); } // The equation is c2*x^2 + c1*x + c0 = 0, where c2 is not zero. Create // a monic polynomial, x^2 + a1*x + a0 = 0. PRational ratInvC2 = msOne/c2; PRational ratA1 = c1*ratInvC2; PRational ratA0 = c0*ratInvC2; // Solve the equation. return Quadratic(ratA0, ratA1); }
int main(int argc, char *argv[]) { // Example R2 // q(0,0) to q(pi, pi) // q0 = [0 0] vctDoubleVec q0; q0.SetSize(2); q0.SetAll(0.0); // q1 = [pi pi] vctDoubleVec q1; q1.SetSize(2); q1.SetAll(cmnPI); // vmax = [0.05, 0.05] vctDoubleVec vmax; vmax.SetSize(2); vmax.SetAll(0.05); double tstart = 0.0; double tstop = 0.0; // define function robLinearRn Linear(q0, // start pos q1, // stop pos vmax, // vmax tstart); // start time // update tstop tstop = Linear.StopTime(); // simulate the time run double tstep = 0.1; vctDoubleVec q; q.SetSize(2); vctDoubleVec qd; qd.SetSize(2); vctDoubleVec qdd; qdd.SetSize(2); // let's log the data to file std::ofstream logfile; logfile.open("FunctionRnLog.txt"); for (double t = tstart; t < tstop; t = t + tstep) { Linear.Evaluate(t, q, qd, qdd); std::cout << q << std::endl; logfile << std::fixed << std::setprecision(3) << "t = " << t << " q = " << q << std::endl; } logfile.close(); return 0; }
/** * \brief Retruns a Piecewise SBasis with prescribed values at prescribed times. * * \param times: vector of times at which the values are given. Should be sorted in increasing order. * \param values: vector of prescribed values. Should have the same size as times and be sorted accordingly. * \param smoothness: (defaults to 1) regularity class of the result: 0=piecewise linear, 1=continuous derivative, etc... */ Piecewise<SBasis> interpolate(std::vector<double> times, std::vector<double> values, unsigned smoothness){ assert ( values.size() == times.size() ); if ( values.size() == 0 ) return Piecewise<SBasis>(); if ( values.size() == 1 ) return Piecewise<SBasis>(values[0]);//what about time?? SBasis sk = shift(Linear(1.),smoothness); SBasis bump_in = integral(sk); bump_in -= bump_in.at0(); bump_in /= bump_in.at1(); SBasis bump_out = reverse( bump_in ); Piecewise<SBasis> result; result.cuts.push_back(times[0]); for (unsigned i = 0; i<values.size()-1; i++){ result.push(bump_out*values[i]+bump_in*values[i+1],times[i+1]); } return result; }
bool PolynomialRootsR<Real>::Quadratic (Real c0, Real c1, Real c2) { if (c2 == (Real)0) { return Linear(c0, c1); } // The equation is c2*x^2 + c1*x + c0 = 0, where c2 is not zero. PRational ratC0(c0), ratC1(c1), ratC2(c2); // Create a monic polynomial, x^2 + a1*x + a0 = 0. PRational ratInvC2 = msOne/ratC2; PRational ratA1 = ratC1*ratInvC2; PRational ratA0 = ratC0*ratInvC2; // Solve the equation. return Quadratic(ratA0, ratA1); }
float AngleLinear(float angleA,float angleB,int spin,float t) { if(spin == 0) return angleA; if(spin > 0) { if((angleB-angleA) < 0) angleB+=360; } else if(spin < 0) { if((angleB-angleA)>0) angleB-=360; } return Linear(angleA,angleB,t); }
void OGL_Light::BindIntoBuffer(GLuint _buffer, unsigned int _index) { glBindBuffer(GL_UNIFORM_BUFFER, _buffer); GLint baseOffset = m_ComputeLightOffset(_index); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset, 3 * sizeof(GLfloat), m_Ia.ToArray().get()); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset + (4 * sizeof(GLfloat)), 3 * sizeof(GLfloat), m_Id.ToArray().get()); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset + 2 * (4 * sizeof(GLfloat)), 3 * sizeof(GLfloat), m_Is.ToArray().get()); baseOffset += 3 * 4 * sizeof(GLfloat); switch (m_Type) { case DIRECTIONAL: { glBufferSubData(GL_UNIFORM_BUFFER, baseOffset, 3 * sizeof(GLfloat), m_Direction.ToArray().get()); } break; case POINT: { glBufferSubData(GL_UNIFORM_BUFFER, baseOffset, 3 * sizeof(GLfloat), m_Position.ToArray().get()); baseOffset += 4 * sizeof(GLfloat); GLfloat constant = Constant(), linear = Linear(), quadratic = Quadratic(); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset, sizeof(GLfloat), &constant); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset + sizeof(GLfloat), sizeof(GLfloat), &linear); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset + 2 * sizeof(GLfloat), sizeof(GLfloat), &quadratic); } break; case SPOT: { glBufferSubData(GL_UNIFORM_BUFFER, baseOffset, 3 * sizeof(GLfloat), m_Position.ToArray().get()); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset + (4 * sizeof(GLfloat)), 3 * sizeof(GLfloat), m_Direction.ToArray().get()); baseOffset += 2 * (4 * sizeof(GLfloat)); GLfloat innerCutoff = InnerCutoff(), cutoff = Cutoff(); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset, sizeof(GLfloat), &innerCutoff); glBufferSubData(GL_UNIFORM_BUFFER, baseOffset + sizeof(GLfloat), sizeof(GLfloat), &cutoff); } break; default: break; } glBindBuffer(GL_UNIFORM_BUFFER, 0); }
std::string CppExporter::toString(const Term* term) const { if (not term) return "NULL"; if (term->className() == Discrete().className()) { const Discrete* discrete = dynamic_cast<const Discrete*> (term); std::ostringstream ss; ss << "fl::" << term->className() << "::create(\"" << term->getName() << "\", "; ss << discrete->x.size() + discrete->y.size() << ", "; for (std::size_t i = 0; i < discrete->x.size(); ++i) { ss << fl::Op::str(discrete->x.at(i)) << ", " << fl::Op::str(discrete->y.at(i)); if (i + 1 < discrete->x.size()) ss << ", "; } ss << ")"; return ss.str(); } if (term->className() == Function().className()) { const Function* function = dynamic_cast<const Function*> (term); std::ostringstream ss; ss << "fl::" << term->className() << "::create(\"" << term->getName() << "\", " << "\"" << function->getFormula() << "\", engine)"; return ss.str(); } if (term->className() == Linear().className()) { const Linear* linear = dynamic_cast<const Linear*> (term); std::ostringstream ss; ss << "fl::" << term->className() << "::create(\"" << term->getName() << "\", " << "engine->inputVariables(), "; for (std::size_t i = 0; i < linear->coefficients.size(); ++i) { ss << fl::Op::str(linear->coefficients.at(i)); if (i + 1 < linear->coefficients.size()) ss << ", "; } ss << ")"; return ss.str(); } std::ostringstream ss; ss << "new fl::" << term->className() << "(\"" << term->getName() << "\", " << Op::findReplace(term->parameters(), " ", ", ") << ")"; return ss.str(); }
void SpatialInfo::Interpolate(const SpatialInfo& other, float t) { x_ = Linear(x_, other.x_, t); y_ = Linear(y_, other.y_, t); if (spin > 0.0f && (other.angle_ - angle_ < 0.0f)) { angle_ = Linear(angle_, other.angle_ + 360.0f, t); } else if (spin < 0.0f && (other.angle_ - angle_ > 0.0f)) { angle_ = Linear(angle_, other.angle_ - 360.0f, t); } else { angle_ = Linear(angle_, other.angle_, t); } scaleX_ = Linear(scaleX_, other.scaleX_, t); scaleY_ = Linear(scaleY_, other.scaleY_, t); alpha_ = Linear(alpha_, other.alpha_, t); }