-2

I have a (homegrown) tool which takes a set of data points and finds the best-fit parabola by finding a rotation angle which gives the best vertical parabola by fitting the rotated data to a standard $ax^2 + bx + c$ form. My answer then can generate the putative parabola only by rotating by $\theta$ after generating the vertical parabola. That is, for $ y(x) = ax^2 + bx + c $ , the final curve is

$x' = x*cos(\theta) - y(x)*sin(\theta) $
$y' = x*sin(\theta) + y(x)*cos(\theta) $
What I'm looking for is an algorithm to convert the parameter set $ {(\theta,a,b,c)} $ to the form $ Ax^2 + Bxy + Cy^2 + Dx +Ey + F = 0$ .

Note: yes, I got into this mess by trying to write a Q&D fitting function rather than doing a nonlinear matrix minimization over $\{A,B,C,D,E,F\}$ .

Carl Witthoft
  • 320
  • 2
  • 12
  • NB yes I can run thru the gross steps of solving the quadratic for y' in terms of x' to eliminate x and y , but was hoping there's a better way. – Carl Witthoft Nov 14 '16 at 20:33
  • What’s wrong with simply applying the rotation and collecting terms? If you need to invert the transformation, that’s trivial: observe that the inverse of a rotation through $\theta$ is a rotation through $-\theta$. – amd Nov 15 '16 at 01:23
  • @amd nothing particularly "wrong," just ugly :-( – Carl Witthoft Nov 15 '16 at 12:22
  • Tenor Clef... You must play the cello, bassoon or trombone. Or you just like symmetrical clefs. :) – Hypergeometricx Nov 15 '16 at 14:24
  • @hypergeometric yep, the 'cello. – Carl Witthoft Nov 15 '16 at 14:26
  • Why do you think you need to solve for $y'$? Simply substitute for $x$ and $y$ in the equation you have. Rewrite it as $ax^2+bx-y+c=0$ first, if you must. – amd Nov 15 '16 at 19:02
  • FWIW, if anyone's interested, I finished this project successfully and posted the package conicfit to CRAN. https://cran.r-project.org/web/packages/fitConic/index.html Not to be confused with fitconic , which has some errors and bugs. – Carl Witthoft Apr 27 '23 at 13:22

1 Answers1

1

There’s no need to solve for $y'$. In fact, for a rotated parabola, $y'$ is not a function of $x'$, anyway.

Recall that the inverse of a rotation through $\theta$ is a rotation through $-\theta$, so the inverse transformation is $$\begin{align}x&=x'\cos\theta+y'\sin\theta\\y&=-x'\sin\theta+y'\cos\theta.\end{align}$$ Substitute this into the equation $y=ax^2+bx+c$ and collect terms.

If this is too “ugly,” try writing the equations in matrix form. The general-form equation $Ax^2+Bxy+Cy^2+Dx+Ey+F=0$ can be expressed as $(x,y,1)\,M\,(x,y,1)^T=0$, where $$M=\pmatrix{A&\frac B2&\frac D2\\\frac B2&C&\frac E2\\\frac D2&\frac E2&F}.$$ Rotating the coordinate system amounts to replacing $(x,y,1)^T$ by $R\,(x',y',1)^T$, where $R$ is a homogeneous rotation matrix, so the coefficient matrix for the rotated quadratic will be $R^TMR$. If you multiply this out, you can then read the coefficients of the rotated general-form equation directly from the result.

In this particular case, we have $ax^2+bx-y+c-0$, so $$M=\pmatrix{a&0&\frac b2\\0&0&-\frac12\\\frac b2&-\frac12&c}.$$

amd
  • 53,693