You've collected coordinate pairs from an experiment. You suspect they trace an ellipse or hyperbola, but you need the exact equation. Three points nail a circle. Five points lock in any conic section.
Here's how to translate five coordinates into a full curve equation using straightforward linear algebra.
The General Form
Every ellipse, hyperbola, and parabola follows this structure:
Ax² + Bxy + Cy² + Dx + Ey + F = 0
Six coefficients define the shape completely. But multiplying everything by the same constant doesn't change the curve—only the ratios matter. That redundancy leaves us five degrees of freedom, which matches our five data points.
Turning Points into Equations
Substitute each (x, y) pair into the general form and rearrange:
Ay² + Bxy + Cx + Dy + E = −x²
Each point gives one equation. Stack all five into a matrix system **Ms = b** where the rows contain [y², xy, x, y, 1] and the right-hand side holds −x² values.
Set A to 1 as a normalization step, then solve for the remaining five coefficients. Add more rows to handle noisy measurements in the least-squares sense.
Checking Your Work
Once you have coefficients A through F, verify by plugging your original points back into the equation. The result should be essentially zero—floating-point precision might leave a tiny residual, but anything significantly larger means something went wrong.
The discriminant Δ = 4AB − C² tells you what curve type you found. Positive Δ means ellipse. Negative Δ means hyperbola. Zero Δ means parabola.
Why It Matters
This approach transforms geometric problems into linear algebra exercises. The matrix structure stays constant regardless of whether your data describes an orbital path, an optical distortion, or an industrial measurement. That consistency makes it reliable for automated pipelines.
Numerical stability deserves attention in practice. Points clustered together or nearly linear produce poorly conditioned matrices—the solution exists mathematically but the numbers blow up in floating-point arithmetic. For production work with real data, overdetermined systems with ten or twenty points spread the error and yield more reliable coefficients. Always check your matrix's condition number before trusting the results.
The flexibility to handle extra points via least squares explains why this method appears in computer vision for ellipse detection, in photogrammetry for camera calibration, and in astronomy for fitting orbital sections. You're not just solving a math puzzle—you're using the same infrastructure that analyzes telescope imagery and tracks objects in video streams.
Who should care:
- Engineers and scientists** fitting experimental data to conic sections
- Computer vision practitioners** detecting circular or elliptical features in images
- Data analysts** working with geometric transformations and calibration
What to Watch Next
When coordinates come from real measurements, expect small errors in every observation. Use overdetermined systems rather than exactly five points. Solve in the least-squares sense to get a curve that best fits the trend rather than exactly hitting every noisy point. This spreads measurement uncertainty across all observations and produces more solid results than the minimal-case solution.
Key takeaways
- Five independent coordinates yield a unique conic section
- Six coefficients in the general form, five solved from data after normalizing A = 1
- The matrix structure stays constant across curve types
- Discriminant 4AB − C² reveals ellipse, hyperbola, or parabola
- More points enable solid fitting when data contains errors
- Check matrix condition number before trusting results from real data
Frequently asked questions
What happens if my points lie on a line?
The matrix becomes singular and cannot be solved. Degenerate cases also occur with exact parabolas or duplicate points.
Can I use this for circles too?
Circles are a constrained ellipse case. Three points determine a circle using a simpler formula, though the matrix method works if you impose the right constraints.
Which programming languages support this?
Python with NumPy is most common. MATLAB, R, and Julia offer equivalent matrix operations. JavaScript and Java have numerical libraries available.
How accurate are the results?
With exact input data, coefficients are exact up to floating-point precision. With real noisy data, accuracy depends on measurement quality and point distribution.
What makes a good input set?
Spread points across the full extent of the curve. Clustered points amplify numerical errors and produce unreliable coefficients.
Source: johndcook.com