예제 #1
0
float Oscillator::GenerateWaveformSample()
{
    float fOutSample = 0.0;
    int nReadIndex = (int)m_fReadIndex;
    float fFrac = m_fReadIndex - nReadIndex;   //fractional part
    int nReadIndexNext = nReadIndex + 1 >1023 ? 0 : nReadIndex +1;

    switch (m_eOscType) {
    case Sinusoid:
        fOutSample = (float)linear_interpolation(0, 1, m_fSinArray[nReadIndex],
                                                 m_fSinArray[nReadIndexNext], fFrac);
        break;
    case Sawtooth:
        fOutSample = (float)linear_interpolation(0, 1, m_fSawToothArray[nReadIndex],
                                                 m_fSawToothArray[nReadIndexNext], fFrac);
        break;
    case Triangle:
        fOutSample = (float)linear_interpolation(0, 1, m_fTriangleArray[nReadIndex],
                                                 m_fTriangleArray[nReadIndexNext], fFrac);
        break;
    case Square:
        fOutSample = (float)linear_interpolation(0, 1, m_fSquareArray[nReadIndex],
                                                 m_fSquareArray[nReadIndexNext], fFrac);
        break;
    default:
        fOutSample = 0.0;
        break;
    }

    m_fReadIndex += m_fIncreament;
    if(m_fReadIndex > WAVETABLE_SAMPLE_RATE)m_fReadIndex = m_fReadIndex - WAVETABLE_SAMPLE_RATE;
    return fOutSample;
}
예제 #2
0
파일: sf6.c 프로젝트: ashao/Offtrac2
void sf6_find_atmconc(  ) {

	int i,j;
	extern double hlat[NYMEM];
	const double equatorbound[2] = {10,-10}; // Set the latitudes where to start interpolating atmospheric concentrations
	double hemisphere_concentrations[2];
	double currtime;
	extern struct timekeeper_t timekeeper;

	currtime = timekeeper.current_time;

	// Interpolate in time to find the atmospheric concentration
	hemisphere_concentrations[0] = linear_interpolation(
			atmconc[SF6IDX].time, atmconc[SF6IDX].nval, currtime,NUMATMVALS);
	hemisphere_concentrations[1] = linear_interpolation(
			atmconc[SF6IDX].time, atmconc[SF6IDX].sval, currtime,NUMATMVALS);


	for (i=0;i<NXMEM;i++)
		for (j=0;j<NYMEM;j++) {

			if (hlat[j] < equatorbound[0] && hlat[j] > equatorbound[1]) {
				sf6_atmconc[i][j] = linear_interpolation(
						equatorbound,hemisphere_concentrations,hlat[j],2);
			}
			if (hlat[j]>equatorbound[0] ) {
				sf6_atmconc[i][j] = hemisphere_concentrations[0];
			}
			if (hlat[j]<equatorbound[1] ) {
				sf6_atmconc[i][j] = hemisphere_concentrations[1];
			}
		}

}
예제 #3
0
  double bilinear_interpolation
  (std::array<double,2> const& grid_pos,std::array<double,4> const& grid,
   std::array<double,4> const& intensity) noexcept
  {
    double i0,i1;

    i0 = 

    linear_interpolation(grid_pos[0],grid[0],intensity[0],grid[2],intensity[1]);

    i1 =

    linear_interpolation(grid_pos[0],grid[0],intensity[2],grid[2],intensity[3]);

    return linear_interpolation(grid_pos[1],grid[1],i0,grid[3],i1);
  }
        // the main method
        virtual void run() {

            // get the new value
            current = buffer->pop();

            //
            switch(type) {

                case LINEAR_INTERPOLATION:
                    linear_interpolation();
                    break;
                case QUADRATIC_INTERPOLATION:
                    break;
                default:
                    break;

            }

            // send the interpolated signal
            DeviceOutput<std::vector<cv::Point2f>>::send(interpolated);

            // update de old value
            old = current;

        }
