bpmnr/nr_quadinterpol.c

Go to the documentation of this file.
00001 
00006 #include "bpm_nr.h"
00007 
00008 double nr_quadinterpol( double x, 
00009                         double x1, double x2, double x3,
00010                         double y1, double y2, double y3 ) {
00011 
00012   double d1, d2, d3, d4;
00013   double a, b, c;
00014 
00015   // if the 3 points are equal, set the interpolated point equal as well
00016   if( ( fabs( y1 - y2 ) < 1.0e-15 ) &&
00017       ( fabs( y2 - y3 ) < 1.0e-15 ) ) return y2;
00018   
00019   // construct the equation of the parabola from the determinant
00020   // d1->4 are the 4 3x3 minor determinants
00021   // d1 * x^2 - d2 * x + d3 * y - d4 = 0
00022   d1 = x1*y2    + x2*y3    + x3*y1    - x3*y2    - y3*x1    - x2*y1;
00023   d2 = x1*x1*y2 + x2*x2*y3 + x3*x3*y1 - x3*x3*y2 - y3*x1*x1 - x2*x2*y1;
00024   d3 = x1*x1*x2 + x2*x2*x3 + x3*x3*x1 - x3*x3*x2 - x3*x1*x1 - x2*x2*x1;
00025   d4 = x1*x1*x2*y3 + x2*x2*x3*y1 + x1*y2*x3*x3 
00026      - x3*x3*x2*y1 - x1*x1*x3*y2 - x2*x2*x1*y3;
00027 
00028   if( fabs( d3 ) < 1.e-15 ) {
00029     //bpm_warning( "Collinearity issue in nr_quadinterpol()", __FILE__, __LINE__ );
00030     return y2;
00031   }
00032 
00033   // now calculate a,b,c, don't forget the - signs !
00034   // y = a * x^2 + b*x + c
00035   a = - d1 / d3;
00036   b =   d2 / d3;
00037   c =   d4 / d3;
00038 
00039   // return interpolated value at the point x
00040   return a*x*x + b*x + c;
00041 }

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1