Techniquecore
Algebraic distance fitting
Also called algebraic fit.
Fits an implicit curve or surface by least squares of its values at the data points, a linear problem that is exact on noise-free data but biased under noise.
Algebraic distance fitting fits an implicit curve or surface to data points by choosing the coefficients of that make smallest. The value is the algebraic distance of the point . It is zero exactly when the point is on the curve, but it is not the Euclidean distance from the point to the curve. Because is linear in its coefficients, the fit is a linear least squares problem or a small eigenvalue problem, with no iteration and no starting guess. That makes it the usual first step for conics, circles, spheres, quadrics and higher degree implicit polynomials. On points that lie exactly on a curve of the family, the fit returns that curve. On noisy points it does not minimize the geometric distance, and its answer is biased: it depends on how the coefficients are normalized, and for circles on short arcs it is pulled toward circles that are too small. The two fixes are the Taubin fit, which divides by the gradient and minimizes a first-order distance, and the geometric fit, which minimizes the orthogonal distance itself.
In plain words
A curve can be described by a formula that gives zero on the curve and some other number off it. To fit such a curve to measured points, choose the formula so that its values at the points are as close to zero as possible. This is easy to compute.
The catch is that the value of the formula at a point is not the distance from the point to the curve. Some points count more than others, depending on where they are and on the size of the curve. For a circle, the value grows with the radius, so the method likes small circles. When the points cover only a short piece of a circle and have some noise, it returns a circle that is clearly too small. It is a good first guess, and a method that uses true distances should then improve it.
When it applies
- The model is an implicit curve or surface that is linear in its coefficients , for fixed basis functions such as monomials. Circles, spheres, conics, quadrics and implicit polynomials of any degree have this form; a cylinder of fixed radius in a general position does not.
- The data are points in the plane or in space, with , sampled near one curve or surface. Segmentation into one region per model comes first; see primitive segmentation.
- A fast, direct answer is needed: as the final result when the noise is small and the points cover the whole curve, or as the starting point of an iterative geometric fit.
- It does not apply when outliers are present: a single far point can dominate the sum of squares. Then RANSAC or another robust method selects the inliers first.
The template
Write for the vector of basis functions. Then , and the sum of squares is with the design matrix of rows and .
ALGEBRAIC-FIT(x_1..x_m, φ, normalization)- 1
for i ← 1 to m do D[i] ← φ(x_i) - 2
M ← Dᵀ D - 3
if normalization fixes one coefficient, a_k = 1 then - 4
solve the normal equations of the other coefficients - 5
else if normalization is |a| = 1 then - 6
a ← unit eigenvector of the smallest eigenvalue of M - 7
else normalization is aᵀ N a = 1 for a fixed symmetric N - 8
a ← eigenvector of M a = λ N a with the smallest λ ≥ 0, scaled to aᵀ N a = 1 - 9
return the curve aᵀ φ(x) = 0
The holes are the basis , which fixes the family of curves, and the normalization, which fixes the answer under noise.
Why a normalization is needed. The coefficients and for give the same curve, and gives a sum of squares of but no curve. A constraint must rule out and fix the scale. The three common kinds are lines L3 to L8.
Line L4. With the cost is , where is column of and holds the other columns. This is an ordinary linear least squares problem, solved by the normal equations or by a QR factorization.
Lines L6 and L8. A stationary point of subject to satisfies by a Lagrange multiplier. Multiply by : the cost at that point is . So the minimum is the eigenvector of the smallest admissible eigenvalue of the generalized eigenvalue problem, and for it is the smallest eigenvector of , which is the last right singular vector of in the singular value decomposition. The SVD of is the better way to compute it, because forming squares the condition number. The ratio is a generalized Rayleigh quotient.
Exact on noise-free data. If every lies on the curve , then , so the cost is reached at , scaled to meet the normalization (for L4 this needs ; for L8 it needs ). Every minimizer has . The answer is unique up to scale exactly when the null space of has dimension , that is, when the points fix the curve: three points not on a line for a circle, five points in general position for a conic.
What it minimizes, and why it is biased. The cost is a sum of algebraic distances. To first order, , where is the signed geometric distance to the curve; the proof is on the Taubin fit page. So the algebraic fit is a geometric fit in which point has the weight , and that weight depends both on where the point is and on the unknown curve. For a circle the relation is exact. With (the coefficient of fixed at , the Kasa fit) and ,
so the Kasa cost is when the are small against . For the same geometric residuals, a smaller circle has a smaller cost. When the points cover the whole circle, shrinking the circle increases the residuals quickly and the effect is small. On a short arc, a smaller circle through the arc changes the residuals only a little, and the fit returns a circle that is too small. For the ellipse with , a point at geometric distance outside the vertex has , and a point at distance outside has . The same error counts less, by the factor in the square, at the sharp end of the ellipse than on its flat side. The identity and the two values are exact; the size of the bias under noise is a statistical result, measured below and analysed in Chernov's book.
Classic examples
- Plane fitting. For a plane with the normalization , everywhere, so the algebraic distance is the geometric distance and the fit has no bias. The optimal is for the centroid , and is the eigenvector of the smallest eigenvalue of the covariance matrix of the points, as in principal component analysis. This is the orthogonal regression of errors-in-variables models.
- The Kasa circle and sphere. with the leading coefficient fixed at (line L4): a linear system. It is invariant under rotations and translations, because its residual depends only on and . It is the standard starting point for circle fitting and for the least-squares reference feature of a circle in inspection, and it is biased toward small circles on short arcs.
- The Pratt circle. For the radius satisfies , and Pratt's normalization is a quadratic constraint of line L8. It allows , so it also fits lines, and it is invariant under rigid motions.
- Conics. Bookstein's fit of a general conic uses , which is invariant under rotations and translations. The fit may return a hyperbola or a parabola for points from an elliptic arc. Fitzgibbon, Pilu and Fisher use instead, an indefinite in line L8, and the fit then always returns an ellipse.
- Gradient weighting. Taubin's choice , with the Jacobian of at , divides the cost by the mean squared gradient and gives the Taubin fit, which is close to the first-order distance fit.
A measured bias. Twenty points were spaced evenly on an arc of degrees of the unit circle, and independent normal noise of standard deviation was added to each coordinate. The Kasa circle (line L4) and the geometric circle (Gauss-Newton from the Kasa circle) were fitted to such samples, with seed 2026.
| arc | median Kasa radius | median geometric radius | |
|---|---|---|---|
| degrees | |||
| degrees | |||
| full circle |
On the short arc the Kasa radius is too small, and more so as the noise grows; on the full circle both are close to . These are runs on synthetic data, not a proof; the expansion of the bias in powers of is in Chernov's book.
Variations
- Fixed coefficient (Kasa, line L4). The cheapest. It needs the fixed coefficient to be nonzero on the true curve, so the choice of excludes some curves: fixing the coefficient of excludes lines.
- Unit coefficient vector (line L6). The smallest singular vector of . It allows every curve of the family, but it is not invariant: the answer changes when the data are moved or scaled.
- Invariant quadratic constraints (line L8). Bookstein for conics, Pratt for circles and spheres, Fitzgibbon for ellipses only.
- Gradient weighted fits. Taubin's constraint (one generalized eigenproblem), and the iterated version that divides each residual by the gradient at the current estimate, which converges to the first-order (Sampson) distance fit.
- Hyper fit. A further choice of by Al-Sharadqah and Chernov removes the leading term of the bias of the circle fit; it is in Chernov's book.
- Higher degree implicit polynomials. The same template with all monomials up to degree . Taubin's 1991 paper treats this case, with the gradient weighting.
Pitfalls
- The normalization changes the answer. Take the seven rational points of the unit circle with and , and move them radially by for and and by for the others. The fit of gives radius ; after a shift of the data by in and the shift back, ; after a shift by , . The Kasa fit gives for every shift. Use an invariant normalization, or at least center and scale the data first.
- The family is not the type. A general conic or quadric fit returns whatever member of the family is best: a hyperbola for an elliptic arc, a pair of planes for a cylinder patch. Constrain the type (Fitzgibbon) or fit the intended primitive directly.
- Extra branches. The zero set of a polynomial of degree three or more can have components far from the data, or come close to the data where is small. A low cost does not show that the curve looks like the data.
- Bias on short arcs and small patches. In reverse engineering, fillets and partial holes are exactly such patches. Refine with a geometric fit before the radius is used.
- Conditioning. Monomials of coordinates in millimeters far from the origin give a badly conditioned . Translate to the centroid and scale to unit size, solve, and transform the coefficients back.
- Outliers. Squares of algebraic distances grow faster than squares of distances for far points (by the factor for a circle), so one outlier does even more damage than in a geometric fit.
Exercises
- Show that the Kasa circle fit gives the same circle after the data are rotated and translated. Hint: its residual is .
- For the plane with , show that minimizing gives and that is the eigenvector of the smallest eigenvalue of .
- Find the algebraic distance of the point to the circle , and to the same circle written as . Which one is the geometric distance? Answer: and ; neither, the geometric distance is .
References
- Fred L. Bookstein, Fitting conic sections to scattered data, Computer Graphics and Image Processing 9(1), 1979, 56 to 71, the least squares fit of a general conic by its algebraic distance, with the quadratic normalization that is invariant under Euclidean motions
- Vaughan Pratt, Direct least-squares fitting of algebraic surfaces, Computer Graphics 21(4) (SIGGRAPH 87), 1987, 145 to 152, the algebraic fit of implicit curves and surfaces as an eigenvector problem, and the normalization for circles and spheres
- Andrew Fitzgibbon, Maurizio Pilu and Robert B. Fisher, Direct least square fitting of ellipses, IEEE Transactions on Pattern Analysis and Machine Intelligence 21(5), 1999, 476 to 480, the normalization 4ac - b^2 = 1, which makes the algebraic fit return an ellipse, solved as a generalized eigenproblem
- Nikolai Chernov, Circular and Linear Regression, Fitting Circles and Lines by Least Squares, CRC Press, 2010, the chapters on the algebraic circle fits (Kasa, Pratt, Taubin, hyper) and on the statistical bias of these fits
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag K7A2W9 Edit this page History Report an error Markdown