|
@ -46,23 +46,23 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) { |
|
|
if (N == 0.0) |
|
|
if (N == 0.0) |
|
|
return 1; |
|
|
return 1; |
|
|
|
|
|
|
|
|
lsf->xbar /= N; |
|
|
const float RN = 1.0f / N, |
|
|
lsf->ybar /= N; |
|
|
xbar = lsf->xbar * RN, |
|
|
lsf->zbar /= N; |
|
|
ybar = lsf->ybar * RN, |
|
|
lsf->x2bar = lsf->x2bar / N - sq(lsf->xbar); |
|
|
zbar = lsf->zbar * RN, |
|
|
lsf->y2bar = lsf->y2bar / N - sq(lsf->ybar); |
|
|
x2bar = lsf->x2bar * RN - sq(xbar), |
|
|
lsf->z2bar = lsf->z2bar / N - sq(lsf->zbar); |
|
|
y2bar = lsf->y2bar * RN - sq(ybar), |
|
|
lsf->xybar = lsf->xybar / N - lsf->xbar * lsf->ybar; |
|
|
xybar = lsf->xybar * RN - xbar * ybar, |
|
|
lsf->yzbar = lsf->yzbar / N - lsf->ybar * lsf->zbar; |
|
|
yzbar = lsf->yzbar * RN - ybar * zbar, |
|
|
lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar; |
|
|
xzbar = lsf->xzbar * RN - xbar * zbar, |
|
|
const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar); |
|
|
DD = x2bar * y2bar - sq(xybar); |
|
|
|
|
|
|
|
|
if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) |
|
|
if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) |
|
|
return 1; |
|
|
return 1; |
|
|
|
|
|
|
|
|
lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD; |
|
|
lsf->A = (yzbar * xybar - xzbar * y2bar) / DD; |
|
|
lsf->B = (lsf->xzbar * lsf->xybar - lsf->yzbar * lsf->x2bar) / DD; |
|
|
lsf->B = (xzbar * xybar - yzbar * x2bar) / DD; |
|
|
lsf->D = -(lsf->zbar + lsf->A * lsf->xbar + lsf->B * lsf->ybar); |
|
|
lsf->D = -(zbar + lsf->A * xbar + lsf->B * ybar); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|