This question is a follow-up on the previous question asked in this thread where we discussed a strategy to find the angle between inner common tangents to two ellipse whose equations are given by:
$ AX^{2}+BXY+CY^{2}+DX+EY+F=0 $
In that approach, we did not use any equation solver and was able to get the angle between inner common tangents by just using the linear algebra and the concepts of projective geometry which made the solutions very computationally efficient. I am looking for a solution along those lines for a slightly different problem.
In the last thread we did not realize that the two ellipse can intersect with each other and the imaginary tangents would still exist. I am using the word imaginary because if the two ellipse intersect then there is no physical meaning of inner common tangents.
Usually, there will be three cases:
- In the first case, the two ellipse do not intersect and the approach discussed in the earlier thread would work to find the inner common tangent angle. This angle will be 0 degrees when the two ellipse are infinitely apart and keeps on increasing as the two ellipse comes closer and closer. It can be noted that this angle will always be less than 180 degrees because the two ellipse never intersect.
In the second case, the two ellipse will intersect each other at only one point with no overlap and as a result the two inner common tangents will coincide with each other and angle between them would be exactly 180 degrees.

In the third case, the two ellipse will overlap and intersect at two, three or four points. In this case, the angle between the inner common tangents should be 180 degrees + some complex number. The magnitude of this complex number would represent the degree of penetration. Greater magnitude represents greater penetration.

To illustrate this imaginary tangent concept for a circle, let us consider that the angle between inner common tangents is given by the following equation: \begin{equation} \theta = 2\ sin^{-1}(\frac{R_1 + R_2}{r}) \end{equation}
where $R_1$ and $R_2$ are the radii of two circles, $r$ is the distance between the centre of the two circles. These quantities can be referred from the following figure:

Now, it can be seen that this angle $\theta$ is always defined even when the two circles intersect with each other. If they are non-intersecting $(R_1+R_2<r)$ then the angle would be purely real, if they are intersecting $(R_1+R_2>r)$ then the angle is 180 degrees + some complex number and finally if they touch each other at only one point $(R_1+R_2=r)$ then this angle would be 180 degrees. Usually, the more the magnitude of complex number, the deeper the overlap of two entities.
This concept is well defined for the case of circle. However, there is an equivalent concept of imaginary tangents in case of ellipse and I am not aware of how to compute this imaginary angle. I only know non-deterministic method of doing that. I hope my question is clear. Please help me out with the deterministic solution for the ellipse case. Thanks!


New updated code.
This seems to work better:
Previous code.
It seems like this code does what you want. It treats the case of real inner tangents of disjoint ellipses or the case of two complex tangents of two ellipses, intersecting at two real points. For circles, the result seems to match the elementary formula.
$$$$
Older Post.
Today I had some time to experiment with the code I wrote in the previous post. Theoretically, the approach should be exactly the same as the case of four real tangents. However, the only major hassle I am seeing for now is the complex arithmetic. In the function
find_common_points()some square roots are calculated, which works fine for real numbers, but when the entries of the trivialized degenerate conicsL1andL2become complex (and they do in the case of two ellipses intersecting at exactly two points), then one needs to carefully calculate the appropriate complex square root. The rest is the same. With two complex tangents and two real ones, you choose the complex to be "inner" and calculate a complex dot product divided by complex norms, which will give you a complex number. After that you can take complexarccos()of that. Whether this scheme leads to the same elementary circle calculation you show in your post, is unclear for now, although the fact that all of these are complex holomorphic functions of several variables that overlap in the real case suggest that it is possible these constructions match due to the rigidity of holomorphic prolongations.