Logo Search packages:      
Sourcecode: ygraph version File versions  Download package

gdouble interp ( GArray *  xy_data,
gdouble  x_val,
gint  order 
)

Performs an 1D interpolation of the requested order, up to a hard-coded limit of MAX_INTERP_ORDER.

Parameters:
xy_data An array of pointers to xy-pairs (doubles).
x_val The x coordinate value at which the data is to be determined.
order The interpolation order.
Returns:
The interpolated data value at the requested point.

Definition at line 327 of file util.c.

References message_dialog().

{
  gdouble* right_pt;
  gdouble* left_pt;
  gdouble slope;
  guint right_idx;
  gint interp_order;

  if (order > MAX_INTERP_ORDER)
    {
      message_dialog
        ("Unsupported interpolation order. Resorting to linear interpolation");
      interp_order = 1;
    }
  else
    interp_order = order;

  if (interp_order == 1)
    {
      right_idx = 0;
      right_pt = g_array_index(xy_data, gdouble*, right_idx);

      while ((right_pt[0] < x_val) && (++right_idx < xy_data->len))
        right_pt = g_array_index(xy_data, gdouble*, right_idx);

      if (right_idx == 0)
        {
          right_idx = 1;
          right_pt = g_array_index(xy_data, gdouble*, right_idx);
        }

      left_pt = g_array_index(xy_data, gdouble*, right_idx-1);

      slope = (right_pt[1] - left_pt[1]) / (right_pt[0] - left_pt[0]);

      return (left_pt[1] + slope * (x_val - left_pt[0]));
    }
  else
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index