2

I have been thinking about the following problem. I have a curve in 2D space (x,y), described by the following equation:

$$ax^2+bxy+cy^2+d=0$$

where $a,b,c,d$ are known. It is obvious that it is a 1D curve embedded in a 2D space. So I would think there could be such a description of the curve, where only single parameter is present.

It is obvious that you can plug $x$ and then solve a quadratic equation for $y$, but that is not what I'm looking for. The solution I expect is in the form

$$x=f_x(t), y=f_y(t), t\in?$$

which can be used in the case of circle equation with sine and cosine of angle.

My goal is to plot the curve in python, so I would like to start at some point of the curve and trace along it. Could you point me to a solution or some materials which are dedicated for such problems?

Thank, r

mathreadler
  • 25,824
  • https://en.wikipedia.org/wiki/Conic_section – Jean-Claude Arbaut May 11 '19 at 22:01
  • If you’re going to be plotting these curves pixel by pixel, consider coding up an old-school DDA. If you can’t find one specifically for plotting hyperbolas, an incremental plotting algorithm for ellipses isn’t too hard to adapt. – amd May 11 '19 at 22:47

3 Answers3

1

Assuming $a>0$ and $c>0$, why not to use $$x=\frac{r \cos (t)}{\sqrt{a}}\qquad \text{and} \qquad y=\frac{r \sin (t)}{\sqrt{c}}$$ which make $ax^2+bxy+cy^2+d$ to become $$r^2 \left(1+\frac{b \sin (2t) }{2\sqrt{ac} }\right)+d=0$$ then $r$ that you replace now in $x$ and $y$.

  • Thank you very much, I did not realize that the solution would require conditions on parameters. In my specific case $a$ and $b$ are positive, $c$ is negative and $d$ is not constrained. The result is a field line of an electric field. – Radek Svoboda May 06 '19 at 17:35
1

With the additional information that $a,b\gt0$ and $c\lt0$, your equation is that of a hyperbola centered at the origin. When $d=0$, it degenerates to a pair of intersecting lines—the asymptotes of the one-parameter family of hyperbolas obtained by holding the other three parameters fixed. I expect that this you’re ultimately going to be plotting several members of this family (for various values of $d$) since you mentioned that these equations represent electric field lines.

A standard parameterization of a hyperbola is, in vector form, $$\mathbf p(t) = \mathbf p_0 \pm \mathbf u \cosh t + \mathbf v \sinh t \tag1$$ where $\mathbf p_0$ is the hyperbola’s center, $\mathbf p_0+\mathbf u$ a point on the hyperbola, and $\mathbf v$ a tangent vector at this point with length chosen such that $\mathbf p_0+\mathbf u+\mathbf v$ lies on an asymptote of the hyperbola. It’s convenient to take $\mathbf u$ in the direction of the transverse axis, i.e., as the vector from the center to one of the vertices, in which case $\mathbf v$ will correspond to the conjugate half-axis. In fact, this parameterization is the image of the unit hyperbola $(\pm\cosh t,\sinh t)$ under the affine transformation $\mathbf x\mapsto \mathbf p_0+\small{\begin{bmatrix}\mathbf u&\mathbf v\end{bmatrix}}\mathbf x$.

A lesser-known, but potentially useful parameterization derives from an affine transformation of $y=\frac1x$: $$\mathbf p(t) = \mathbf p_0 +t\,\mathbf v_1+\frac1t\,\mathbf v_2, t \ne 0. \tag2$$ Here, $\mathbf v_1$ and $\mathbf v_2$ parallel the hyperbola’s asymptotes and $\mathbf p_0+\mathbf v_1+\mathbf v_2$ lies on the hyperbola. If $\mathbf v_1$ and $\mathbf v_2$ have the same length, then $t=\pm1$ gives the hyperbola’s vertices.

For your hyperbolas, $\mathbf p_0=0$. Their common asymptotes can be found by splitting the degenerate conic obtained with $d=0$ to get the lines $$y = -{b\pm\sqrt{b^2-4ac}\over2c}x,$$ i.e., we can take suitable scalar multiples of $\left(-2c,b\pm\sqrt{b^2-4ac}\right)$ for $\mathbf v_1$ and $\mathbf v_2$ in parameterization (2). The axis directions are the angle bisectors of these two lines, the directions of which you can compute from these vectors. Alternatively, the hyperbolas’ axes are at an angle $\varphi$ from the coordinate axes such that $\tan{2\varphi}=\frac b{a-c}$. One other way to find the axis directions is to compute the eigenvalues and eigenvectors of the associated matrix. This can be a convenient way to go when developing parameterization (1) because you can get the semiaxis lengths directly from the eigenvalues. The general expressions for these are a bit messy, but not too bad since the equation doesn’t have any linear terms. These asymptotes and axis direction vectors are constant over the entire family of hyperbolas, so you need only compute them once and then adjust the vector lengths (and possibly signs) for different values of $d$.

Another possibility is to create a rational parameterization directly: Pick a fixed point on the hyperbola and let $m$ be the varying slope of a line through this point. The other intersection of each of these lines with the hyperbola will give you a pair of rational functions of $m$. This method can be used to generate a rational parameterization of not only a hyperbola, but of any nondegenerate conic.

There are some other parameterizations listed here in the Wikipedia article on hyperbolas that might work better for your purposes. They are all parameterizations of a hyperbola in standard position, so they’ll take a bit of work to adapt to your situation.

You might also try converting to polar coordinates, a la Claude Lebovici’s answer. This isn’t as convenient as it might be for an ellipse since the curve is restricted to certain ranges of polar angle. Substituting directly into your Cartesian equation produces $$r^2 = {-d\over a\cos^2\theta+b\cos\theta\sin\theta+c\sin^2\theta}.$$ However, if you offset the polar angle by $\phi$ or $\phi+\frac\pi4$ from above, you can get this equation into the form $$r = {B\over\sqrt{e^2\cos^2\theta'-1}},$$ where $e$ is the eccentricity and $B$ the conjugate axis half-length. In this form, the valid range of $\theta'$ for the right branch is $-\arctan\frac1e\lt\theta'\lt\arctan\frac1e$.

amd
  • 53,693
0

The solution of the quadratic equation gives you one kind of parameterization of the ellipse, though you may not like it. You could find the minimum and maximum values of $x$ and let $x$ go from the minimum to the maximum and back again to the minimum as $t$ increases. Going in one direction you set $y$ to one of the solutions of the quadratic, and in the other direction you set $y$ to the other solution, so that $y$ is also a function of $t.$

There are other ways, however.

Since the equation is a quadratic equation in $x$ and $y,$ there are only a limited number of kinds of shapes that can solve it, and we can quickly rule out all of these shapes except for an ellipse. It is possible to find the center, major axis $a$, and minor axis $b$ of the ellipse, as well as the angle the axes are rotated from the coordinate axes. Let $x' = a \cos\theta$ and $y' = b \sin\theta$ to get an axis-aligned ellipse centered at $(0,0),$ the apply a coordinate transformation $x=f(x',y'),$ $y = g(x',y')$ to translate and rotate the ellipse as needed. (The translation is zero in this case since it turns out the center of your ellipse is at $(0,0)$.)

You can save a lot of bother from the previous paragraph by knowing that at the end of the procedure you'll have something equivalent to \begin{align} x &= h + m \cos\theta - n \sin\theta, \\ y &= k + n \cos\theta + m \sin\theta. \end{align} Take a few points on the ellipse and solve for $h,$ $k,$ $m,$ and $n.$ (In this case $h = k = 0,$ but I've written this for a general ellipse.)

David K
  • 98,388