예제 #5
0
static unsigned int	color_algorithm(t_env *env, t_complexe *z, int i)
{
	if (env->color == 0)
		return (hsv_to_rgb(i / (double)env->iter_max * 360, 0.6, 1));
	else if (env->color == 1)
		return (linear_interpolation(env, i));
	else
		return (hsv_to_rgb(i / (double)env->iter_max * 360,
					fmod(z->img, 1), 1));
}
예제 #6
0
  void setTime (double t)
  {
    clear_render_data();
    double cur_mass_pp = linear_interpolation(_origin_mass_pp,
					      _dest_mass_pp, t);

    for (size_t i = 0; i < _N; ++i)
      {
	_cur_centroids[i] =
	  linear_interpolation_point<K> (_origin_centroids[i],
					 _dest_centroids[i], t);
	double radius = linear_interpolation(_origin_radii[i],
					     _dest_radii[i], t);
	_cur_radii[i] = radius;

	double gray = _masses[i] / (M_PI * radius * radius * cur_mass_pp);
	_cur_colors[i] = double_to_QColor(255.0 * gray);
      }
    update();
  }
예제 #7
0
int main(int argc, char *argv[]) {
    int nd = atoi(argv[1]);
    int nx = atoi(argv[2]);

    double *xd, *yd, *x, *y;

    xd = (double *)malloc(sizeof(double)*nd);
    yd = (double *)malloc(sizeof(double)*nd);
    x = (double *)malloc(sizeof(double)*nx);
    y = (double *)malloc(sizeof(double)*nx);

    FILE *f;
    int i;
    f = fopen("data.dat","r");
    for(i=0;i<nd;i++) {
        fscanf(f,"%lg\t%lg\n",&xd[i],&yd[i]);

    }
    fclose(f);

    f = fopen("xvals.dat","r");
    for(i=0;i<nx;i++) {
        fscanf(f,"%lg\n",&x[i]);

    }
    fclose(f);

    printf("Testing linear interpolation...\n");
    linear_interpolation(x,y,xd,yd,nx,nd);

    f = fopen("yvals_lint.dat","w");
    for(i=0;i<nx;i++) {
        fprintf(f,"%.16lg\n",y[i]);
    }
    fclose(f);

    for(i=0;i<nx;i++) y[i] = 0;

    printf("Testing cubic spline interpolation...\n");

    cubic_spline_interpolation(x,y,xd,yd,nx,nd);

    printf("Outputting cubic spline interpolation...\n");
    f = fopen("yvals_splint.dat","w");
    for(i=0;i<nx;i++) {
        fprintf(f,"%.16lg\n",y[i]);
    }
    fclose(f);
    
    return 0;

}
예제 #8
0
파일: render.c 프로젝트: tlazaro/cg-ucu
void draw_line(Point2D start, Point2D end) {
    int dx = abs(end.x - start.x);
    int dy = abs(end.y - start.y);

    int sx = (start.x < end.x) ? 1 : -1;
    int sy = (start.y < end.y) ? 1 : -1;

    int err = dx - dy;

    Color c;
    float totalPixels = 1 + (dx <= dy) ? dy : dx;
    int pixels = 0;
    for (;;) {
        c.r = linear_interpolation(pixels / totalPixels, (float) start.c.r, (float) end.c.r);
        c.g = linear_interpolation(pixels / totalPixels, (float) start.c.g, (float) end.c.g);
        c.b = linear_interpolation(pixels / totalPixels, (float) start.c.b, (float) end.c.b);

        cg_putpixel(start.x, start.y, c);
        pixels++;
        if (start.x == end.x && start.y == end.y)
            break;

        int e2 = 2 * err;

        if (e2 > -dy) {
            err = err - dy;
            start.x += sx;
        }
        if (start.x == end.x && start.y == end.y) {
            cg_putpixel(start.x, start.y, end.c);
            break;
        }
        if (e2 < dx) {
            err = err + dx;
            start.y = start.y + sy;
        }
    }
}
static int convert_sensor_output(const char* name, const int input,
                                 int *output, int conv)
{
    int sens_ind=-1, inf_ind=-1;
    int ret;

    if (!sensors.attrs) {
        ret = parse_sensor_config(SENSORS_XML_CONFIG);
        if (ret) {
            ALOGE("Thermalutils: Failed to parse sensor config:%d", ret);
            return ret;
        }
#ifdef SENSORS_DEBUG
        dumpsensors();
#endif
    }

    /* check for valid sensor and its index */
    for (sens_ind=0; sens_ind<sensors.sensor_count; sens_ind++) {
        if (!strncmp(name, (sensors.attrs+sens_ind)->name,
                     MAX_SENSOR_NAME_LEN))
            break;
    }

    if (sens_ind >= sensors.sensor_count) {
        ALOGE("Thermalutils: Requested sensor not found");
        return ERROR_SENSOR_NOT_FOUND;
    }

    /* find inflexion point */
    ret = find_inflex_index(sens_ind, input, &inf_ind, conv);
    if (ret == ERROR_INVALID_INPUT) {
        ALOGE("Thermalutils: Index not found, invalid input");
        return ret;
    }

    if (ret == NO_LINEAR_INTERPOLATION) {
        ALOGD("Thermalutils: No interpolation required");
        *output = find_from_lookup_table(sens_ind, inf_ind, conv);
        return 0;
    }

    /* Perform interpolation */
    *output = linear_interpolation(sens_ind, inf_ind, input, conv);

    return 0;
}
double Potential_interpolation_2d::operator()(double rho, double z) const
{
    Point p(rho, z);
    vector<pair<Point, double> > ncoords;
    double norm = natural_neighbor_coordinates_2(
                      _dt, p, back_inserter(ncoords)).second;
    pair<double, bool> res = quadratic_interpolation(
                                 ncoords.begin(), ncoords.end(), norm, p,
                                 Data_access_value(_value_map),
                                 Data_access_grad(_grad_map),
                                 GradTraits());
    if (res.second)
    {
        return res.first;
    }
    else
    {
        return linear_interpolation(
                   ncoords.begin(), ncoords.end(), norm,
                   Data_access_value(_value_map));
    }
}
int tester()
{
//description
  std::vector<std::string> neutrals;
  std::vector<std::string> ions;
  neutrals.push_back("N2");
  neutrals.push_back("CH4");
  neutrals.push_back("C2H");
//ionic system contains neutral system
  ions = neutrals;
  ions.push_back("N2+");
  Scalar MN(14.008L), MC(12.011), MH(1.008L);
  Scalar MN2 = 2.L*MN , MCH4 = MC + 4.L*MH, MC2H = 2.L * MC + MH;
  std::vector<Scalar> Mm;
  Mm.push_back(MN2);
  Mm.push_back(MCH4);
  Mm.push_back(MC2H);

//densities
  std::vector<Scalar> molar_frac;
  molar_frac.push_back(0.95999L);
  molar_frac.push_back(0.04000L);
  molar_frac.push_back(0.00001L);
  molar_frac.push_back(0.L);
  Scalar dens_tot(1e12L);

//hard sphere radius
  std::vector<Scalar> hard_sphere_radius;
  hard_sphere_radius.push_back(2.0675e-8L * 1e-2L); //N2  in cm -> m
  hard_sphere_radius.push_back(2.3482e-8L * 1e-2L); //CH4 in cm -> m
  hard_sphere_radius.push_back(0.L); //C2H

//zenith angle
//not necessary

//photon flux
//not necessary

////cross-section
//not necessary

//altitudes
  Scalar zmin(600.),zmax(1400.),zstep(10.);

//binary diffusion
  Scalar bCN1(1.04e-5 * 1e-4),bCN2(1.76); //cm2 -> m2
  Planet::DiffusionType CN_model(Planet::DiffusionType::Wakeham);
  Scalar bCC1(5.73e16 * 1e-4),bCC2(0.5); //cm2 -> m2
  Planet::DiffusionType CC_model(Planet::DiffusionType::Wilson);
  Scalar bNN1(0.1783 * 1e-4),bNN2(1.81); //cm2 -> m2
  Planet::DiffusionType NN_model(Planet::DiffusionType::Massman);

/************************
 * first level
 ************************/

//altitude
  Planet::Altitude<Scalar,std::vector<Scalar> > altitude(zmin,zmax,zstep);

//neutrals
  Antioch::ChemicalMixture<Scalar> neutral_species(neutrals); 

//ions
  Antioch::ChemicalMixture<Scalar> ionic_species(ions); 

//chapman
//not needed

//binary diffusion
  Planet::BinaryDiffusion<Scalar> N2N2(   Antioch::Species::N2,  Antioch::Species::N2 , bNN1, bNN2, NN_model);
  Planet::BinaryDiffusion<Scalar> N2CH4(  Antioch::Species::N2,  Antioch::Species::CH4, bCN1, bCN2, CN_model);
  Planet::BinaryDiffusion<Scalar> CH4CH4( Antioch::Species::CH4, Antioch::Species::CH4, bCC1, bCC2, CC_model);
  Planet::BinaryDiffusion<Scalar> N2C2H( Antioch::Species::N2, Antioch::Species::C2H);
  Planet::BinaryDiffusion<Scalar> CH4C2H( Antioch::Species::CH4, Antioch::Species::C2H);
  std::vector<std::vector<Planet::BinaryDiffusion<Scalar> > > bin_diff_coeff;
  bin_diff_coeff.resize(2);
  bin_diff_coeff[0].push_back(N2N2);
  bin_diff_coeff[0].push_back(N2CH4);
  bin_diff_coeff[0].push_back(N2C2H);
  bin_diff_coeff[1].push_back(N2CH4);
  bin_diff_coeff[1].push_back(CH4CH4);
  bin_diff_coeff[1].push_back(CH4C2H);


/************************
 * second level
 ************************/

//temperature
  std::vector<Scalar> T0,Tz;
  read_temperature<Scalar>(T0,Tz,"input/temperature.dat");
  std::vector<Scalar> neutral_temperature;
  linear_interpolation(T0,Tz,altitude.altitudes(),neutral_temperature);
  Planet::AtmosphericTemperature<Scalar, std::vector<Scalar> > temperature(neutral_temperature, neutral_temperature, altitude);

//photon opacity
//not needed

//reaction sets
//not needed

/************************
 * third level
 ************************/

//atmospheric mixture
  Planet::AtmosphericMixture<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > composition(neutral_species, ionic_species, altitude, temperature);
  composition.init_composition(molar_frac,dens_tot);
  composition.set_hard_sphere_radius(hard_sphere_radius);
  composition.initialize();

//kinetics evaluators
//not needed

/************************
 * fourth level
 ************************/

//photon evaluator
//not needed

//molecular diffusion
  Planet::MolecularDiffusionEvaluator<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > molecular_diffusion(bin_diff_coeff,
                                                                                                                          composition,
                                                                                                                          altitude,
                                                                                                                          temperature);
  molecular_diffusion.make_molecular_diffusion();

//eddy diffusion
//not needed

/************************
 * checks
 ************************/

  molar_frac.pop_back();//get the ion outta here
  Scalar Matm(0.L);
  for(unsigned int s = 0; s < molar_frac.size(); s++)
  {
     Matm += molar_frac[s] * composition.neutral_composition().M(s);
  }
  Matm *= 1e-3L; //to kg

  std::vector<std::vector<Scalar> > densities;
  calculate_densities(densities, dens_tot, molar_frac, zmin,zmax,zstep, temperature.neutral_temperature(), Mm);
//N2, CH4, C2H
  std::vector<std::vector<Scalar> > Dij;
  Dij.resize(2);
  Dij[0].resize(3,0.L);
  Dij[1].resize(3,0.L);

  int return_flag(0);
  for(unsigned int iz = 0; iz < altitude.altitudes().size(); iz++)
  {
      Scalar P = pressure(composition.total_density()[iz],temperature.neutral_temperature()[iz]);
      Scalar T = temperature.neutral_temperature()[iz];
      Dij[0][0] = binary_coefficient(T,P,bNN1,bNN2); //N2 N2
      Dij[1][1] = binary_coefficient(T,P,bCC1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCC2 + Scalar(1.L)) 
                                              * Planet::Constants::Universal::kb<Scalar>()
                                              / Planet::Constants::Convention::P_normal<Scalar>(),bCC2 + Scalar(1.L)); //CH4 CH4
      Dij[0][1] = binary_coefficient(T,P,bCN1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCN2),bCN2); //N2 CH4
      Dij[0][2] = binary_coefficient(Dij[0][0],Mm[0],Mm[2]); //N2 C2H
      Dij[1][2] = binary_coefficient(Dij[1][1],Mm[1],Mm[2]); //CH4 C2H
      Dij[1][0] = Dij[0][1]; //CH4 N2
      for(unsigned int s = 0; s < molar_frac.size(); s++)
      {
        Scalar tmp(0.L);
        Scalar M_diff(0.L);
        for(unsigned int medium = 0; medium < 2; medium++)
        {
           if(s == medium)continue;
           tmp += densities[medium][iz]/Dij[medium][s];
        }
        Scalar Ds = (barometry(zmin,altitude.altitudes()[iz],neutral_temperature[iz],Matm,dens_tot) - densities[s][iz]) / tmp;
        for(unsigned int j = 0; j < molar_frac.size(); j++)
        {
           if(s == j)continue;
           M_diff += composition.total_density()[iz] * composition.neutral_molar_fraction()[j][iz] * composition.neutral_composition().M(j);
        }
        M_diff /= Scalar(molar_frac.size() - 1);
        Scalar Dtilde = Ds / (Scalar(1.L) - composition.neutral_molar_fraction()[s][iz] * (Scalar(1.L) - composition.neutral_composition().M(s)/M_diff));

        return_flag = return_flag ||
                      check_test(Dtilde,molecular_diffusion.Dtilde()[s][iz],"D tilde of species at altitude");

      }
      return_flag = return_flag ||
                    check_test(Dij[0][0],molecular_diffusion.binary_coefficient(0,0,T,P),"binary molecular coefficient N2 N2 at altitude") || 
                    check_test(Dij[0][1],molecular_diffusion.binary_coefficient(0,1,T,P),"binary molecular coefficient N2 CH4 at altitude") || 
                    check_test(Dij[0][2],molecular_diffusion.binary_coefficient(0,2,T,P),"binary molecular coefficient N2 C2H at altitude") || 
                    check_test(Dij[1][1],molecular_diffusion.binary_coefficient(1,1,T,P),"binary molecular coefficient CH4 CH4 at altitude") || 
                    check_test(Dij[1][2],molecular_diffusion.binary_coefficient(1,2,T,P),"binary molecular coefficient CH4 C2H at altitude");
  }

  return return_flag;
}
예제 #12
0
파일: GameHelper.cpp 프로젝트: knied/LD29
Color4 color_interpolation(Color4 const& color0, Color4 const& color1, float t) {
    Vector3 v0(color0[0]/255.0f, color0[1]/255.0f, color0[2]/255.0f);
    Vector3 v1(color1[0]/255.0f, color1[1]/255.0f, color1[2]/255.0f);
    Vector3 r = linear_interpolation(v0, v1, t);
    return Color4(r[0]*255.0f, r[1]*255.0f, r[2]*255.0f, 255);
}