# Determining if two general conic sections are tangent to each other

Given two conics in general form $A_ix^2 + B_ixy + C_iy^2 + D_ix + E_iy + F_i = 0$ for $i = 1, 2$, I want to determine if they are tangent to one another, and I'm looking for a method that wouldn't be too difficult to implement on a computer.

This is what I was going to implement originally:

Assume the two conics are $\mathcal{C}_1$ and $\mathcal{C}_2$. If I want to determine if they are tangent to each other I have to find a point $x_0$ such that $\frac{d}{dx}\mathcal{C}_1(x_0) = \frac{d}{dx}\mathcal{C}_2(x_0)$ and $\mathcal{C}_1(x_0) = \mathcal{C}_2(x_0)$ (the slopes are the same and the point is the same on both conics).

To do this, we have to solve for x in $\frac{d}{dx}\mathcal{C}_1(x) = \frac{d}{dx}\mathcal{C}_2(x)$, which when written out in full is:

$$-\frac{B_1x + 2C_1y_1(x) + E_1}{2A_1x + B_1y_1(x) + D_1} = -\frac{B_2x + 2C_2y_2(x) + E_2}{2A_2x + B_2y_2(x) + D_2}$$ with $$y_i(x) = \frac{-(B_ix + E_i) \pm \sqrt{(B_ix + E_i)^2 - 4C_i(A_ix^2 + D_ix + F_i)}}{2C_i}$$ which is gross, like seriously vomit inducing. Since I'm not using a computer algebra system that could solve it for me, I propose calculating it approximately using the secant method$^*$.

Let $$f(x) = \frac{B_2x + 2C_2y_2(x) + E_2}{2A_2x + B_2y_2(x) + D_2} -\frac{B_1x + 2C_1y_1(x) + E_1}{2A_1x + B_1y_1(x) + D_1}.$$ The secant method tells us that $$x_n = \frac{x_{n-2}f(x_{n-1})-x_{n-1}f(x_{n-2})}{f(x_{n-1})-f(x_{n-2})}$$ so eventually we'd get a relatively accurate answer for $x$ that we can plug into our original equations $\mathcal{C}_1$ and $\mathcal{C}_2$.

$*$ - I propose the secant method over Newton's method because it doesn't require us to calculate $\frac{d^2}{dx^2}\mathcal{C}_i$. This is already brutally arithmetically inefficient.

Are there any better methods?

Considering the intersection of two conics being the solution of a quartic equation, you should expect the two conics to have 4 points of intersection (including intersection at infinity and complex intersection points). But when tangency happens, two of the 4 intersection points get lumped together into a multiplicity $2$ point. This means the discriminant of the quartic equation is zero. You should have an equation to detect whether two conics are tangent without even solving the point of intersection. But of course the details could be more involved.