Conic Fit
Source inspiration: (Mathew 2000-2019).
Determinant-Based Conic Fitting
Given data points \((x_i,y_i)\) in the plane, we fit an implicit curve
\[ F(x,y)=0 \]
so every data point satisfies the equation exactly.
A planar conic can be written as \[ Ax^2+Bxy+Cy^2+Dx+Ey+F=0, \tag{1} \] with coefficients not all zero.
Five points determine a unique conic (up to a nonzero scale factor) when they are in general position, meaning they do not force a degenerate rank condition in the fitting system.
Core Determinant Formulas
For a symbolic point \((x,y)\) and data points \((x_i,y_i)\), the legacy module uses determinants so that replacing the first row by a point row forces that point onto the curve.
Line through two points: \[ \det\begin{pmatrix} x & y & 1\\ x_1 & y_1 & 1\\ x_2 & y_2 & 1 \end{pmatrix}=0. \tag{2} \]
Circle through three points: \[ \det\begin{pmatrix} x^2+y^2 & x & y & 1\\ x_1^2+y_1^2 & x_1 & y_1 & 1\\ x_2^2+y_2^2 & x_2 & y_2 & 1\\ x_3^2+y_3^2 & x_3 & y_3 & 1 \end{pmatrix}=0. \tag{3} \]
Standard parabola model \(y=ax^2+bx+c\): \[ \det\begin{pmatrix} x^2 & x & 1 & y\\ x_1^2 & x_1 & 1 & y_1\\ x_2^2 & x_2 & 1 & y_2\\ x_3^2 & x_3 & 1 & y_3 \end{pmatrix}=0. \tag{4} \]
Alternate parabola model \(x=ay^2+by+c\): \[ \det\begin{pmatrix} y^2 & y & 1 & x\\ y_1^2 & y_1 & 1 & x_1\\ y_2^2 & y_2 & 1 & x_2\\ y_3^2 & y_3 & 1 & x_3 \end{pmatrix}=0. \tag{5} \]
Standard ellipse model \(Ax^2+Cy^2+Dx+Ey+F=0\): \[ \det\begin{pmatrix} x^2 & y^2 & x & y & 1\\ x_1^2 & y_1^2 & x_1 & y_1 & 1\\ x_2^2 & y_2^2 & x_2 & y_2 & 1\\ x_3^2 & y_3^2 & x_3 & y_3 & 1\\ x_4^2 & y_4^2 & x_4 & y_4 & 1 \end{pmatrix}=0. \tag{6} \]
General five-point conic: \[ \det\begin{pmatrix} x^2 & xy & y^2 & x & y & 1\\ x_1^2 & x_1y_1 & y_1^2 & x_1 & y_1 & 1\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ x_5^2 & x_5y_5 & y_5^2 & x_5 & y_5 & 1 \end{pmatrix}=0. \tag{7} \]
Example 1 - Line Through Two Points
Find the line through \((1,4)\) and \((5,3)\).
Step 1: Use the two-point form.
\[ \frac{y-4}{x-1}=\frac{3-4}{5-1}=-\frac14. \]
Step 2: Rearrange to implicit form.
\[ y=-\frac14x+\frac{17}{4} \quad\Longrightarrow\quad x+4y-17=0. \]
The fitted line is
\[ \boxed{x+4y-17=0}. \]
Verification:
| Point | Left-hand side \(x+4y-17\) | Result |
|---|---|---|
| \((1,4)\) | \(1+16-17=0\) | \(0=0\;\checkmark\) |
| \((5,3)\) | \(5+12-17=0\) | \(0=0\;\checkmark\) |
Example 2 - Circle Through Three Points
Find the circle through \((6,1)\), \((2,2)\), and \((1,4)\).
Assume
\[ x^2+y^2+Dx+Ey+F=0. \]
Step 1: Substitute each point.
\[ \begin{aligned} 37+6D+E+F&=0,\\ 8+2D+2E+F&=0,\\ 17+D+4E+F&=0. \end{aligned} \]
Step 2: Solve for \((D,E,F)\).
\[ D=-\frac{67}{7}, \quad E=-\frac{65}{7}, \quad F=\frac{208}{7}. \]
Hence
\[ x^2+y^2-\frac{67}{7}x-\frac{65}{7}y+\frac{208}{7}=0, \]
or equivalently
\[ \boxed{7x^2+7y^2-67x-65y+208=0}. \]
Verification:
| Point | Left-hand side \(7x^2+7y^2-67x-65y+208\) | Result |
|---|---|---|
| \((6,1)\) | \(252+7-402-65+208=0\) | \(0=0\;\checkmark\) |
| \((2,2)\) | \(28+28-134-130+208=0\) | \(0=0\;\checkmark\) |
| \((1,4)\) | \(7+112-67-260+208=0\) | \(0=0\;\checkmark\) |
Example 3 - Same Three Points, Two Parabola Models
Use \((6,1)\), \((2,2)\), and \((1,4)\).
(a) Standard form \(y=ax^2+bx+c\)
Step 1: Build the linear system.
\[ \begin{aligned} 36a+6b+c&=1,\\ 4a+2b+c&=2,\\ a+b+c&=4. \end{aligned} \]
Step 2: Solve.
\[ a=\frac{7}{20}, \quad b=-\frac{61}{20}, \quad c=\frac{67}{10}. \]
So
\[ \boxed{7x^2-61x-20y+134=0}. \]
(b) Alternate form \(x=ay^2+by+c\)
Step 1: Build the linear system.
\[ \begin{aligned} a+b+c&=6,\\ 4a+2b+c&=2,\\ 16a+4b+c&=1. \end{aligned} \]
Step 2: Solve.
\[ a=\frac{7}{6}, \quad b=-\frac{15}{2}, \quad c=\frac{37}{3}. \]
So
\[ \boxed{7y^2-45y-6x+74=0}. \]
Verification:
| Point | \(7x^2-61x-20y+134\) | \(7y^2-45y-6x+74\) |
|---|---|---|
| \((6,1)\) | \(252-366-20+134=0\) | \(7-45-36+74=0\) |
| \((2,2)\) | \(28-122-40+134=0\) | \(28-90-12+74=0\) |
| \((1,4)\) | \(7-61-80+134=0\) | \(112-180-6+74=0\) |
Example 4 - Standard Ellipse Model Through Four Points
Fit the model
\[ Ax^2+Cy^2+Dx+Ey+F=0 \]
through \((6,1)\), \((2,2)\), \((1,4)\), \((9,2)\).
Step 1: Substitute the four points.
\[ \begin{aligned} 36A+C+6D+E+F&=0,\\ 4A+4C+2D+2E+F&=0,\\ A+16C+D+4E+F&=0,\\ 81A+4C+9D+2E+F&=0. \end{aligned} \]
Because conics are scale-invariant, set \(A=3\) and solve for the remaining coefficients.
Step 2: Solve.
\[ C=8, \quad D=-33, \quad E=-60, \quad F=142. \]
Hence
\[ \boxed{3x^2+8y^2-33x-60y+142=0}. \]
Verification:
| Point | Left-hand side \(3x^2+8y^2-33x-60y+142\) | Result |
|---|---|---|
| \((6,1)\) | \(108+8-198-60+142=0\) | \(0=0\;\checkmark\) |
| \((2,2)\) | \(12+32-66-120+142=0\) | \(0=0\;\checkmark\) |
| \((1,4)\) | \(3+128-33-240+142=0\) | \(0=0\;\checkmark\) |
| \((9,2)\) | \(243+32-297-120+142=0\) | \(0=0\;\checkmark\) |
Example 5 - Legacy Five-Point Conic (Example 8)
Legacy data points:
\[ \left(\tfrac72,\tfrac52\right), \ (2,2), \ \left(\tfrac52,\tfrac72\right), \ (7,5), \ \left(\tfrac{19}{2},7\right). \]
Assume the general form
\[ Ax^2+Bxy+Cy^2+Dx+Ey+F=0. \]
Step 1: Substitute the five points to get a homogeneous linear system for \(A,B,C,D,E,F\).
Step 2: Solve up to scale.
\[ (A,B,C,D,E,F)=(2,-4,2,-1,-1,4). \]
Therefore the fitted conic is
\[ \boxed{2x^2-4xy+2y^2-x-y+4=0}. \]
Verification:
| Point | Left-hand side \(2x^2-4xy+2y^2-x-y+4\) | Result |
|---|---|---|
| \(\left(\tfrac72,\tfrac52\right)\) | \(0\) | \(0=0\;\checkmark\) |
| \((2,2)\) | \(0\) | \(0=0\;\checkmark\) |
| \(\left(\tfrac52,\tfrac72\right)\) | \(0\) | \(0=0\;\checkmark\) |
| \((7,5)\) | \(0\) | \(0=0\;\checkmark\) |
| \(\left(\tfrac{19}{2},7\right)\) | \(0\) | \(0=0\;\checkmark\) |
Classification by Discriminant
For
\[ Ax^2+Bxy+Cy^2+Dx+Ey+F=0, \]
the discriminant is
\[ \Delta=B^2-4AC. \tag{8} \]
- If \(\Delta<0\): ellipse (or circle as a special case).
- If \(\Delta=0\): parabola.
- If \(\Delta>0\): hyperbola (including intersecting-line degeneracies).
Additional Legacy Five-Point Results
The remaining legacy five-point examples follow exactly the same workflow as Example 5.
| Legacy example | Point set | Conic equation | Type by \(\Delta\) |
|---|---|---|---|
| 9 | \(\left(\tfrac{14}{5},\tfrac{22}{5}\right),(2,2),\left(\tfrac{22}{5},\tfrac{14}{5}\right),(7,5),(10,10)\) | \(17x^2-30xy+17y^2-24x-24y+80=0\) | Ellipse (\(\Delta=-256\)) |
| 10 | \(\left(\tfrac74,\tfrac{13}{4}\right),(2,2),\left(\tfrac{31}{12},\tfrac74\right),\left(\tfrac{13}{4},\tfrac74\right),\left(\tfrac{38}{5},\tfrac{14}{5}\right)\) | \(3x^2-10xy+3y^2+16=0\) | Hyperbola (\(\Delta=64\)) |
| 11 | \((1,1),(3,5),(5,4),(7,3),(9,7)\) | \(3x^2+2xy-8y^2-38x+54y-13=0\) | Hyperbola (\(\Delta=100\)) |
| 12 | \((1,8),(2,1),(8,9),(9,2),(10,5)\) | \(x^2+y^2-10x-10y+25=0\) | Ellipse (\(\Delta=-4\)) |
Each equation above was checked by substitution at all five listed points.