Linear Interpolation in C..

Something that's been bugging me for a while, and happy I've finally cracked! there might be a less-expensive way todo it, but seems to work ok for me..
Pretty basic 2D Linear Interpolation, I'm not sure if you would call this piece-meal interpolation or not..

check attachment below for better source too.


double tbl_rpm_to_duty[11][2] =
  {
    {8600, 15},
    {6600, 10},
    {6000, 9.0},
    {5000, 8.0},
    {4500, 20.0},
    {4000, 8.0},
    {3500, 7},
    {3000, 7},
    {2000, 6.9},
    {1000, 6.5},
    {800, 7.5 }
  };


/**
  * My interpolation function
  * should return linear interpolated second dimension value
  * if the col_a value is greater it will return the highest value (capped results)
  * results off the lower end of the chart will interpolate to zero
  */
double interp_table(double dbl_table[][2], int col_a)
{
  short i;
  double col_b_diff;

  for (i=0; dbl_table[i][0]; i++) {
    if( (dbl_table[i][0] >= col_a) && (dbl_table[i+1][0] <= col_a)) {
      col_b_diff = dbl_table[i][1]-dbl_table[i+1][1];
      return dbl_table[i+1][1]+col_b_diff *(col_a-dbl_table[i+1][0]) / (dbl_table[i][0]-dbl_table[i+1][0]);
    }
  }

  if(col_a > dbl_table[0][0]) {
    return dbl_table[0][1];
  }

  return 0;
}

int main(void)
{
  printf("%f\n", interp_table(tbl_rpm_to_duty,9422) );
  printf("%f\n", interp_table(tbl_rpm_to_duty,500) );
  printf("%f\n", interp_table(tbl_rpm_to_duty,5400) );

  return 0;
}
AttachmentSize
map.c1.12 KB

Software is known as the

Software is known as the logical or software of a digital computer, includes all necessary software components that make possible the realization of specific tasks, as opposed to the physical components of the system, called hardware.

These software components include, among others, software-as the word processor that allows the user to perform all tasks related to editing text-o-system software such as operating system, which basically allows other programs to function properly, facilitating interaction with the physical components and other applications, also providing a user interface.
Descargar programas Gratis, Descargar Free Video to iPhone Converter 2.1.3.51, Descargar OpenBravo 2.35, Descargar Viewer2 4.0.44, Descargar Silent Hill 4: The Room Trial Version, Descargar DVD Profiler 3.1.1,