Listing 3: The parabolic and line fits
Listing 3: The parabolic and line fits
// do a parabolic fit of the three points centered at k
// return the results in X and Y
void para_fit(int k, double &X, double &Y){
assert(npoints >= 3);
assert((k > 0) && (k < npoints-1));
double m0 = (y[k] - y[k-1])/(x[k] - x[k-1]);
double m1 = (y[k+1] - y[k])/(x[k+1] - x[k]);
double m = (y[k+1] - y[k-1])/(x[k+1] - x[k-1]);
double c = (m1 - m0)/(x[k+1] - x[k-1]);
X = (x[k-1] + x[k+1] - m/c)/2.0;
Y = y[k-1] - c*X*X;
}
// do a "wide" parabolic fit of the three points x0, x2, and x4
// return the results in X and Y
void para_wide(double &X, double &Y){
assert(npoints ==5);
double m0 = (y[2] - y[0])/(x[2] - x[0]);
double m1 = (y[4] - y[2])/(x[4] - x[2]);
double m = (y[4] - y[0])/(x[4] - x[0]);
double c = (m1 - m0)/(x[4] - x[0]);
X = (x[0] + x[4] - m/c)/2.0;
Y = y[0] - c*X*X;
}
// Fit straight lines through the outer two pairs of points,
// and find the intersection.
// return the results in X and Y
void line_fit(double &X, double &Y){
assert(npoints ==5);
double m0 = (y[1] - y[0])/(x[1] - x[0]);
double m3 = (y[4] - y[3])/(x[4] - x[3]);
X = (m3*x[3] + m0*x[0] - (y[3]-y[0]))/(m3-m0);
Y = y[0] + m0*(X-x[0]);
}
|