core/vnl/algo/vnl_fit_parabola.h
Go to the documentation of this file.
00001 // This is core/vnl/algo/vnl_fit_parabola.h
00002 #ifndef vnl_fit_parabola_h_
00003 #define vnl_fit_parabola_h_
00004 
00005 //:
00006 // \file
00007 // \brief Function to fit a parabola to three point to predict the centre line
00008 // \author Tim Cootes
00009 // \date   Feb 2007
00010 //
00011 // \verbatim
00012 //  Modifications
00013 // \endverbatim
00014 
00015 //: Fit a parabola so as to estimate the position of the centre line
00016 //  The centre (maxima or minima) lies at xb + p/q.
00017 //  If q is near zero, then the parabola is nearly flat
00018 inline void vnl_fit_parabola(double xa, double xb, double xc,
00019                              double fa, double fb, double fc,
00020                              double& p, double& q)
00021 {
00022   // Effectively shift origin to (xb,fb)
00023   // Parabola is then y=a*x*x+b*x
00024   // Centre is then at -b/2a = p/q in the following
00025   double x1=xa-xb, f1 = fa-fb;
00026   double x2=xc-xb, f2 = fc-fb;
00027   p = x2*x2*f1-x1*x1*f2;
00028   q = 2*(x2*f1-x1*f2);
00029 }
00030 
00031 #endif // vnl_fit_parabola_h_