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