Ellipse fitting in python?

R

Ron Kneusel

Is there a python package out there that supports fitting a set of 2D
points to an ellipse? I haven't been able to find one.

Thanks!

Ron
 
J

John J. Lee

Is there a python package out there that supports fitting a set of 2D
points to an ellipse? I haven't been able to find one.

This is a set of points with some noise (scatter), right?

A not-very-thoughtful answer: a sledgehammer method is to throw an
implementation of a standard nonlinear least-squares algorithm at the
problem. For example, SciPy contains a wrapper of MINPACK's nonlinear
LS solver . There are several implementations of the same
(Levenburg-Marquardt) algorithm in pure Python floating around, too.

If there's no scatter, it's time to dig out your old algebra textbooks
:)


John
 
F

Fernando Perez

John said:
This is a set of points with some noise (scatter), right?

A not-very-thoughtful answer: a sledgehammer method is to throw an
implementation of a standard nonlinear least-squares algorithm at the
problem. For example, SciPy contains a wrapper of MINPACK's nonlinear
LS solver . There are several implementations of the same
(Levenburg-Marquardt) algorithm in pure Python floating around, too.

A quick comment in case it's not obvious: an ellipse is not a function in
Cartesian coordinates, and most standard LS solvers expect a function. So
it's probably best to convert things over to polar before feeding the data to
the LS solver.

f
 
H

Helmut Jarausch

Ron said:
Is there a python package out there that supports fitting a set of 2D
points to an ellipse? I haven't been able to find one.

It's not so easy; it's a nonlinear orthogonal distance regression problem.
I know of a FORTRAN package and I myself have a (more general) package written
in Scilab ( a Matlab "clone" )

If you have just a few datasets, I'll compute a fit for you.
But implementing it in Python would be much work.


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
C

Christopher T King

A quick comment in case it's not obvious: an ellipse is not a function in
Cartesian coordinates, and most standard LS solvers expect a function. So
it's probably best to convert things over to polar before feeding the data to
the LS solver.

You could break both the ellipse and the data into two pieces (say, y>=K
and y<K). Polar coordinates might get you more uniform results, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top