I have a problem and I haven´t been able to solve it. The problem is in the area of least-square fitting. Someone drew a sort of "conic" figure on a canvas (i.e. a MATLAB plot) so I have a series of points ($x_i$, $y_i$). Now I need for this points to adjust to a perfect "conic" using least-square fitting.
I now how to do this over a line $f(x) = ax + b$, but I don't know what to do with the general conic equation $Ax^2+Bxy+Cy^2+Dx+Ey+F = 0$
Can someone point me into the right direction.
Some remarks I've been working around:
- that is an equation, not a function, do i need to parametrize it? how to?
- Don't know what to do with rectangle term ($Bxy$)
Thanks in advance.
PS: If there was something unclear, please say so and I'll try to explain myself.
PS.1: MATLAB code will be appreciated
Edit:
After checking what @ClaudeLeibovici suggested I got working an example on MATLAB where after getting the points I solve the system of equations given in the french paper and It plotted a perfet circle as I needed (using ezplot with the "explicit equation"), but it does not satisfies Hyperbolas or Parabolas, just circles and elipses. And i need to fit any conic.
Sometimes I get what it looks like to be an hyperbola, sometimes not in the right direction and sometimes not even close to the one I "drew".
Anyhow, I will apreciate if someone could explain me where did the "Generalization for conics" from the paper came from? and what does it means in a least-square sense?
I tried reading it, but couldn't understand it very well, cause I do not speak nor understand french, and the translation wasn't good. I need to understand what is going on cause I need to do a presentation about this.
Thanks in advance
PS: I used $F=1$ as suggested.
The basic idea is to minimize $$\Phi=\sum_{i=1}^n (Ax_i^2+Bx_iy_i+Cy_i^2+Dx_i+Ey_i+F)^2$$ Take the derivatives with respect to each parameter and set it equal to $0$.
If you are lazy, define $z_i=0$ for all $i$'s and perform a least square fit for $$z=Ax^2+Bxy+Cy^2+Dx+Ey+F$$ Just a multilinear regression then.
Warning : As JeanMarie commented, set $F=1$ or whatever number you want. This fix to $5$ the number of parameters to be adjusted. And $5$ is the minimum number of points which define a general conic not going through the origin.