Here is my (unfinished) version.
Very good Stefan!
I was initially going to use the property that a line extending from the intersection of the tangents and passing through the midpoint of the line between the two given points will also pass through the ellipse center in order to determine the center location and minor radius:
And then use a rearrangement of the cartesian equation of an ellipse with the minor radius and second point in order to find the major radius.
However, your code is far more succinct.
Though, I'm rather embarassed to confess that, when studying your code, I could not derive the equations that you are using to calculate the minor & major radii after you rotate the ellipse to be orthogonal to the WCS axes:
b (* y (/ (- y (* m x)) (- (* 2 y) (* m x))))
a
(/ (* b x
) (sqrt (- (* 2 b y
) (* y y
))))
I understand that variable
m is the tangent of the angle formed by the second tangent direction, but could not derive the above equations geometrically from the diagram.
Could you possibly shed some light?
PS: I should think you could alternatively achieve the rotation of the ellipse by exploiting an appropriate change of coordinates using the
trans function, but I do like your use of the rotation matrix.