X-Git-Url: http://git.johnwright.org/?p=fmit.git;a=blobdiff_plain;f=libs%2FCppAddons%2FFit.h;fp=libs%2FCppAddons%2FFit.h;h=a0cc638ceed166d6236ab6d2b19445a910a33e03;hp=4ced5f435bfaab9a9161396f0b8b94adbee1265d;hb=49947d1cd4506f5574b3be62ee90e9f00227d9fd;hpb=82c9faab9421b3d87a0faa84a73f55aaccbbb689 diff --git a/libs/CppAddons/Fit.h b/libs/CppAddons/Fit.h index 4ced5f4..a0cc638 100644 --- a/libs/CppAddons/Fit.h +++ b/libs/CppAddons/Fit.h @@ -21,8 +21,21 @@ namespace Math { - void FitParabola(double x1, double y1, double x2, double y2, double x3, double y3, - double& a, double& b, double& c, double& xapex, double& yapex); + inline void FitParabola(double x1, double y1, double x2, double y2, double x3, double y3, + double& a, double& b, double& c, double& xapex, double& yapex) + { + assert(x1!=x2 && x1!=x3 && x2!=x3); + + double h31 = (y3-y1)/(x3-x1); + double h21 = (y2-y1)/(x2-x1); + + a = (h31-h21)/(x3-x2); + b = h21 - a*(x2+x1); + c = y1 - a*x1*x1 - b*x1; + + xapex = -b/2/a; + yapex = c - b*b/4/a; + } } #endif