6

There is a conic-section with this implicit form:

$$ f(x,y) = ax^2 + 2bxy + cy^2 + 2dx + 2ey + f = 0 $$

I would like to write a program, which draws it, but I have no idea where to start. I could use a brute-force method, calculate it for each pixel, and the point is on the curve, if the value is around zero. But I am looking for a better solution.

Iter Ator
  • 618
  • 1
    Don't know about a general form, but you could separate the conics into classes and use well known parametric forms (i.e. v. hyperbola - $x(t)=a\sec(t),,, y(t)=b\tan(t)$, h. hyperbola - $x(t) = a \cosh(t),,, y(t)=b\sinh(t)$, ...). I think this might be a better approach than finding a general solution. – Dando18 Jun 05 '17 at 15:15
  • Yes. Seems like you'll have to look at the discriminant and go from there. – sharding4 Jun 05 '17 at 15:17

3 Answers3

3

$$ax^2 + 2bxy + cy^2 + 2dx + 2ey + f = 0 $$ $$cy^2 + 2(bx + e)y + (ax^2 + 2dx + f) = 0 $$ $$y_1(x)=\frac{(bx+e)+\sqrt{(bx+e)^2-c(ax^2 + 2dx + f)}}{c}$$ $$y_2(x)=\frac{(bx+e)-\sqrt{(bx+e)^2-c(ax^2 + 2dx + f)}}{c}$$ Draw successively the two functions. The whole is $y(x)$.

You can scan point after point the considered range of $x$. If $(bx+e)^2-c(ax^2 + 2dx + f)>0$ compute $y$ and plot $(x,y)$. If not, of course don't compute $y$ nor plot it.

JJacquelin
  • 68,401
  • 4
  • 40
  • 91
  • 1
    Do need to handle $c=0$ as a separate case. – sharding4 Jun 05 '17 at 15:24
  • 1
    Yes, sure. My answer gives the principle. It's even easier to find the function $y(x)$ in case of $c=0$. Then, more sub-cases have to be considered. I suppose that one can continue on this way without much difficulty. – JJacquelin Jun 05 '17 at 15:27
3

For the General Parabola $$(Ax+Cy)^2+Dx+Ey+F=0$$ a possible parametric form is

$$\color{red}{\left(\frac {Ct^2-Et+CF}{AE-CD}, -\frac{At^2-Dt+AF}{AE-CD}\right)}$$

See this answer here.

Equating coefficients with the form of the general conic given in the question, i.e. $$ax^2+2bxy+cy^2+2dx+2ey+f=0$$ gives $$a=A^2\\ b=AC\\ c=C^2\\ d=\frac D2\\ e=\dfrac E2\\ f=F$$

1
a = 3; b = 2; h = 2; k = 1; (* Ellipse *)
x[u_, v_] = (a Cos[u] + h) Cos[v] - (b Sin[u] + k) Sin[v]
    y[u_, v_] = (a Cos[u] + h) Sin[v] + (b Sin[u] + k) Cos[v]
ParametricPlot[{x[u, v], y[u, v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}]
(* Hyperbola *)
x[u_, v_] = (a Cosh[u] + h) Cosh[v] - (b Sinh[u] + k) Sinh[v]
    y[u_, v_] = (a Cosh[u] + h) Sinh[v] + (b Sinh[u] + k) Cosh[v]
ParametricPlot[{x[u, v], y[u, v]}, {u, -1, 1}, {v, 0, 2 Pi}]

from Mathematica, did not Latex it for clarity..

Conics with principal axes parallel to coordinate axes $u$ generator circle rotation and $v,$ the rigid conic rotation.

For hyperbolic cases added $h$, $ \cos \rightarrow \cosh ..$

Narasimham
  • 42,260